def test_insert(self): self.assertEqual(self.obj["foo"], [{"bar": 1}, {"bar": 2}, {"baz": 3}]) gpath.insert(self.obj, ["foo", 0], "asdf") self.assertEqual(self.obj["foo"], ["asdf", { "bar": 1 }, { "bar": 2 }, { "baz": 3 }]) gpath.insert(self.obj, ["foo", 3], "hello") self.assertEqual(self.obj["foo"], ["asdf", { "bar": 1 }, { "bar": 2 }, "hello", { "baz": 3 }]) gpath.insert(self.obj, ["foo", None], "world") self.assertEqual( self.obj["foo"], ["asdf", { "bar": 1 }, { "bar": 2 }, "hello", { "baz": 3 }, "world"])
def test_insert_strict(self): with self.assertRaisesRegex(Exception, r'not an array'): gpath.insert(self.obj, ["foo"], "asdf") with self.assertRaisesRegex(Exception, r'invalid.*index'): gpath.insert(self.obj, ["foo", -1], 17) with self.assertRaisesRegex(Exception, r'invalid.*index'): gpath.insert(self.obj, ["foo", "foo"], 17)
def test_glob_strict_wildcard(self): """should only support tail wildcard for updates""" with self.assertRaisesRegex(Exception, r'invalid array index'): gpath.remove(self.obj, ["foo", "*"]) with self.assertRaisesRegex(Exception, r'invalid array index'): gpath.insert(self.obj, ["foo", "*"], 1)