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"]))
示例#10
0
 def test_push__False_create_arg__raises_IndexError(self):
     a = NestedList()
     with self.assertRaises(IndexError):
         a.push(ListIndex(0), "foo", create=False)
示例#11
0
 def test___bool____empty_data__returns_False(self):
     self.assertFalse(bool(NestedList()))
示例#12
0
 def test__expand(self):
     a = NestedList([[["v"]]])
     b = a._expand(a.collapse())
     self.assertEqual(b, a.get())
示例#13
0
 def test___init____list_arg(self):
     a = NestedList(["v"])
     self.assertEqual(a, ["v"])
示例#14
0
 def test_pull__path_arg___raises_IndexError(self):
     a = NestedList()
     with self.assertRaises(IndexError):
         a.pull(ListIndex(0), "v")
示例#15
0
 def test_pull__path_arg__raises_ValueError(self):
     a = NestedList([["foo"]])
     with self.assertRaises(ValueError):
         a.pull(ListIndex(0), "bar")
示例#16
0
 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, [[]])
示例#17
0
 def test_pull__index_arg(self):
     a = NestedList([["foo"]])
     a.pull(ListIndex(0), "foo")
     self.assertEqual(a, [[]])
示例#18
0
 def test_push__False_create_arg__raises_TypeError(self):
     a = NestedList(["foo"])
     with self.assertRaises(AttributeError):
         a.push(ListIndex(0), "bar", create=False)
示例#19
0
 def test_collapse(self):
     a = NestedList(["v"])
     b = a.collapse()
     self.assertEqual(b, {(ListIndex(0), ): 'v'})
示例#20
0
 def test___call____no_args(self):
     a = NestedList(["v"])
     a()
     self.assertEqual(a, [])
示例#21
0
 def test_pull__path_arg__raises_TypeError(self):
     a = NestedList(["v"])
     with self.assertRaises(TypeError):
         a.pull((ListIndex(0), ListIndex(0)), "v")
示例#22
0
 def test_push__True_create_arg__creates_list(self):
     a = NestedList([[]])
     a.push(ListIndex(0), "bar")
     self.assertEqual(a, [["bar"]])
示例#23
0
 def test___init____no_args(self):
     a = NestedList()
     self.assertEqual(a.data, [])
示例#24
0
 def test_unset__path_arg(self):
     a = NestedList([[["v"]]])
     a.unset((ListIndex(0), ListIndex(0)))
     self.assertEqual(a, [[]])
示例#25
0
 def test___init____raises_TypeError(self):
     with self.assertRaises(TypeError):
         a = NestedList("foo")
示例#26
0
 def test_unset__cleanup_arg_True__removes_empty_containers(self):
     a = NestedList([[["v"]]])
     a.unset((ListIndex(0), ListIndex(0)), cleanup=True)
     self.assertEqual(a, [])
示例#27
0
 def test___call____dict_arg(self):
     a = NestedList()
     a(["v"])
     self.assertEqual(a, ["v"])
示例#28
0
 def test_unset__path_arg__raises_IndexError(self):
     a = NestedList([[["v"]]])
     with self.assertRaises(IndexError):
         a.unset((ListIndex(1), ListIndex(0)))
示例#29
0
 def test___bool____non_empty_data__returns_True(self):
     self.assertTrue(bool(NestedList(["v"])))
示例#30
0
 def test__merge(self):
     a = NestedList(["v"])
     self.assertEqual(["foo"], a.merge(["foo"]))