[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Fix size_of recursion
commit a58772ea8109c0a4f2d0b1395ab32951950c9191
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Mon Aug 21 12:27:08 2017 -0700
Fix size_of recursion
Baka. Recursing was on our input rather than entries we're iterating on,
effectively making that a no-op. Ran into this with dicts so adding that to our
tests.
---
stem/util/system.py | 2 +-
test/unit/util/system.py | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/stem/util/system.py b/stem/util/system.py
index 0569992b..391c4b70 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -466,7 +466,7 @@ def size_of(obj, exclude = None):
if type(obj) in SIZE_RECURSES:
for entry in SIZE_RECURSES[type(obj)](obj):
- size += size_of(obj, exclude)
+ size += size_of(entry, exclude)
return size
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index a331aab7..0f61963d 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -156,6 +156,8 @@ class TestSystem(unittest.TestCase):
self.assertTrue(10 < system.size_of('hello') < 50)
self.assertTrue(10 < system.size_of([]) < 50)
self.assertTrue(system.size_of([]) < system.size_of(['hello']) < system.size_of(['hello', 'world']))
+ self.assertTrue(100 < system.size_of({'hello': 'world'}) < 300)
+ self.assertTrue(system.size_of({}) < system.size_of({'hello': 'world'}) < system.size_of({'hello': 'world', 'more': 'stuff'}))
@patch('stem.util.system.call')
@patch('stem.util.proc.is_available', Mock(return_value = False))
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits