From 562dc72129207180752aa32e026f98eea174a2ec Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 6 Aug 2020 18:32:33 +1000 Subject: [PATCH] Publish implementation of geocoding MicroMVD --- .../features/steps/element_classes.py | 6 +- src/ifcbimtester/features/steps/geocoding.py | 69 +++++++++++++++++++ src/ifcbimtester/features/steps/utils.py | 18 ++++- 3 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 src/ifcbimtester/features/steps/geocoding.py diff --git a/src/ifcbimtester/features/steps/element_classes.py b/src/ifcbimtester/features/steps/element_classes.py index d0330d85e4..f296a3f59c 100644 --- a/src/ifcbimtester/features/steps/element_classes.py +++ b/src/ifcbimtester/features/steps/element_classes.py @@ -1,16 +1,16 @@ from behave import step -from utils import IfcFile, assert_attribute +from utils import IfcFile, assert_attribute, assert_type @step('The element {guid} is an {ifc_class} only') def step_impl(context, guid, ifc_class): element = IfcFile.by_guid(guid) - assert element.is_a() == ifc_class, 'The element {} is an {} instead of {}.'.format(element, element.is_a(), ifc_class) + assert_type(element, ifc_class, is_exact=True) @step('The element {guid} is an {ifc_class}') def step_impl(context, guid, ifc_class): element = IfcFile.by_guid(guid) - assert element.is_a(ifc_class), 'The element {} is an {} instead of {}.'.format(element, element.is_a(), ifc_class) + assert_type(element, ifc_class) @step('The element {guid} is further defined as a {predefined_type}') diff --git a/src/ifcbimtester/features/steps/geocoding.py b/src/ifcbimtester/features/steps/geocoding.py new file mode 100644 index 0000000000..daf690a62e --- /dev/null +++ b/src/ifcbimtester/features/steps/geocoding.py @@ -0,0 +1,69 @@ +from behave import step +from utils import IfcFile, assert_attribute, assert_type + +def check_geocode_attribute(guid, ifc_class, name, value): + element = IfcFile.by_guid(guid) + assert_type(element, ifc_class) + assert_attribute(element, name, value) + + +def check_geocode_address(guid, ifc_class, name, value): + element = IfcFile.by_guid(guid) + assert_type(element, ifc_class) + if ifc_class == 'IfcSite': + address_name = 'SiteAddress' + elif ifc_class == 'IfcBuilding': + address_name = 'BuildingAddress' + assert_attribute(element, address_name) + assert_attribute(getattr(element, address_name), name, value) + + +use_step_matcher('re') +@step('The (site|building|facility) (?P.*) has a name of (?P.*)') +def step_impl(context, _unused, guid, name): + check_geocode_attribute(guid, 'IfcSite', 'Name', name) + + +@step('The (site|building|facility) (?P.*) has a description of (?P.*)') +def step_impl(context, _unused, guid, description): + check_geocode_attribute(guid, 'IfcSite', 'Description', description) + + +@step('The (site|building) (?P.*) has a land title number of (?P.*)') +def step_impl(context, _unused, guid, land_title_number): + check_geocode_attribute(guid, 'IfcSite', 'LandTitleNumber', land_title_number) + + +@step('The (site|building) (?P.*) has the address "(?P.*)"') +def step_impl(context, _unused, guid, address_lines): + check_geocode_address(guid, 'IfcSite', 'AddressLines', address_lines.split('\\n')) + + +@step('The (site|building) (?P.*) has a postal box of (?P.*)') +def step_impl(context, _unused, guid, postal_box): + check_geocode_address(guid, 'IfcSite', 'PostalBox', postal_box) + + +@step('The (site|building) (?P.*) is in the town (?P.*)') +def step_impl(context, _unused, guid, town): + check_geocode_address(guid, 'IfcSite', 'Town', town) + + +@step('The (site|building) (?P.*) is in the region (?P.*)') +def step_impl(context, _unused, guid, region): + check_geocode_address(guid, 'IfcSite', 'Region', region) + + +@step('The (site|building) (?P.*) has a post code of (?P.*)') +def step_impl(context, _unused, guid, post_code): + check_geocode_address(guid, 'IfcSite', 'PostalCode', post_code) + + +@step('The (site|building) (?P.*) is in the country (?P.*)') +def step_impl(context, _unused, guid, country): + check_geocode_address(guid, 'IfcSite', 'Country', country) + + +@step('The (site|building) (?P.*) has an address description of (?P.*)') +def step_impl(context, _unused, guid, description): + check_geocode_address(guid, 'IfcSite', 'Description', description) diff --git a/src/ifcbimtester/features/steps/utils.py b/src/ifcbimtester/features/steps/utils.py index 1dfc29c0c8..a8f6b1604d 100644 --- a/src/ifcbimtester/features/steps/utils.py +++ b/src/ifcbimtester/features/steps/utils.py @@ -29,12 +29,24 @@ def assert_number(number): except ValueError: assert False, 'A number should be specified, not {}'.format(number) -def assert_attribute(element, name, value): - if value == 'NULL': - value = None +def assert_type(element, ifc_class, is_exact = False): + if is_exact: + assert element.is_a() == ifc_class, 'The element {} is an {} instead of {}.'.format(element, element.is_a(), ifc_class) + else: + assert element.is_a(ifc_class), 'The element {} is an {} instead of {}.'.format(element, element.is_a(), ifc_class) + +def assert_attribute(element, name, value=None): if not hasattr(element, name): assert False, 'The element {} does not have the attribute {}'.format(element, name) + if not value: + if getattr(element, name) is None: + assert False, 'The element {} does not have a value for the attribute {}'.format(element, name) + return + if value == 'NULL': + value = None actual_value = getattr(element, name) + if isinstance(value, list): + actual_value = list(actual_value) assert actual_value == value, 'We expected a value of "{}" but instead got "{}" for the element {}'.format(value, actual_value, element) def assert_pset(element, pset_name, prop_name=None, value=None):