From 7fe8afba38a2e6bd721b5f0819b8093b679c2236 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Tue, 17 Sep 2024 00:19:56 +0200 Subject: [PATCH] Move test parameters to YAML The large amount of test data can be managed more easily if it is contained in a separate file instead of being in the test code. Signed-off-by: Georg Pfuetzenreuter --- tests/matrix.yaml | 43 +++++++++++++++++++++++ tests/test_pyacl.py | 85 +++++++++------------------------------------ 2 files changed, 59 insertions(+), 69 deletions(-) create mode 100644 tests/matrix.yaml diff --git a/tests/matrix.yaml b/tests/matrix.yaml new file mode 100644 index 0000000..143c151 --- /dev/null +++ b/tests/matrix.yaml @@ -0,0 +1,43 @@ +--- +- user:user:r: + user: + user: + read: true + write: false + execute: false + group: + null: + read: true + write: false + execute: false + mask: + null: + read: true + write: false + execute: false + other: + null: + read: true + write: false + execute: false +- user:user:-w-: + user: + user: + read: false + write: true + execute: false + group: + null: + read: true + write: false + execute: false + mask: + null: + read: true + write: true + execute: false + other: + null: + read: true + write: false + execute: false diff --git a/tests/test_pyacl.py b/tests/test_pyacl.py index 0bd9241..286df8d 100644 --- a/tests/test_pyacl.py +++ b/tests/test_pyacl.py @@ -8,80 +8,27 @@ An English copy of the Licence is shipped in a file called LICENSE along with th You may obtain copies of the Licence in any of the official languages at https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12. """ +from os.path import dirname, join + from pytest import mark +from yaml import safe_load from pyacl import acl -testdata = [ - ( - 'user:user:r', - { - 'user': { - 'user': { - 'read': True, - 'write': False, - 'execute': False, - }, - }, - 'group': { - None: { - 'read': True, - 'write': False, - 'execute': False, - }, - }, - 'mask': { - None: { - 'read': True, - 'write': False, - 'execute': False, - }, - }, - 'other': { - None: { - 'read': True, - 'write': False, - 'execute': False, - }, - }, - }, - ), - ( - 'user:user:-w-', - { - 'user': { - 'user': { - 'read': False, - 'write': True, - 'execute': False, - }, - }, - 'group': { - None: { - 'read': True, - 'write': False, - 'execute': False, - }, - }, - 'mask': { - None: { - 'read': True, - 'write': True, - 'execute': False, - }, - }, - 'other': { - None: { - 'read': True, - 'write': False, - 'execute': False, - }, - }, - }, - ), -] -@mark.parametrize('aclin, aclout', testdata) +def load_yaml(file): + with open(join(dirname(__file__), file)) as fh: + data = safe_load(fh) + + out = [] + + for entry in data: + out.append(tuple(entry.items())[0]) + + return out + + +@mark.parametrize('aclin, aclout', load_yaml('matrix.yaml')) def test_parse_acl(sample_file, aclin, aclout): have = acl.parsefromfile(sample_file) assert aclout == have