Skip to content

Commit

Permalink
Merge pull request #27 from open205/xlsx-fixes
Browse files Browse the repository at this point in the history
XLSX fixes
  • Loading branch information
nealkruis authored May 27, 2020
2 parents 3020651 + 04e140b commit e854c98
Show file tree
Hide file tree
Showing 5 changed files with 355 additions and 186 deletions.
10 changes: 10 additions & 0 deletions test/test_tk205_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
Unit tests
'''

def test_resolve_ref():
schema = tk205.A205Schema(os.path.join(os.path.dirname(__file__),'..','schema-205',"schema","ASHRAE205.schema.json"))

node = schema.resolve_ref("ASHRAE205.schema.json#/definitions/ASHRAE205")
assert('title' not in node)

def test_get_schema_node():
schema = tk205.A205Schema(os.path.join(os.path.dirname(__file__),'..','schema-205',"schema","ASHRAE205.schema.json"))

Expand Down Expand Up @@ -37,6 +43,10 @@ def test_get_schema_node():
node = schema.get_schema_node([])
assert('required' in node)

# Root node of nested RS
node = schema.get_schema_node(['RS_instance','performance','fan_representation'],[1,None,None])
assert('ASHRAE 205' not in node['description'])

def test_get_representation_node_and_rs_selections():
rep = tk205.load('schema-205/examples/RS0002/RS0002SimpleExampleFile.a205.json')
node, rs_selections = tk205.util.get_representation_node_and_rs_selections(rep, ['RS_instance','performance','DX_system_representation','RS_instance','performance','performance_map_cooling','grid_variables'])
Expand Down
9 changes: 5 additions & 4 deletions tk205/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def process_errors(self, errors, rs_index, parent_level = 0):
messages += self.process_errors(rs_errors, rs_index, len(error.path))
else:
if len(error.path) >= parent_level:
messages.append(f"{error.message} ({'.'.join(error.path)})")
messages.append(f"{error.message} ({'.'.join([str(x) for x in error.path])})")
if len(messages) == 0 and parent_level == 0:
for error in errors:
messages.append(f"{error.message} ({'.'.join(error.path)})")
Expand All @@ -63,9 +63,10 @@ def validate(self, instance):
def resolve(self, node, step_in=True):
if '$ref' in node:
resolution = self.resolve_ref(node['$ref'])
# If this node is a reference to a nested representation, append the required RS_ID
if 'RS' in node:
resolution['RS'] = node['RS']
# Carry other contents from location of reference
for item in node:
if item != '$ref':
resolution[item] = node[item]
else:
resolution = node

Expand Down
4 changes: 2 additions & 2 deletions tk205/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def objects_near_equal(object1, object2, rel_tol=1e-9, abs_tol=0.0):
elif isinstance(object1, list):
if len(object1) != len(object2):
return False
for index, item in enumerate(object1):
if not objects_near_equal(object1[index], object2[index], rel_tol=rel_tol, abs_tol=abs_tol):
for index_item in enumerate(object1):
if not objects_near_equal(object1[index_item[0]], object2[index_item[0]], rel_tol=rel_tol, abs_tol=abs_tol):
return False
elif isinstance(object1, Number):
if not isclose(object1, object2, rel_tol=rel_tol, abs_tol=abs_tol):
Expand Down
Loading

0 comments on commit e854c98

Please sign in to comment.