Merge pull request #25 from bauerj/util-test
Add unit tests for the methods in util
This commit is contained in:
commit
60e003df31
48
tests/test_util.py
Normal file
48
tests/test_util.py
Normal file
@ -0,0 +1,48 @@
|
||||
from lib import util
|
||||
|
||||
|
||||
def test_cachedproperty():
|
||||
class Target:
|
||||
def __init__(self):
|
||||
self.call_count = 0
|
||||
|
||||
@util.cachedproperty
|
||||
def prop(self):
|
||||
self.call_count += 1
|
||||
return self.call_count
|
||||
|
||||
t = Target()
|
||||
assert t.prop == t.prop == 1
|
||||
|
||||
|
||||
def test_deep_getsizeof():
|
||||
int_t = util.deep_getsizeof(1)
|
||||
assert util.deep_getsizeof([1, 1]) > 2 * int_t
|
||||
assert util.deep_getsizeof({1: 1}) > 2 * int_t
|
||||
assert util.deep_getsizeof({1: {1: 1}}) > 3 * int_t
|
||||
|
||||
|
||||
class Base:
|
||||
pass
|
||||
|
||||
|
||||
class A(Base):
|
||||
pass
|
||||
|
||||
|
||||
class B(Base):
|
||||
pass
|
||||
|
||||
|
||||
def test_subclasses():
|
||||
assert util.subclasses(Base) == [A, B]
|
||||
|
||||
|
||||
def test_chunks():
|
||||
assert list(util.chunks([1, 2, 3, 4, 5], 2)) == [[1, 2], [3, 4], [5]]
|
||||
|
||||
|
||||
def test_increment_byte_string():
|
||||
assert util.increment_byte_string(b'1') == b'2'
|
||||
assert util.increment_byte_string(b'\x01\x01') == b'\x01\x02'
|
||||
assert util.increment_byte_string(b'\xff\xff') == b'\x01\x00\x00'
|
||||
Loading…
Reference in New Issue
Block a user