validate fixtures: validate expected error count

This commit is contained in:
Andrej730
2026-08-03 19:46:18 +05:00
parent c1c94b9362
commit cdf107e579
40 changed files with 72 additions and 48 deletions
+33 -12
View File
@@ -16,29 +16,50 @@
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import glob
import os
from pathlib import Path
import pytest
import tabulate
import ifcopenshell.validate
from .fixture_generate import FailObj, Result, parse_result
_filepaths = list((Path(__file__).parent / "fixtures/validate").glob("*.ifc"))
@pytest.mark.parametrize(
"file",
glob.glob(os.path.join(os.path.dirname(__file__), "fixtures/validate/*.ifc")),
"filepath,expected_result",
[(fp, parse_result(fp)) for fp in _filepaths],
ids=[fp.name for fp in _filepaths],
)
def test_file(file):
def test_file(filepath: Path, expected_result: Result):
logger = ifcopenshell.validate.json_logger()
try:
ifcopenshell.validate.validate(file, logger)
except ifcopenshell.SchemaError as e:
ifcopenshell.validate.validate(filepath, logger)
except ifcopenshell.SchemaError:
pytest.skip()
file = os.path.basename(file)
if file.startswith("fail-"):
assert len(logger.statements) > 0
if file.startswith("pass-"):
assert len(logger.statements) == 0
results = logger.statements
print()
print(filepath.name)
print()
print(f"{len(results)} errors")
if results:
print(
tabulate.tabulate(
[[c or "" for c in r.values()] for r in results],
maxcolwidths=[20, 100, 20],
tablefmt="simple_grid",
headers=results[0].keys(),
)
)
match expected_result:
case FailObj(expected_count=expected_count):
assert len(results) == expected_count
case "pass":
assert len(results) == 0
if __name__ == "__main__":