Skip to content

Commit

Permalink
added some things, v2.25.4
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmaslanka committed Aug 30, 2024
1 parent 2fd9b7c commit 7f7fe8d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion satella/coding/structures/singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions satella/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def __enter__(self):

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


Expand Down
8 changes: 4 additions & 4 deletions satella/instrumentation/memory/get_object_size.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import platform
import sys


Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def test_monotonous(self):
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'))
Expand Down
9 changes: 6 additions & 3 deletions tests/test_instrumentation/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ def can_fire(self, *args) -> bool:


class TestMemory(unittest.TestCase):
@unittest.skipIf(platform.python_implementation(), 'This will not work on PyPy')
def test_get_size_dict(self):
a = {'aba': 'aba'}

class Aba:
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):
Expand Down

0 comments on commit 7f7fe8d

Please sign in to comment.