From 41a47f14ae311b54c31fc8f0200531b2d8292e48 Mon Sep 17 00:00:00 2001 From: ArturTomczak Date: Mon, 5 Jul 2021 13:21:36 +0200 Subject: [PATCH] add basic parsing tests --- .../ifcopenshell/test_ids.py | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/test_ids.py b/src/ifcopenshell-python/ifcopenshell/test_ids.py index 23bd98e43d..73dec07978 100644 --- a/src/ifcopenshell-python/ifcopenshell/test_ids.py +++ b/src/ifcopenshell-python/ifcopenshell/test_ids.py @@ -1,20 +1,62 @@ import unittest from ids import ids, specification, entity, classification, property, material +import requests +def read_web_file(URL): + return requests.get(URL).text + class TestIds(unittest.TestCase): """ Parsing IDS.xml """ - def test_parse(self): - ids_file = ids.parse(sys.argv[1]) + def test_basic_ids_parse(self): + IDS_URL = "https://raw.githubusercontent.com/atomczak/Sample-BIM-Files/main/IDS/IDS_Wall_needs_all_fields.xml" + ids_file = ids.parse(read_web_file(IDS_URL)) self.assertEqual( type(ids_file).__name__, "ids" ) + + def test_entity_facet(self): + IDS_URL = "https://raw.githubusercontent.com/atomczak/Sample-BIM-Files/main/IDS/IDS_Wall_needs_entity.xml" + ids_file = ids.parse(read_web_file(IDS_URL)) + self.assertEqual( ids_file.specifications[0].requirements.terms[0].node['name'] , "IfcWall" ) + def test_predefinedtype_facet(self): + IDS_URL = "https://raw.githubusercontent.com/atomczak/Sample-BIM-Files/main/IDS/IDS_Wall_needs_predefinedtype.xml" + ids_file = ids.parse(read_web_file(IDS_URL)) + self.assertEqual( ids_file.specifications[0].requirements.terms[0].node['predefinedtype'] , "CLADDING" ) + + def test_property_facet(self): + IDS_URL = "https://raw.githubusercontent.com/atomczak/Sample-BIM-Files/main/IDS/IDS_Wall_needs_property.xml" + ids_file = ids.parse(read_web_file(IDS_URL)) + self.assertEqual( ids_file.specifications[0].requirements.terms[0].node['propertyset'] , "Test_PropertySet" ) + self.assertEqual( ids_file.specifications[0].requirements.terms[0].node['name'] , "Test_Parameter" ) + self.assertEqual( ids_file.specifications[0].requirements.terms[0].node['value'] , "Test_Value" ) + + def test_material_facet(self): + IDS_URL = "https://raw.githubusercontent.com/atomczak/Sample-BIM-Files/main/IDS/IDS_Wall_needs_material.xml" + ids_file = ids.parse(read_web_file(IDS_URL)) + self.assertEqual( ids_file.specifications[0].requirements.terms[0].node['value'] , "Test_Material" ) + + def test_classification_facet(self): + IDS_URL = "https://raw.githubusercontent.com/atomczak/Sample-BIM-Files/main/IDS/IDS_Wall_needs_classification.xml" + ids_file = ids.parse(read_web_file(IDS_URL)) + self.assertEqual( ids_file.specifications[0].requirements.terms[0].node['value'] , "Test_Classification" ) + self.assertEqual( ids_file.specifications[0].requirements.terms[0].node['system'] , "Test_System" ) + + """ Parsing invalid IDS.xml """ + # TODO + # def test_invalid_classification_facet(self): + # IDS_URL = "https://raw.githubusercontent.com/atomczak/Sample-BIM-Files/main/IDS/Invalid_IDS_Wall_needs_classification.xml" + # self.assertRaises( XMLSchemaChildrenValidationError, ids.parse(read_web_file(IDS_URL)) ) + """ IDS authoring """ + # TODO """ IFC validation with IDS """ + # TODO """ IDS validation results """ + # TODO if __name__ == '__main__':