Debian Codegraph @

tests/test_ldapvaluelist.py

raw symbols SCIP
1 import pytest
2
3 from bonsai.ldapvaluelist import LDAPValueList
4
5
6 def test_append():
7 """ Test LDAPValueList's append method. """
8 lvl = LDAPValueList()
9 lvl.append("test")
10 assert "test" in lvl
11 with pytest.raises(ValueError):
12 lvl.append("Test")
13
14
15 def test_insert():
16 """ Test LDAPValueList's insert method. """
17 lvl = LDAPValueList(("test1",))
18 lvl.insert(0, "test2")
19 assert lvl == ["test2", "test1"]
20 with pytest.raises(ValueError):
21 lvl.insert(2, "test2")
22
23
24 def test_remove():
25 """ Test LDAPValueList's remove method. """
26 lvl = LDAPValueList(("test1", "test2"))
27 lvl.remove("Test1")
28 assert lvl == ["test2"]
29 with pytest.raises(ValueError):
30 lvl.remove("test1")
31
32
33 def test_set():
34 """ Test LDAPValueList's __setitem__ method. """
35 lvl = LDAPValueList()
36 lvl[0:2] = ("test1", "test2", "test3")
37 lvl[1] = "test4"
38 assert lvl == ["test1", "test4", "test3"]
39 with pytest.raises(ValueError):
40 lvl[1] = "test3"
41 with pytest.raises(ValueError):
42 lvl[1:3] = ["test5", "test1"]
43 del lvl[0:2]
44 assert lvl == ["test3"]
45 del lvl[0]
46 assert lvl == []
47 lvl = LDAPValueList([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
48 del lvl[slice(1, 10, 2)]
49 assert lvl == [1, 3, 5, 7, 9, 11, 12]
50 lvl[slice(2, 6, 2)] = (13, 14)
51 assert lvl == [1, 3, 13, 7, 14, 11, 12]
52
53
54 def test_extend():
55 """ Test LDAPValueList's extend method. """
56 lvl = LDAPValueList(("test1",))
57 lvl.extend(("test2", "test3"))
58 assert lvl == ["test1", "test2", "test3"]
59 with pytest.raises(ValueError):
60 lvl.extend(("test4", "test1"))
61
62
63 def test_pop():
64 """ Test LDAPValueList's pop method. """
65 lvl = LDAPValueList(("test1", "test2"))
66 assert lvl.pop(0) == "test1"
67 assert lvl == ["test2"]
68 lvl.pop()
69 assert lvl == []
70 with pytest.raises(IndexError):
71 lvl.pop()
72
73
74 def test_copy():
75 """ Test LDAPValueList's copy method. """
76 lvl1 = LDAPValueList(("test1", "test2"))
77 lvl2 = lvl1.copy()
78 assert lvl1 == lvl2
79 assert lvl1.status == lvl2.status
80
81
82 def test_add():
83 """ Test adding list to an LDAPValueList. """
84 lvl = LDAPValueList((1, 2, 3))
85 assert lvl + [4, 5] == [1, 2, 3, 4, 5]
86 with pytest.raises(TypeError):
87 _ = lvl + 3
88 with pytest.raises(TypeError):
89 lvl += "x"
90 lvl += [4, 5]
91 assert lvl == [1, 2, 3, 4, 5]
92
93
94 def test_mul():
95 """ Test multiplying an LDAPValueList. """
96 lvl = LDAPValueList((1, 2, 3))
97 with pytest.raises(TypeError):
98 _ = lvl * 3
99
100
101 def test_set_status():
102 """ Test setting LDAPValueList's status. """
103 lvl = LDAPValueList()
104 with pytest.raises(TypeError):
105 lvl.status = "a"
106 with pytest.raises(ValueError):
107 lvl.status = -1
108 lvl.status = 2
109 assert lvl.status == 2
110
111
112 def test_clear():
113 """ Test setting LDAPValueList's clear method. """
114 lvl = LDAPValueList((1, 2, 3))
115 lvl.append(4)
116 lvl.clear()
117 assert lvl == []
118
119
120 def test_readonly_attrs():
121 """ Test modifying read-only attributes. """
122 lvl = LDAPValueList((1, 2, 3))
123 with pytest.raises(AttributeError):
124 lvl.added = [1, 2, 3]
125 with pytest.raises(AttributeError):
126 lvl.deleted = [1, 2, 3]
127 with pytest.raises(AttributeError):
128 lvl._status_dict = {"status": 2}