|
15 | 15 | import pytest
|
16 | 16 |
|
17 | 17 | # this package
|
18 |
| -from domdf_python_tools.bases import Dictable, namedlist |
| 18 | +from domdf_python_tools.bases import Dictable, NamedList, namedlist |
19 | 19 | from domdf_python_tools.utils import printr, printt
|
20 | 20 |
|
21 | 21 |
|
@@ -111,8 +111,80 @@ def test_namedlist(capsys):
|
111 | 111 |
|
112 | 112 | captured = capsys.readouterr()
|
113 | 113 | stdout = captured.out.split("\n")
|
114 |
| - assert stdout[0] == "<class 'domdf_python_tools.bases.namedlist.<locals>.NamedList'>" |
| 114 | + assert stdout[0] == "<class 'domdf_python_tools.bases.namedlist.<locals>.cls'>" |
115 | 115 | assert stdout[1] == "['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']"
|
116 | 116 | assert stdout[2] == (
|
117 | 117 | "ShoppingList['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']"
|
118 | 118 | )
|
| 119 | + |
| 120 | + assert str(type(shopping_list)) == "<class 'domdf_python_tools.bases.namedlist.<locals>.cls'>" |
| 121 | + assert repr( |
| 122 | + shopping_list |
| 123 | + ) == "['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']" |
| 124 | + assert str(shopping_list) == ( |
| 125 | + "ShoppingList['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']" |
| 126 | + ) |
| 127 | + |
| 128 | + |
| 129 | +def test_namedlist_subclass_function(capsys): |
| 130 | + |
| 131 | + class ShoppingList(namedlist()): # type: ignore |
| 132 | + pass |
| 133 | + |
| 134 | + shopping_list = ShoppingList(["egg and bacon", "egg sausage and bacon", "egg and spam", "egg bacon and spam"]) |
| 135 | + assert isinstance(shopping_list, UserList) |
| 136 | + assert shopping_list[0] == "egg and bacon" |
| 137 | + |
| 138 | + printt(shopping_list) |
| 139 | + printr(shopping_list) |
| 140 | + print(shopping_list) |
| 141 | + |
| 142 | + captured = capsys.readouterr() |
| 143 | + stdout = captured.out.split("\n") |
| 144 | + assert stdout[0] == "<class 'tests.test_bases.test_namedlist_subclass_function.<locals>.ShoppingList'>" |
| 145 | + assert stdout[1] == "['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']" |
| 146 | + assert stdout[2] == ( |
| 147 | + "ShoppingList['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']" |
| 148 | + ) |
| 149 | + |
| 150 | + assert str( |
| 151 | + type(shopping_list) |
| 152 | + ) == "<class 'tests.test_bases.test_namedlist_subclass_function.<locals>.ShoppingList'>" |
| 153 | + assert repr( |
| 154 | + shopping_list |
| 155 | + ) == "['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']" |
| 156 | + assert str(shopping_list) == ( |
| 157 | + "ShoppingList['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']" |
| 158 | + ) |
| 159 | + |
| 160 | + |
| 161 | +def test_namedlist_subclass_class(capsys): |
| 162 | + |
| 163 | + class ShoppingList(NamedList): |
| 164 | + pass |
| 165 | + |
| 166 | + shopping_list = ShoppingList(["egg and bacon", "egg sausage and bacon", "egg and spam", "egg bacon and spam"]) |
| 167 | + assert isinstance(shopping_list, UserList) |
| 168 | + assert shopping_list[0] == "egg and bacon" |
| 169 | + |
| 170 | + printt(shopping_list) |
| 171 | + printr(shopping_list) |
| 172 | + print(shopping_list) |
| 173 | + |
| 174 | + captured = capsys.readouterr() |
| 175 | + stdout = captured.out.split("\n") |
| 176 | + assert stdout[0] == "<class 'tests.test_bases.test_namedlist_subclass_class.<locals>.ShoppingList'>" |
| 177 | + assert stdout[1] == "['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']" |
| 178 | + assert stdout[2] == ( |
| 179 | + "ShoppingList['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']" |
| 180 | + ) |
| 181 | + |
| 182 | + assert str( |
| 183 | + type(shopping_list) |
| 184 | + ) == "<class 'tests.test_bases.test_namedlist_subclass_class.<locals>.ShoppingList'>" |
| 185 | + assert repr( |
| 186 | + shopping_list |
| 187 | + ) == "['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']" |
| 188 | + assert str(shopping_list) == ( |
| 189 | + "ShoppingList['egg and bacon', 'egg sausage and bacon', 'egg and spam', 'egg bacon and spam']" |
| 190 | + ) |
0 commit comments