Exemplo n.º 1
0
 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"])
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
 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)