mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-29 03:37:21 +00:00
Run black on ids module
This commit is contained in:
@@ -556,7 +556,7 @@ class classification(facet):
|
|||||||
def create(location="any", value=None, system=None):
|
def create(location="any", value=None, system=None):
|
||||||
"""Create a classification facet that can be added to applicability or requirements of IDS specification.
|
"""Create a classification facet that can be added to applicability or requirements of IDS specification.
|
||||||
|
|
||||||
:param location: Define where to check for the parameter. One of "any"|"instance"|"type", defaults to "any"
|
:param location: Where to check for the parameter. One of "any"|"instance"|"type", defaults to "any"
|
||||||
:type location: str, optional
|
:type location: str, optional
|
||||||
:param value: Value that is required. Could be alphanumeric or restriction object, defaults to None
|
:param value: Value that is required. Could be alphanumeric or restriction object, defaults to None
|
||||||
:type value: restriction|alphanumeric, optional
|
:type value: restriction|alphanumeric, optional
|
||||||
@@ -741,7 +741,7 @@ class property(facet):
|
|||||||
def create(location="any", propertySet=None, name=None, value=None):
|
def create(location="any", propertySet=None, name=None, value=None):
|
||||||
"""Create a property facet that can be added to applicability or requirements of IDS specification.
|
"""Create a property facet that can be added to applicability or requirements of IDS specification.
|
||||||
|
|
||||||
:param location: Define where to check for the parameter. One of "any"|"instance"|"type", defaults to "any"
|
:param location: Where to check for the parameter. One of "any"|"instance"|"type", defaults to "any"
|
||||||
:type location: str, optional
|
:type location: str, optional
|
||||||
:param propertySet: Propertyset that is required. Could be alphanumeric or restriction object, defaults to None
|
:param propertySet: Propertyset that is required. Could be alphanumeric or restriction object, defaults to None
|
||||||
:type propertySet: restriction|alphanumeric, optional
|
:type propertySet: restriction|alphanumeric, optional
|
||||||
@@ -857,7 +857,7 @@ class material(facet):
|
|||||||
def create(location="any", value=None):
|
def create(location="any", value=None):
|
||||||
"""Create a material facet that can be added to applicability or requirements of IDS specification.
|
"""Create a material facet that can be added to applicability or requirements of IDS specification.
|
||||||
|
|
||||||
:param location: Define where to check for the parameter. One of "any"|"instance"|"type", defaults to "any"
|
:param location: Where to check for the parameter. One of "any"|"instance"|"type", defaults to "any"
|
||||||
:type location: str, optional
|
:type location: str, optional
|
||||||
:param value: Value that is required. Could be alphanumeric or restriction object, defaults to None
|
:param value: Value that is required. Could be alphanumeric or restriction object, defaults to None
|
||||||
:type value: restriction|alphanumeric, optional
|
:type value: restriction|alphanumeric, optional
|
||||||
@@ -1249,7 +1249,7 @@ class BcfHandler(logging.StreamHandler):
|
|||||||
bcf_handler = BcfHandler(
|
bcf_handler = BcfHandler(
|
||||||
project_name="Default IDS Project",
|
project_name="Default IDS Project",
|
||||||
author="your@email.com",
|
author="your@email.com",
|
||||||
filepath=r".\example.bcf",
|
filepath="example.bcf",
|
||||||
)
|
)
|
||||||
logger = logging.getLogger("IDS_Logger")
|
logger = logging.getLogger("IDS_Logger")
|
||||||
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ file.close()
|
|||||||
ifc_file = ifcopenshell.open(IFC_URL)
|
ifc_file = ifcopenshell.open(IFC_URL)
|
||||||
os.remove(os.path.join(tempfile.gettempdir(), "test.ifc"))
|
os.remove(os.path.join(tempfile.gettempdir(), "test.ifc"))
|
||||||
|
|
||||||
|
|
||||||
class TestIdsParsing(unittest.TestCase):
|
class TestIdsParsing(unittest.TestCase):
|
||||||
|
|
||||||
"""Parsing basic IDS files"""
|
"""Parsing basic IDS files"""
|
||||||
@@ -55,9 +56,7 @@ class TestIdsParsing(unittest.TestCase):
|
|||||||
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "IfcWall")
|
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "IfcWall")
|
||||||
|
|
||||||
def test_parse_predefinedType_facet(self):
|
def test_parse_predefinedType_facet(self):
|
||||||
IDS_URL = (
|
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_predefinedtype.xml")
|
||||||
os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_predefinedtype.xml")
|
|
||||||
)
|
|
||||||
ids_file = ids.ids.open(IDS_URL)
|
ids_file = ids.ids.open(IDS_URL)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
ids_file.specifications[0].requirements.terms[0].node["predefinedType"]["simpleValue"], "CLADDING"
|
ids_file.specifications[0].requirements.terms[0].node["predefinedType"]["simpleValue"], "CLADDING"
|
||||||
@@ -78,9 +77,7 @@ class TestIdsParsing(unittest.TestCase):
|
|||||||
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["value"]["simpleValue"], "Test_Material")
|
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["value"]["simpleValue"], "Test_Material")
|
||||||
|
|
||||||
def test_parse_classification_facet(self):
|
def test_parse_classification_facet(self):
|
||||||
IDS_URL = (
|
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_classification.xml")
|
||||||
os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_classification.xml")
|
|
||||||
)
|
|
||||||
ids_file = ids.ids.open(IDS_URL)
|
ids_file = ids.ids.open(IDS_URL)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
ids_file.specifications[0].requirements.terms[0].node["value"]["simpleValue"], "Test_Classification"
|
ids_file.specifications[0].requirements.terms[0].node["value"]["simpleValue"], "Test_Classification"
|
||||||
@@ -96,7 +93,7 @@ class TestIdsParsing(unittest.TestCase):
|
|||||||
""" Saving parsed IDS to IDS.xml """
|
""" Saving parsed IDS to IDS.xml """
|
||||||
|
|
||||||
def test_parsed_ids_to_xml(self):
|
def test_parsed_ids_to_xml(self):
|
||||||
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_all_fields.xml")
|
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files", "IDS", "IDS_Wall_needs_all_fields.xml")
|
||||||
ids_file = ids.ids.open(IDS_URL)
|
ids_file = ids.ids.open(IDS_URL)
|
||||||
fn = "TEST_FILE.xml"
|
fn = "TEST_FILE.xml"
|
||||||
result = ids_file.to_xml(fn)
|
result = ids_file.to_xml(fn)
|
||||||
@@ -106,7 +103,11 @@ class TestIdsParsing(unittest.TestCase):
|
|||||||
""" Parsing IDS files with restrictions """
|
""" Parsing IDS files with restrictions """
|
||||||
|
|
||||||
def test_parse_restrictions_enumeration(self):
|
def test_parse_restrictions_enumeration(self):
|
||||||
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property_with_restriction_enumeration.xml")
|
IDS_URL = os.path.join(
|
||||||
|
os.path.dirname(__file__),
|
||||||
|
"Sample-BIM-Files/IDS/",
|
||||||
|
"IDS_Wall_needs_property_with_restriction_enumeration.xml",
|
||||||
|
)
|
||||||
ids_file = ids.ids.open(IDS_URL)
|
ids_file = ids.ids.open(IDS_URL)
|
||||||
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
|
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@@ -118,7 +119,9 @@ class TestIdsParsing(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_parse_restrictions_bounds(self):
|
def test_parse_restrictions_bounds(self):
|
||||||
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property_with_restriction_bounds.xml")
|
IDS_URL = os.path.join(
|
||||||
|
os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property_with_restriction_bounds.xml"
|
||||||
|
)
|
||||||
ids_file = ids.ids.open(IDS_URL)
|
ids_file = ids.ids.open(IDS_URL)
|
||||||
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
|
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@@ -127,7 +130,9 @@ class TestIdsParsing(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_parse_restrictions_pattern_simple(self):
|
def test_parse_restrictions_pattern_simple(self):
|
||||||
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property_with_restriction_pattern.xml")
|
IDS_URL = os.path.join(
|
||||||
|
os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property_with_restriction_pattern.xml"
|
||||||
|
)
|
||||||
ids_file = ids.ids.open(IDS_URL)
|
ids_file = ids.ids.open(IDS_URL)
|
||||||
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
|
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
@@ -263,10 +268,10 @@ class TestIdsAuthoring(unittest.TestCase):
|
|||||||
i.specifications[0].add_applicability(m)
|
i.specifications[0].add_applicability(m)
|
||||||
i.specifications[0].add_requirement(c)
|
i.specifications[0].add_requirement(c)
|
||||||
i.specifications[0].add_requirement(p1)
|
i.specifications[0].add_requirement(p1)
|
||||||
#TODO i.specifications[0].add_requirement(p2)
|
# TODO i.specifications[0].add_requirement(p2)
|
||||||
i.specifications[0].add_requirement(p3)
|
i.specifications[0].add_requirement(p3)
|
||||||
i.specifications[0].add_requirement(p4)
|
i.specifications[0].add_requirement(p4)
|
||||||
#TODO i.specifications[0].add_requirement(p5)
|
# TODO i.specifications[0].add_requirement(p5)
|
||||||
fn = "TEST_FILE.xml"
|
fn = "TEST_FILE.xml"
|
||||||
result = i.to_xml(fn)
|
result = i.to_xml(fn)
|
||||||
os.remove(fn)
|
os.remove(fn)
|
||||||
@@ -289,9 +294,8 @@ class TestIdsAuthoring(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class TestIfcValidation(unittest.TestCase):
|
class TestIfcValidation(unittest.TestCase):
|
||||||
|
|
||||||
def test_validate_simple(self):
|
def test_validate_simple(self):
|
||||||
#Same test as in reporting...
|
# Same test as in reporting...
|
||||||
ids_file = ids.ids.open(IDS_URL)
|
ids_file = ids.ids.open(IDS_URL)
|
||||||
report = ids.SimpleHandler()
|
report = ids.SimpleHandler()
|
||||||
logger.addHandler(report)
|
logger.addHandler(report)
|
||||||
@@ -300,12 +304,12 @@ class TestIfcValidation(unittest.TestCase):
|
|||||||
logger.handlers.pop()
|
logger.handlers.pop()
|
||||||
|
|
||||||
def test_validate_all_facets(self):
|
def test_validate_all_facets(self):
|
||||||
#Those are true:
|
# Those are true:
|
||||||
e = ids.entity.create(name="IfcWall")
|
e = ids.entity.create(name="IfcWall")
|
||||||
p1 = ids.property.create(location="any", propertySet="MySet", name="Param1", value="banan")
|
p1 = ids.property.create(location="any", propertySet="MySet", name="Param1", value="banan")
|
||||||
p2 = ids.property.create(location="any", propertySet="MySet", name="Param2", value=120.0)
|
p2 = ids.property.create(location="any", propertySet="MySet", name="Param2", value=120.0)
|
||||||
p3 = ids.property.create(location="any", propertySet="Pset_WallCommon", name="LoadBearing", value=False)
|
p3 = ids.property.create(location="any", propertySet="Pset_WallCommon", name="LoadBearing", value=False)
|
||||||
#Those are false:
|
# Those are false:
|
||||||
p4 = ids.property.create(location="any", propertySet="MySet", name="Param1", value="orange")
|
p4 = ids.property.create(location="any", propertySet="MySet", name="Param1", value="orange")
|
||||||
p5 = ids.property.create(location="any", propertySet="MySet", name="Param2", value=123.4)
|
p5 = ids.property.create(location="any", propertySet="MySet", name="Param2", value=123.4)
|
||||||
p6 = ids.property.create(location="any", propertySet="Pset_WallCommon", name="LoadBearing", value=True)
|
p6 = ids.property.create(location="any", propertySet="Pset_WallCommon", name="LoadBearing", value=True)
|
||||||
@@ -327,42 +331,60 @@ class TestIfcValidation(unittest.TestCase):
|
|||||||
# TODO self.assertEqual(len(report.statements), 27) #there are 5 walls in the IFC, one passed 3 criteria, est should fail (27 failures)
|
# TODO self.assertEqual(len(report.statements), 27) #there are 5 walls in the IFC, one passed 3 criteria, est should fail (27 failures)
|
||||||
logger.handlers.pop()
|
logger.handlers.pop()
|
||||||
|
|
||||||
|
|
||||||
""" Validating IDS files with restrictions """
|
""" Validating IDS files with restrictions """
|
||||||
|
|
||||||
def test_validate_restrictions_enumeration(self):
|
def test_validate_restrictions_enumeration(self):
|
||||||
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property_with_restriction_enumeration.xml")
|
IDS_URL = os.path.join(
|
||||||
|
os.path.dirname(__file__),
|
||||||
|
"Sample-BIM-Files/IDS/",
|
||||||
|
"IDS_Wall_needs_property_with_restriction_enumeration.xml",
|
||||||
|
)
|
||||||
ids_file = ids.ids.open(IDS_URL)
|
ids_file = ids.ids.open(IDS_URL)
|
||||||
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]['simpleValue'], "Test_Parameter")
|
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
|
||||||
self.assertEqual( [x['@value'] for x in ids_file.specifications[0].requirements.terms[0].node["value"]['restriction'][0]['enumeration'] ], ['testA', 'testB'])
|
self.assertEqual(
|
||||||
|
[
|
||||||
|
x["@value"]
|
||||||
|
for x in ids_file.specifications[0].requirements.terms[0].node["value"]["restriction"][0]["enumeration"]
|
||||||
|
],
|
||||||
|
["testA", "testB"],
|
||||||
|
)
|
||||||
# TODO actual test of validation result
|
# TODO actual test of validation result
|
||||||
# self.assertTrue( )
|
# self.assertTrue( )
|
||||||
|
|
||||||
def test_validate_restrictions_boundsInclusive(self):
|
def test_validate_restrictions_boundsInclusive(self):
|
||||||
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property_with_restriction_bounds.xml")
|
IDS_URL = os.path.join(
|
||||||
|
os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property_with_restriction_bounds.xml"
|
||||||
|
)
|
||||||
ids_file = ids.ids.open(IDS_URL)
|
ids_file = ids.ids.open(IDS_URL)
|
||||||
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]['simpleValue'], "Test_Parameter")
|
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
|
||||||
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["value"]['restriction'][0]['minInclusive']['@value'], '0')
|
self.assertEqual(
|
||||||
|
ids_file.specifications[0].requirements.terms[0].node["value"]["restriction"][0]["minInclusive"]["@value"],
|
||||||
|
"0",
|
||||||
|
)
|
||||||
# TODO actual test of validation result
|
# TODO actual test of validation result
|
||||||
# self.assertTrue( )
|
# self.assertTrue( )
|
||||||
|
|
||||||
def test_validate_restrictions_boundsExclusive(self):
|
def test_validate_restrictions_boundsExclusive(self):
|
||||||
#TODO
|
# TODO
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_validate_restrictions_pattern_simple(self):
|
def test_validate_restrictions_pattern_simple(self):
|
||||||
IDS_URL = os.path.join(os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property_with_restriction_pattern.xml")
|
IDS_URL = os.path.join(
|
||||||
|
os.path.dirname(__file__), "Sample-BIM-Files/IDS/", "IDS_Wall_needs_property_with_restriction_pattern.xml"
|
||||||
|
)
|
||||||
ids_file = ids.ids.open(IDS_URL)
|
ids_file = ids.ids.open(IDS_URL)
|
||||||
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]['simpleValue'], "Test_Parameter")
|
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["name"]["simpleValue"], "Test_Parameter")
|
||||||
self.assertEqual(ids_file.specifications[0].requirements.terms[0].node["value"]['restriction'][0]['pattern']['@value'], '[A-Z]{2,4}')
|
self.assertEqual(
|
||||||
|
ids_file.specifications[0].requirements.terms[0].node["value"]["restriction"][0]["pattern"]["@value"],
|
||||||
|
"[A-Z]{2,4}",
|
||||||
|
)
|
||||||
# TODO actual test of validation result
|
# TODO actual test of validation result
|
||||||
# self.assertTrue( )
|
# self.assertTrue( )
|
||||||
|
|
||||||
|
|
||||||
class TestIdsReporting(unittest.TestCase):
|
class TestIdsReporting(unittest.TestCase):
|
||||||
|
|
||||||
def test_simple_report(self):
|
def test_simple_report(self):
|
||||||
#Same test as in validation...
|
# Same test as in validation...
|
||||||
ids_file = ids.ids.open(IDS_URL)
|
ids_file = ids.ids.open(IDS_URL)
|
||||||
report = ids.SimpleHandler()
|
report = ids.SimpleHandler()
|
||||||
logger.addHandler(report)
|
logger.addHandler(report)
|
||||||
@@ -370,7 +392,6 @@ class TestIdsReporting(unittest.TestCase):
|
|||||||
self.assertEqual(len(report.statements), 5)
|
self.assertEqual(len(report.statements), 5)
|
||||||
logger.handlers.pop()
|
logger.handlers.pop()
|
||||||
|
|
||||||
|
|
||||||
def test_bcf_report(self):
|
def test_bcf_report(self):
|
||||||
ids_file = ids.ids.open(IDS_URL)
|
ids_file = ids.ids.open(IDS_URL)
|
||||||
fn = os.path.join(tempfile.gettempdir(), "test.bcf")
|
fn = os.path.join(tempfile.gettempdir(), "test.bcf")
|
||||||
|
|||||||
Reference in New Issue
Block a user