def test___copy__(self): a1 = NestedList([[["foo"]]]) a2 = copy.copy(a1) self.assertIsNot(a1, a2) self.assertEqual(a1, a2) a1.set((ListIndex(0), ListIndex(0), ListIndex(0)), "bar") self.assertEqual(a1, a2)
def test___deepcopy__(self): a1 = NestedList([[["foo"]]]) a2 = copy.deepcopy(a1) self.assertIsNot(a1, a2) self.assertEqual(a1, a2) a1.data[0][0][0] = "bar" self.assertNotEqual(a1, a2)
def test___eq____different_class__returns_True(self): a1 = NestedList(["v"]) a2 = ["v"] self.assertTrue(a1 == a2) a3 = NestedList() a4 = [] self.assertTrue(a3 == a4)
def test_collapse__function_arg(self): a = NestedList([[["v"]]]) def detect_operator(key, value, container): return container is NestedList and value == "v" b = a.collapse(func=detect_operator) self.assertEqual(b, {(ListIndex(0), ListIndex(0)): ["v"]})
def test_merge__incompatible_types(self): a = NestedList([[["v"]]]) b = a.merge("foo") self.assertEqual(b, [[["v"]]])
def test_merge__nested_list_arg(self): a = NestedList([[["foo"]]]) b = a.merge([[["bar"]]]) self.assertEqual(b, [[["bar"]]])
def test_merge__NestedDict_param(self): a = NestedList([[["foo"]]]) b = a.merge(NestedList([[["bar"]]])) self.assertEqual(b, [[["bar"]]])
def test_push__path_arg(self): a = NestedList([[["foo"]]]) a.push((ListIndex(0), ListIndex(0)), "bar") self.assertEqual(a, [[["foo", "bar"]]])
def test__merge__unequal_length_sequences(self): a = NestedList(["foo", "bar"]) self.assertEqual(["baz", "bar"], a.merge(["baz"]))
def test_push__False_create_arg__raises_IndexError(self): a = NestedList() with self.assertRaises(IndexError): a.push(ListIndex(0), "foo", create=False)
def test___bool____empty_data__returns_False(self): self.assertFalse(bool(NestedList()))
def test__expand(self): a = NestedList([[["v"]]]) b = a._expand(a.collapse()) self.assertEqual(b, a.get())
def test___init____list_arg(self): a = NestedList(["v"]) self.assertEqual(a, ["v"])
def test_pull__path_arg___raises_IndexError(self): a = NestedList() with self.assertRaises(IndexError): a.pull(ListIndex(0), "v")
def test_pull__path_arg__raises_ValueError(self): a = NestedList([["foo"]]) with self.assertRaises(ValueError): a.pull(ListIndex(0), "bar")
def test_pull__cleanup_arg_True__removes_empty_containers(self): a = NestedList([[["v"]]]) a.pull((ListIndex(0), ListIndex(0)), "v", cleanup=True) self.assertEqual(a, [[]])
def test_pull__index_arg(self): a = NestedList([["foo"]]) a.pull(ListIndex(0), "foo") self.assertEqual(a, [[]])
def test_push__False_create_arg__raises_TypeError(self): a = NestedList(["foo"]) with self.assertRaises(AttributeError): a.push(ListIndex(0), "bar", create=False)
def test_collapse(self): a = NestedList(["v"]) b = a.collapse() self.assertEqual(b, {(ListIndex(0), ): 'v'})
def test___call____no_args(self): a = NestedList(["v"]) a() self.assertEqual(a, [])
def test_pull__path_arg__raises_TypeError(self): a = NestedList(["v"]) with self.assertRaises(TypeError): a.pull((ListIndex(0), ListIndex(0)), "v")
def test_push__True_create_arg__creates_list(self): a = NestedList([[]]) a.push(ListIndex(0), "bar") self.assertEqual(a, [["bar"]])
def test___init____no_args(self): a = NestedList() self.assertEqual(a.data, [])
def test_unset__path_arg(self): a = NestedList([[["v"]]]) a.unset((ListIndex(0), ListIndex(0))) self.assertEqual(a, [[]])
def test___init____raises_TypeError(self): with self.assertRaises(TypeError): a = NestedList("foo")
def test_unset__cleanup_arg_True__removes_empty_containers(self): a = NestedList([[["v"]]]) a.unset((ListIndex(0), ListIndex(0)), cleanup=True) self.assertEqual(a, [])
def test___call____dict_arg(self): a = NestedList() a(["v"]) self.assertEqual(a, ["v"])
def test_unset__path_arg__raises_IndexError(self): a = NestedList([[["v"]]]) with self.assertRaises(IndexError): a.unset((ListIndex(1), ListIndex(0)))
def test___bool____non_empty_data__returns_True(self): self.assertTrue(bool(NestedList(["v"])))
def test__merge(self): a = NestedList(["v"]) self.assertEqual(["foo"], a.merge(["foo"]))