Skip to content

Commit

Permalink
Fix callback typo and add tests for it
Browse files Browse the repository at this point in the history
  • Loading branch information
gaogaotiantian committed Dec 9, 2020
1 parent ba0f6b6 commit d0e3a01
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/watchpoints/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def tracefunc(self, frame, event, arg):
for elem in self.watch_list:
changed, exist = elem.changed(frame)
if changed:
if elem.callback:
if elem._callback:
elem._callback(frame, elem, (self._prev_funcname, self._prev_filename, self._prev_lineno))
else:
self._callback(frame, elem, (self._prev_funcname, self._prev_filename, self._prev_lineno))
Expand Down
2 changes: 1 addition & 1 deletion src/watchpoints/watch_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, frame, node, alias=None, default_alias=None, printer=None, ca
self.alias = alias
self.default_alias = default_alias
self.printer = printer
self.callback = callback
self._callback = callback
self.exist = True

def changed(self, frame):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ def __init__(self):
obj.a = 2
self.assertEqual(cb.counter, 1)

def test_element_callback(self):
cb = CB()
a = [1, 2, 3]
watch(a, callback=cb)
a[0] = 2
a.append(4)
b = a
b.append(5)
a = {"a": 1}
a["b"] = 2

def change(d):
d["c"] = 3

change(a)

self.assertEqual(cb.counter, 6)
unwatch()

def test_printer(self):
watch.restore()
s = io.StringIO()
Expand Down

0 comments on commit d0e3a01

Please sign in to comment.