def test_remove_strict(self): """remove should be strict""" with self.assertRaisesRegex(Exception, r'non-existent'): gpath.remove(self.obj, ["bar", 4]) with self.assertRaisesRegex(Exception, r'not an array'): gpath.remove(self.obj, ["foo"]) with self.assertRaisesRegex(Exception, r'invalid.*index'): gpath.remove(self.obj, ["foo", -1]) with self.assertRaisesRegex(Exception, r'invalid.*index'): gpath.remove(self.obj, ["foo", None])
def test_remove(self): """remove should remove indices""" self.assertEqual(self.obj["foo"], [{"bar": 1}, {"bar": 2}, {"baz": 3}]) gpath.remove(self.obj, ["foo", 0]) self.assertEqual(self.obj["foo"], [{"bar": 2}, {"baz": 3}]) gpath.remove(self.obj, ["foo", 1]) self.assertEqual(self.obj["foo"], [{"bar": 2}]) gpath.remove(self.obj, ["foo", 0]) self.assertEqual(self.obj["foo"], [])
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)