MCPcopy Create free account
hub / github.com/cdgriffith/Box / test_box_list_index_changes

Method test_box_list_index_changes

test/test_comments.py:253–286  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

251 assert target.settings.get_comment("host") == {"eol": "bind address"}
252
253 def test_box_list_index_changes(self):
254 bl = BoxList(["a", "b", "c", "d"])
255 for index in range(4):
256 bl.set_comment(index, "abcd"[index])
257
258 def comments():
259 return [(bl.get_comment(i) or {}).get("eol") for i in range(len(bl))]
260
261 bl.insert(1, "new")
262 assert comments() == ["a", None, "b", "c", "d"]
263 bl.pop(1)
264 assert comments() == ["a", "b", "c", "d"]
265 del bl[0]
266 assert comments() == ["b", "c", "d"]
267 bl.remove("c")
268 assert comments() == ["b", "d"]
269 bl.insert(-1, "x")
270 assert bl == ["b", "x", "d"] and comments() == ["b", None, "d"]
271 bl.reverse()
272 assert comments() == ["d", None, "b"]
273 bl.sort()
274 assert bl == ["b", "d", "x"] and comments() == ["b", "d", None]
275 bl.sort(key=lambda v: v == "b", reverse=True)
276 assert bl == ["b", "d", "x"] and comments() == ["b", "d", None]
277 bl.append("e")
278 bl += ["f"]
279 assert comments() == ["b", "d", None, None, None]
280 bl.pop()
281 bl[0:2] = ["y"] # slice writes drop the list's item comments
282 assert comments() == [None, None, None]
283 bl.set_comment(0, "again")
284 bl.clear()
285 bl.append(1)
286 assert bl.get_comment(0) is None
287
288 def test_box_list_copies_and_pickles(self):
289 bl = BoxList.from_yaml("- 1 # one\n- 2\n")

Callers

nothing calls this directly

Calls 10

set_commentMethod · 0.95
insertMethod · 0.95
popMethod · 0.95
removeMethod · 0.95
reverseMethod · 0.95
sortMethod · 0.95
appendMethod · 0.95
clearMethod · 0.95
get_commentMethod · 0.95
BoxListClass · 0.90

Tested by

no test coverage detected