From cb71a04a44560b8d747d8f9647d7acf4f9ddffde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Tue, 24 Aug 2021 17:39:32 +0200 Subject: [PATCH] fix ver --- satella/instrumentation/memory/get_object_size.py | 6 +++++- tests/test_instrumentation/test_memory.py | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/satella/instrumentation/memory/get_object_size.py b/satella/instrumentation/memory/get_object_size.py index fae6a179..63ed7a7f 100644 --- a/satella/instrumentation/memory/get_object_size.py +++ b/satella/instrumentation/memory/get_object_size.py @@ -9,8 +9,12 @@ def get_size(obj, seen=None) -> int: :param obj: object to measure :return: size in bytes of the object and all of it's subcomponents + :raises RuntimeError: when ran on PyPy """ - size = sys.getsizeof(obj) + try: + size = sys.getsizeof(obj) + except TypeError: + raise RuntimeError('Running on PyPy?') if seen is None: seen = set() obj_id = id(obj) diff --git a/tests/test_instrumentation/test_memory.py b/tests/test_instrumentation/test_memory.py index 3b73a9a8..7fa6daeb 100644 --- a/tests/test_instrumentation/test_memory.py +++ b/tests/test_instrumentation/test_memory.py @@ -1,5 +1,6 @@ import logging import os +import platform import signal import sys @@ -27,10 +28,16 @@ class TestMemory(unittest.TestCase): install_dump_frames_on(signal.SIGUSR1) os.kill(os.getpid(), signal.SIGUSR1) + @unittest.skipIf(platform.python_implementation() == 'PyPy', 'does not work on PyPy') def test_get_size(self): a = 'a' * 1024 self.assertGreaterEqual(get_size(a), 1024) + @unittest.skipIf(platform.python_implementation() != 'PyPy', 'requires PyPy') + def test_get_size_runtime_error(self): + a = 'a' * 1024 + self.assertRaises(RuntimeError, lambda: get_size(a)) + def test_dump_memory(self): dump_memory_on() -- GitLab