Skip to content

Commit 6474f1e

Browse files
committed
fixes #105 - dynamic assertion on dict work with dict methods
1 parent 1f366c1 commit 6474f1e

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

assertpy/dynamic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ def _wrapper(*args, **kwargs):
9393
if len(args) != 1:
9494
raise TypeError('assertion <%s()> takes exactly 1 argument (%d given)' % (attr, len(args)))
9595

96-
try:
97-
val_attr = getattr(self.val, attr_name)
98-
except AttributeError:
96+
if is_dict:
9997
val_attr = self.val[attr_name]
98+
else:
99+
val_attr = getattr(self.val, attr_name)
100100

101101
if callable(val_attr):
102102
try:

tests/test_dict.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,16 @@ def test_dynamic_assertion_bad_key_failure():
470470
fail('should have raised error')
471471
except AssertionError as ex:
472472
assert_that(str(ex)).is_equal_to('Expected key <foo>, but val has no key <foo>.')
473+
474+
def test_dynamic_assertion_on_reserved_word():
475+
fred = {'def': 'Fred'}
476+
assert_that(fred).is_type_of(dict)
477+
assert_that(fred['def']).is_equal_to('Fred')
478+
assert_that(fred).has_def('Fred')
479+
480+
def test_dynamic_assertion_on_dict_method():
481+
fred = {'update': 'Foo'}
482+
fred.update({'update': 'Fred'})
483+
assert_that(fred).is_type_of(dict)
484+
assert_that(fred['update']).is_equal_to('Fred')
485+
assert_that(fred).has_update('Fred')

0 commit comments

Comments
 (0)