Skip to content

Commit

Permalink
Merge pull request #42 from jetavator/issue-41-Update_property_behavi…
Browse files Browse the repository at this point in the history
…our_so_default_and_default_function_don_t_set_a_value_persistently

Issue 41 update property behaviour so default and default function don t set a value persistently
  • Loading branch information
jtv8 authored Jun 12, 2020
2 parents 3fce591 + bc859f6 commit 66a9251
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
38 changes: 33 additions & 5 deletions features/dict.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Feature: Test dictionary DOM objects
"first_name": "Marge",
"last_name": "Simpson",
"current_address": {
"first_line": "123 Fake Street",
"second_line": "",
"city": "Springfield",
"postal_code": 58008
"first_line": "123 Fake Street",
"second_line": "",
"city": "Springfield",
"postal_code": 58008
},
"previous_addresses": [{
"first_line": "742 Evergreen Terrace",
Expand Down Expand Up @@ -199,4 +199,32 @@ Feature: Test dictionary DOM objects
And the following statement raises ValidationError
"""
dict_module.Person(example_dict_input)
"""
"""

Scenario: Defaults should not be written as permanent values when accessed

Given the Python module dict_module.py
When we execute the following python code:
"""
example_dict_input = {
"first_name": "Marge",
"last_name": "Simpson",
"previous_addresses": [{
"first_line": "742 Evergreen Terrace",
"city": "Springfield",
"postal_code": 58008
}]
}
example = dict_module.Person(example_dict_input)
original_address = example.current_address
example.previous_addresses[0] = {
"first_line": "123 Fake Street",
"city": "Springfield",
"postal_code": 58008
}
"""
Then the following statements are true:
"""
example.current_address.first_line == "123 Fake Street"
example.previous_addresses[0].first_line == "123 Fake Street"
"""
2 changes: 1 addition & 1 deletion wysdom/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = (0, 1, 3)
VERSION = (0, 1, 4)

__version__ = '.'.join(map(str, VERSION))
4 changes: 2 additions & 2 deletions wysdom/user_objects/UserProperty.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ def __get__(
"UserProperty is not valid as a class data descriptor")
if self.name not in instance:
if self.default_function:
instance[self.name] = self.default_function(instance)
return self.default_function(instance)
else:
instance[self.name] = self.default
return self.default
return instance[self.name]

def __set__(
Expand Down

0 comments on commit 66a9251

Please sign in to comment.