More aggressive refactoring for IfcTester to break up the monolithic codebase

This commit is contained in:
Dion Moult
2022-07-15 14:09:35 +10:00
parent bdf46f9431
commit 282c140c14
8 changed files with 2004 additions and 1968 deletions
+22 -24
View File
@@ -1,30 +1,30 @@
# IfcOpenShell - IFC toolkit and geometry engine
# Copyright (C) 2021 Thomas Krijnen <thomas@aecgeeks.com>
# IfcTester - IDS based model auditing
# Copyright (C) 2021-2022 Thomas Krijnen <thomas@aecgeeks.com>, Dion Moult <dion@thinkmoult.com>
#
# This file is part of IfcOpenShell.
# This file is part of IfcTester.
#
# IfcOpenShell is free software: you can redistribute it and/or modify
# IfcTester is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# IfcOpenShell is distributed in the hope that it will be useful,
# IfcTester is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
# along with IfcTester. If not, see <http://www.gnu.org/licenses/>.
import os
import re
import unittest
import pytest
import functools
import itertools
import ifcopenshell
import test_ids
import test_facet
from xml.dom.minidom import parseString
from ifcopenshell import ids, template, validate
from ifctester import ids
from ifcopenshell import validate
outdir = "build"
@@ -42,8 +42,7 @@ class DocGenerator:
f = inst.wrapped_data.file
# Validate the file created and loop over the issues, fixing them
# one by one.
# Validate the file created and loop over the issues, fixing them one by one.
l = validate.json_logger()
validate.validate(f, l)
for issue in l.statements:
@@ -63,18 +62,18 @@ class DocGenerator:
basename = f"{result}-" + re.sub("[^0-9a-zA-Z]", "_", name.lower())
# Write IFC to disk
f.write(os.path.join(outdir, f"{basename}.ifc"))
f.write(os.path.join(outdir, "files", f"{basename}.ifc"))
# Create an IDS with the applicability selecting exactly
# the entity type passed to us in `inst`.
specs = ids.ids(title=name)
spec = ids.specification(name=name)
spec.add_applicability(ids.entity.create(name=inst.is_a()))
spec.add_requirement(facet)
specs = ids.Ids(title=name)
spec = ids.Specification(name=name)
spec.applicability.append(ids.Entity(name=inst.is_a()))
spec.requirements.append(facet)
specs.specifications.append(spec)
# Write IDS to disk
with open(os.path.join(outdir, f"{basename}.ids"), "w", encoding="utf-8") as ids_file:
with open(os.path.join(outdir, "files", f"{basename}.ids"), "w", encoding="utf-8") as ids_file:
ids_file.write(specs.to_string())
xml_text = "\n".join(
@@ -97,13 +96,12 @@ class DocGenerator:
self.facet = facet
test_ids.run = DocGenerator()
test_ids.set_facet = test_ids.run.set_facet
test_facet.run = DocGenerator()
test_facet.set_facet = test_facet.run.set_facet
suite = unittest.TestLoader().discover(".", pattern="test_ids.py")
result = unittest.TextTestRunner(verbosity=2).run(suite)
pytest.main(["-p", "no:pytest-blender"])
for facet, testcases in test_ids.run.testcases.items():
for facet, testcases in test_facet.run.testcases.items():
with open(os.path.join(outdir, f"testcases-{facet}.md"), "w") as f:
write = functools.partial(print, file=f)
write(f"# {facet.capitalize()} testcases")
@@ -124,6 +122,6 @@ for facet, testcases in test_ids.run.testcases.items():
write("~~~")
write()
write(
f"[Sample IDS]({testcase['basename']}.ids) - [Sample IFC: {testcase['id']}]({testcase['basename']}.ifc)"
f"[Sample IDS](files/{testcase['basename']}.ids) - [Sample IFC: {testcase['id']}](files/{testcase['basename']}.ifc)"
)
write()
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff