diff --git a/CHANGELOG.md b/CHANGELOG.md index f7902b9f3a8e78391e3287e505962ea4253d3594..5ffe064b8860d17b4855ec53632178508f5d1de0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,3 +4,4 @@ * improved typing for reraise_as * added weak_refs to SingletonWithRegardsTo * added jump_to_directory +* fixed get_size() to RuntimeError on PyPy instead of hanging diff --git a/satella/coding/structures/singleton.py b/satella/coding/structures/singleton.py index 0a7609d8cfbbf1cbd65bc7f89bdb8ed9f4bfaf92..1744c96995394bc47706604733f7f9b2501a78d2 100644 --- a/satella/coding/structures/singleton.py +++ b/satella/coding/structures/singleton.py @@ -61,7 +61,8 @@ def SingletonWithRegardsTo(num_args: int, weak_refs: bool = False): :param weak_refs: if True, then singleton will be stored within a weak dictionary, so that it cleans up after itself when the values are gone. - .. warning:: If you set weak_refs to False and have a potentially unbounded number of arguments, you better watch out. + .. warning:: If you set weak_refs to False and have a potentially unbounded number of argument values, you better + watch out for the memory usage. """ def inner(cls): diff --git a/satella/files.py b/satella/files.py index 04a5b488da4a1c1342a04c6e04910265d515e2fd..eca97481c85c737a621aa51f15e2a2131c2a1e55 100644 --- a/satella/files.py +++ b/satella/files.py @@ -63,8 +63,7 @@ class jump_to_directory(object): def __exit__(self, exc_type, exc_val, exc_tb): assert self.prev_path is not None - with reraise_as(FileNotFoundError): - os.chdir(self.prev_path) + os.chdir(self.prev_path) return False diff --git a/satella/instrumentation/memory/get_object_size.py b/satella/instrumentation/memory/get_object_size.py index ffdeabb52771d6f2cee535bc15fb9447dfa6aa0c..67c604bd312ee9546e51777eb2b256f46d0bef4e 100644 --- a/satella/instrumentation/memory/get_object_size.py +++ b/satella/instrumentation/memory/get_object_size.py @@ -1,3 +1,4 @@ +import platform import sys @@ -11,10 +12,9 @@ def get_size(obj, seen=None) -> int: :return: size in bytes of the object and all of it's subcomponents :raises RuntimeError: when ran on PyPy """ - try: - size = sys.getsizeof(obj) - except TypeError: - raise RuntimeError('Running on PyPy?') + if platform.python_implementation() != 'CPython': + raise RuntimeError('Runnable only on CPython') + size = sys.getsizeof(obj) if seen is None: seen = set() obj_id = id(obj) diff --git a/tests/test_files.py b/tests/test_files.py index 0d3e7f6dfd9019b2aed7a43f7b92c1998696fd67..6206d6f02b99fa2f53df3c1688915be45869fff6 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -20,7 +20,6 @@ class TestFiles(unittest.TestCase): with jump_to_directory('test_d/path'): path = os.getcwd() self.assertTrue(path.endswith('path')) - self.assertTrue(os.path.exists('path')) def test_read_nonexistent_file(self): self.assertRaises(FileNotFoundError, lambda: read_in_file('moot')) diff --git a/tests/test_instrumentation/test_memory.py b/tests/test_instrumentation/test_memory.py index c072e8ce1ab8cd7d53f81d48e02186a75abcaea6..be51355ec22ea06f6910586088be62d5fa17b83c 100644 --- a/tests/test_instrumentation/test_memory.py +++ b/tests/test_instrumentation/test_memory.py @@ -22,7 +22,6 @@ class OnDemandCondition(CustomCondition): class TestMemory(unittest.TestCase): - @unittest.skipIf(platform.python_implementation(), 'This will not work on PyPy') def test_get_size_dict(self): a = {'aba': 'aba'} @@ -30,8 +29,12 @@ class TestMemory(unittest.TestCase): def __init__(self): self.aba = 'aba' - self.assertGreater(get_size(a), 6) - self.assertGreater(get_size(Aba()), 6) + if platform.python_implementation() == 'PyPy': + self.assertRaises(RuntimeError, get_size, a) + self.assertRaises(RuntimeError, get_size, Aba()) + else: + self.assertGreater(get_size(a), 6) + self.assertGreater(get_size(Aba()), 6) @unittest.skipIf(sys.platform == 'win32', 'testable only on unices') def test_install_dump_on(self):