readability
This commit is contained in:
@@ -12,48 +12,51 @@ def get_id(a: Any):
|
|||||||
class TestHookedList:
|
class TestHookedList:
|
||||||
class TestConstruction:
|
class TestConstruction:
|
||||||
def test_empty(self):
|
def test_empty(self):
|
||||||
lst = HookedList(existing=[])
|
lst = HookedList([])
|
||||||
assert list(lst) == []
|
assert list(lst) == []
|
||||||
|
|
||||||
def test_with_items(self):
|
def test_with_items(self):
|
||||||
lst = HookedList(existing=[1, 2, 3])
|
lst = HookedList([1, 2, 3])
|
||||||
assert list(lst) == [1, 2, 3]
|
assert list(lst) == [1, 2, 3]
|
||||||
|
|
||||||
def test_recreation(self):
|
def test_recreation(self):
|
||||||
initial = [1, 2, 3]
|
initial = [1, 2, 3]
|
||||||
initial_id = id(initial)
|
initial_id = id(initial)
|
||||||
|
|
||||||
lst = HookedList(existing=initial)
|
lst = HookedList(initial)
|
||||||
assert id(lst._data) == initial_id
|
assert id(lst._data) == initial_id
|
||||||
|
|
||||||
lst2 = HookedList(existing=lst)
|
lst2 = HookedList(lst)
|
||||||
assert id(lst2._data) == initial_id
|
assert id(lst2._data) == initial_id
|
||||||
|
|
||||||
class TestSeqOps:
|
class TestSeqOps:
|
||||||
def test_len(self):
|
def test_len(self):
|
||||||
lst = HookedList(existing=[1, 2, 3])
|
lst = HookedList([1, 2, 3])
|
||||||
assert len(lst) == 3
|
assert len(lst) == 3
|
||||||
|
|
||||||
def test_getitem(self):
|
def test_getitem(self):
|
||||||
lst = HookedList(existing=[1, 2, 3])
|
lst = HookedList([1, 2, 3])
|
||||||
assert lst[0] == 1
|
assert lst[0] == 1
|
||||||
assert lst[1] == 2
|
assert lst[1] == 2
|
||||||
assert lst[-1] == 3
|
assert lst[-1] == 3
|
||||||
|
|
||||||
def test_contains(self):
|
def test_contains(self):
|
||||||
lst = HookedList(existing=[1, 2, 3])
|
lst = HookedList([1, 2, 3])
|
||||||
assert 2 in lst
|
assert 2 in lst
|
||||||
assert 4 not in lst
|
assert 4 not in lst
|
||||||
|
|
||||||
def test_iter(self):
|
def test_iter(self):
|
||||||
lst = HookedList(existing=[1, 2, 3])
|
lst = HookedList([1, 2, 3])
|
||||||
for i, item in enumerate(lst, start=1):
|
for i, item in enumerate(lst, start=1):
|
||||||
assert item == i
|
assert item == i
|
||||||
|
|
||||||
class TestMutableOps:
|
class TestMutableOps:
|
||||||
def test_setitem(self):
|
def test_setitem(self):
|
||||||
added = []
|
added = []
|
||||||
lst = HookedList([1, 2, [4, 5, [6, 7]]], lambda e: added.append(e.item))
|
lst = HookedList(
|
||||||
|
[1, 2, [4, 5, [6, 7]]],
|
||||||
|
lambda e: added.append(e.item),
|
||||||
|
)
|
||||||
lst[0] = 10
|
lst[0] = 10
|
||||||
lst.append(20)
|
lst.append(20)
|
||||||
assert added == [10, 20]
|
assert added == [10, 20]
|
||||||
@@ -62,11 +65,11 @@ class TestHookedList:
|
|||||||
assert added == [10, 20, 8]
|
assert added == [10, 20, 8]
|
||||||
|
|
||||||
def test_delitem(self):
|
def test_delitem(self):
|
||||||
lst = HookedList(existing=[1, 2, 3])
|
lst = HookedList([1, 2, 3])
|
||||||
del lst[1]
|
del lst[1]
|
||||||
assert list(lst) == [1, 3]
|
assert list(lst) == [1, 3]
|
||||||
|
|
||||||
def test_insert(self):
|
def test_insert(self):
|
||||||
lst = HookedList(existing=[1, 3])
|
lst = HookedList([1, 3])
|
||||||
lst.insert(1, 2)
|
lst.insert(1, 2)
|
||||||
assert list(lst) == [1, 2, 3]
|
assert list(lst) == [1, 2, 3]
|
||||||
|
|||||||
Reference in New Issue
Block a user