Skip to content
Snippets Groups Projects
Commit d1a64d1a authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

Merge branch 'master' into develop

parents 0687fbdc cb71a04a
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment