diff --git a/test/test_main.py b/test/test_main.py index c4baa18e..85986ad1 100644 --- a/test/test_main.py +++ b/test/test_main.py @@ -1,6 +1,7 @@ import os import glob import sys +import re import pytest import tabulate @@ -11,8 +12,37 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) from main import run -test_files = glob.glob(os.path.join(os.path.dirname(__file__), "files/**/*.ifc"), recursive=True) -@pytest.mark.parametrize("filename", test_files) +rule_code_pattern = re.compile(r"^[a-zA-Z]{3}\d{3}$") +rule_codes = list(filter(lambda arg: rule_code_pattern.match(arg), sys.argv[1:])) + +def get_test_files(): + """ + Option -> Example + Test files for a rule -> 'python3 test_main.py alb001' + Also applies for multiple rules -> 'python3 test_main.py alb001 alb002' + Test files for a single file -> 'python3 test_main.py .ifc + Also applies for multiple files -> 'python3 test_main.py .ifc .ifc' + Codes and rules can also be combined -> 'python3 test_main.py alb001 .ifc' + """ + args = [a for a in sys.argv[1:] if not a.startswith('-')] + rule_code_pattern = re.compile(r"^[a-zA-Z]{3}\d{3}$") + rule_codes = list(filter(lambda arg: rule_code_pattern.match(arg), args)) + + test_files = [] + for code in rule_codes: + paths = glob.glob(os.path.join(os.path.dirname(__file__), "files/", code.lower(), "*.ifc")) + if not paths: + print(f"No IFC files were found for the following rule code: {code}. Please provide test files or verify the input.") + test_files.extend(paths) + + file_pattern = r".*\.ifc(\')?$" #matches ".ifc" and "ifc'" + test_files.extend([s.strip("'") for s in args if re.match(file_pattern, s)]) + + if not args: # for example, with 'pytest -sv' + test_files = glob.glob(os.path.join(os.path.dirname(__file__), "files/**/*.ifc"), recursive=True) + return test_files + +@pytest.mark.parametrize("filename", get_test_files()) def test_invocation(filename): results = list(run(filename)) base = os.path.basename(filename)