Skip to content

Commit

Permalink
Merge branch 'limit-rules-tested'
Browse files Browse the repository at this point in the history
  • Loading branch information
aothms committed Sep 18, 2023
2 parents 4683d48 + c1dd5e6 commit 95ff46b
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions test/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import glob
import sys
import re

import pytest
import tabulate
Expand All @@ -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 <path>.ifc
Also applies for multiple files -> 'python3 test_main.py <path1>.ifc <path2>.ifc'
Codes and rules can also be combined -> 'python3 test_main.py alb001 <path>.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)
Expand Down

0 comments on commit 95ff46b

Please sign in to comment.