Skip to content

Commit e0daaba

Browse files
committed
Update tests
1 parent aaccae2 commit e0daaba

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ __pycache__
44
*.so
55
/.coverage
66
/.pytest_cache
7+
/htmlcov

python/cachebox/_cachebox.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def capacity(self) -> int:
9696
def __len__(self) -> int:
9797
return len(self._raw)
9898

99-
def __sizeof__(self):
99+
def __sizeof__(self): # pragma: no cover
100100
return self._raw.__sizeof__()
101101

102102
def __contains__(self, key: KT) -> bool:
@@ -147,10 +147,10 @@ def setdefault(self, key: KT, default: typing.Optional[DT] = None) -> typing.Uni
147147
"""
148148
return self._raw.setdefault(key, default)
149149

150-
def popitem(self) -> typing.NoReturn:
150+
def popitem(self) -> typing.NoReturn: # pragma: no cover
151151
raise NotImplementedError()
152152

153-
def drain(self) -> typing.NoReturn:
153+
def drain(self) -> typing.NoReturn: # pragma: no cover
154154
raise NotImplementedError()
155155

156156
def update(self, iterable: typing.Union["Cache", dict, tuple, typing.Generator]) -> None:
@@ -181,13 +181,13 @@ def __delitem__(self, key: KT) -> None:
181181

182182
def __eq__(self, other) -> bool:
183183
if not isinstance(other, Cache):
184-
return False
184+
return False # pragma: no cover
185185

186186
return self._raw == other._raw
187187

188188
def __ne__(self, other) -> bool:
189189
if not isinstance(other, Cache):
190-
return False
190+
return False # pragma: no cover
191191

192192
return self._raw != other._raw
193193

@@ -268,7 +268,7 @@ def capacity(self) -> int:
268268
def __len__(self) -> int:
269269
return len(self._raw)
270270

271-
def __sizeof__(self):
271+
def __sizeof__(self): # pragma: no cover
272272
return self._raw.__sizeof__()
273273

274274
def __contains__(self, key: KT) -> bool:
@@ -307,7 +307,7 @@ def popitem(self) -> typing.Tuple[KT, VT]:
307307
except _core.CoreKeyError:
308308
raise KeyError() from None
309309

310-
def drain(self, n: int) -> int:
310+
def drain(self, n: int) -> int: # pragma: no cover
311311
if n == 0:
312312
return 0
313313

@@ -342,13 +342,13 @@ def __delitem__(self, key: KT) -> None:
342342

343343
def __eq__(self, other) -> bool:
344344
if not isinstance(other, FIFOCache):
345-
return False
345+
return False # pragma: no cover
346346

347347
return self._raw == other._raw
348348

349349
def __ne__(self, other) -> bool:
350350
if not isinstance(other, FIFOCache):
351-
return False
351+
return False # pragma: no cover
352352

353353
return self._raw != other._raw
354354

python/tests/mixin.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __hash__(self) -> int:
2626
return self.val
2727

2828

29-
def getsizeof(obj, use_sys=True):
29+
def getsizeof(obj, use_sys=True): # pragma: no cover
3030
try:
3131
if use_sys:
3232
return sys.getsizeof(obj)
@@ -36,7 +36,7 @@ def getsizeof(obj, use_sys=True):
3636
return len(obj)
3737

3838

39-
class _TestMixin:
39+
class _TestMixin: # pragma: no cover
4040
CACHE: typing.Type[BaseCacheImpl]
4141

4242
KWARGS: dict = {}
@@ -100,15 +100,6 @@ def test___len__(self):
100100
assert len(cache) == 10
101101
assert cache.is_full()
102102

103-
def test___sizeof__(self):
104-
cache = self.CACHE(10, **self.KWARGS, capacity=10)
105-
106-
# all classes have to implement __sizeof__
107-
# __sizeof__ returns exactly allocated memory size by cache
108-
# but sys.getsizeof add also garbage collector overhead to that, so sometimes
109-
# sys.getsizeof is greater than __sizeof__
110-
getsizeof(cache, False)
111-
112103
def test___bool__(self):
113104
cache = self.CACHE(1, **self.KWARGS, capacity=1)
114105

@@ -146,16 +137,22 @@ def test___setitem__(self):
146137
del cache[2]
147138
del cache[3]
148139

140+
with pytest.raises(KeyError):
141+
del cache["error"]
142+
149143
cache[0]
150144

151145
with pytest.raises(KeyError):
152146
cache[2]
153147

154148
def test___repr__(self):
155-
cache = self.CACHE(2, **self.KWARGS, capacity=2)
149+
cache = self.CACHE(100, **self.KWARGS, capacity=2)
156150
assert str(cache) == repr(cache)
157151
assert repr(cache).startswith(self.CACHE.__name__)
158152

153+
cache.update({i: i for i in range(100)})
154+
assert str(cache) == repr(cache)
155+
159156
def test_insert(self):
160157
cache = self.CACHE(5, **self.KWARGS, capacity=5)
161158

python/tests/test_caches.py

+2
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,5 @@ def test_first_last(self):
8888

8989
assert obj.first() == 1
9090
assert obj.last() == 10
91+
assert obj.first(-1) == obj.last()
92+
assert obj.first(-10000) is None

0 commit comments

Comments
 (0)