Skip to content

Commit

Permalink
Improved docs of GarbateTracker class; streamlined decorator call to …
Browse files Browse the repository at this point in the history
…assert

Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Feb 14, 2020
1 parent 7a000e6 commit bc9493a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
9 changes: 4 additions & 5 deletions yagot/_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ def wrapper_func(*args, **kwargs):
and reports any garbage objects by raising an AssertionError exception.
"""

tracker = GarbageTracker.get_tracker('decorated')
tracker = GarbageTracker.get_tracker('_yagot.garbage_tracked')
tracker.enable()
tracker.start()

ret = func(*args, **kwargs)

tracker.stop()
if tracker.garbage:
location = "{file}::{func}". \
format(file=func.__module__, func=func.__name__)
tracker.assert_no_garbage(location)
location = "{file}::{func}". \
format(file=func.__module__, func=func.__name__)
tracker.assert_no_garbage(location)

return ret

Expand Down
18 changes: 10 additions & 8 deletions yagot/_garbagetracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ def print_if_garbage(self, location=None, max=10, stream=sys.stdout):
# pylint: disable=redefined-builtin
"""
If there were garbage objects found during the last tracking period,
print the garbage objects.
print the garbage objects (up to a maximum number).
Parameters:
location (string): Location of the testcase (file::func).
location (string): Location of the tracked code, e.g. as
"module::function".
max (int): Maximum number of objects to be printed.
max (int): Maximum number of garbage objects to be printed.
stream: Stream to be printed on.
"""
Expand All @@ -182,15 +183,16 @@ def assert_no_garbage(self, location=None, max=10):
# pylint: disable=redefined-builtin
"""
Assert that there were no garbage objects found during the last
tracking period. Raise AssertionError with a message that describes
the location of the testcase and the garbage objects (up to a maximum
number), otherwise.
tracking period. Otherwise, raise AssertionError with a message that
describes the garbage objects (up to a maximum number).
Parameters:
location (string): Location of the testcase (file::func).
location (string): Location of the tracked code, e.g. as
"module::function".
max (int): Maximum number of garbage bjects to be included.
max (int): Maximum number of garbage objects to be included in the
exception message.
"""
if self.enabled and self.garbage:
ass_str = "{num} garbage objects left by {loc}:\n". \
Expand Down

0 comments on commit bc9493a

Please sign in to comment.