Skip to content

Commit

Permalink
Address further issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondegraw committed Mar 25, 2024
1 parent 661f557 commit e31476b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/energyplus_version/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def describe(self) -> str:
return 'Change the field named "%s" to "%s".' % (self.old_name, self.new_name)

class AddComputedField(Change):
def __init__(self, object: str, field: str, compute: Callable[[dict, dict], int|float|str|None]=do_not_add):
def __init__(self, object: str, field: str, compute): #: Callable[[dict, dict], int|float|str|None]=do_not_add):
self.object = object
self.field = field
self.compute = compute
Expand All @@ -62,7 +62,7 @@ def _apply(self, object_name:str, value:str) -> list:
path = '/%s/%s/%s' % (self.object, object_name, self.field)
return [{'op': 'add', 'path': path, 'value': value}]
def valid(self, object) -> bool:
return self.old_name in object
return self.field in object
def describe(self) -> str:
return 'Add the field named "%s" with a computed value.' % self.field

Expand Down
4 changes: 2 additions & 2 deletions tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def test_remove_field_all():
def test_map_field_value():
obj = {'Test': {'test_one': {'field_one': 'A', 'field_two': 'B'}}}
change = energyplus_version.MapValues('Test', 'field_one', {'A': 'Z', 'B': 'Y'})
assert change.valid(obj['Test']['test_one'])
patch = change.apply('test_one', obj['Test']['test_one'])
assert change.valid(obj)
patch = change.generate_patch(obj)
assert len(patch) == 1
expected = {'op': 'replace', 'path': '/Test/test_one/field_one', 'value': 'Z'}
assert all((patch[0].get(k) == v for k, v in expected.items()))
Expand Down

0 comments on commit e31476b

Please sign in to comment.