mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-09 13:52:23 +00:00
Publish implementation of geocoding MicroMVD
This commit is contained in:
@@ -1,16 +1,16 @@
|
|||||||
from behave import step
|
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')
|
@step('The element {guid} is an {ifc_class} only')
|
||||||
def step_impl(context, guid, ifc_class):
|
def step_impl(context, guid, ifc_class):
|
||||||
element = IfcFile.by_guid(guid)
|
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}')
|
@step('The element {guid} is an {ifc_class}')
|
||||||
def step_impl(context, guid, ifc_class):
|
def step_impl(context, guid, ifc_class):
|
||||||
element = IfcFile.by_guid(guid)
|
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}')
|
@step('The element {guid} is further defined as a {predefined_type}')
|
||||||
|
|||||||
@@ -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<guid>.*) has a name of (?P<name>.*)')
|
||||||
|
def step_impl(context, _unused, guid, name):
|
||||||
|
check_geocode_attribute(guid, 'IfcSite', 'Name', name)
|
||||||
|
|
||||||
|
|
||||||
|
@step('The (site|building|facility) (?P<guid>.*) has a description of (?P<description>.*)')
|
||||||
|
def step_impl(context, _unused, guid, description):
|
||||||
|
check_geocode_attribute(guid, 'IfcSite', 'Description', description)
|
||||||
|
|
||||||
|
|
||||||
|
@step('The (site|building) (?P<guid>.*) has a land title number of (?P<land_title_number>.*)')
|
||||||
|
def step_impl(context, _unused, guid, land_title_number):
|
||||||
|
check_geocode_attribute(guid, 'IfcSite', 'LandTitleNumber', land_title_number)
|
||||||
|
|
||||||
|
|
||||||
|
@step('The (site|building) (?P<guid>.*) has the address "(?P<address_lines>.*)"')
|
||||||
|
def step_impl(context, _unused, guid, address_lines):
|
||||||
|
check_geocode_address(guid, 'IfcSite', 'AddressLines', address_lines.split('\\n'))
|
||||||
|
|
||||||
|
|
||||||
|
@step('The (site|building) (?P<guid>.*) has a postal box of (?P<postal_box>.*)')
|
||||||
|
def step_impl(context, _unused, guid, postal_box):
|
||||||
|
check_geocode_address(guid, 'IfcSite', 'PostalBox', postal_box)
|
||||||
|
|
||||||
|
|
||||||
|
@step('The (site|building) (?P<guid>.*) is in the town (?P<town>.*)')
|
||||||
|
def step_impl(context, _unused, guid, town):
|
||||||
|
check_geocode_address(guid, 'IfcSite', 'Town', town)
|
||||||
|
|
||||||
|
|
||||||
|
@step('The (site|building) (?P<guid>.*) is in the region (?P<region>.*)')
|
||||||
|
def step_impl(context, _unused, guid, region):
|
||||||
|
check_geocode_address(guid, 'IfcSite', 'Region', region)
|
||||||
|
|
||||||
|
|
||||||
|
@step('The (site|building) (?P<guid>.*) has a post code of (?P<post_code>.*)')
|
||||||
|
def step_impl(context, _unused, guid, post_code):
|
||||||
|
check_geocode_address(guid, 'IfcSite', 'PostalCode', post_code)
|
||||||
|
|
||||||
|
|
||||||
|
@step('The (site|building) (?P<guid>.*) is in the country (?P<country>.*)')
|
||||||
|
def step_impl(context, _unused, guid, country):
|
||||||
|
check_geocode_address(guid, 'IfcSite', 'Country', country)
|
||||||
|
|
||||||
|
|
||||||
|
@step('The (site|building) (?P<guid>.*) has an address description of (?P<description>.*)')
|
||||||
|
def step_impl(context, _unused, guid, description):
|
||||||
|
check_geocode_address(guid, 'IfcSite', 'Description', description)
|
||||||
@@ -29,12 +29,24 @@ def assert_number(number):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
assert False, 'A number should be specified, not {}'.format(number)
|
assert False, 'A number should be specified, not {}'.format(number)
|
||||||
|
|
||||||
def assert_attribute(element, name, value):
|
def assert_type(element, ifc_class, is_exact = False):
|
||||||
if value == 'NULL':
|
if is_exact:
|
||||||
value = None
|
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):
|
if not hasattr(element, name):
|
||||||
assert False, 'The element {} does not have the attribute {}'.format(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)
|
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)
|
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):
|
def assert_pset(element, pset_name, prop_name=None, value=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user