Exemplo n.º 1
0
 def test_get_element_from_wrong_index_with_no_exception(self):
     d = [1, 2, 3]
     value, exists = xjpath.path_lookup(d, '@10')
     self.assertIsNone(value)
     self.assertFalse(exists)
Exemplo n.º 2
0
 def test_get_element_from_dict_using_array_index(self):
     d = {'1': '1', '2': '2'}
     value, exists = xjpath.path_lookup(d, '@1')
     self.assertIsNone(value)
     self.assertFalse(exists)
Exemplo n.º 3
0
 def test_type_escape_for_dict(self):
     self.assertEqual(({"1": 1}, True),
                      xjpath.path_lookup({'a{}': {"1": 1}}, 'a\{}', True))
     self.assertEqual(({}, True),
                      xjpath.path_lookup({'a{}': {"1": 1}}, 'a{}', True))
Exemplo n.º 4
0
 def test_type_escape_for_list(self):
     self.assertEqual(([1], True),
                      xjpath.path_lookup({'a[]': [1]}, 'a\[]', True))
     self.assertEqual(([], True),
                      xjpath.path_lookup({'a[]': [1]}, 'a[]', True))
Exemplo n.º 5
0
 def test_type_escape_for_number(self):
     self.assertEqual((123, True),
                      xjpath.path_lookup({'a#': 123}, 'a\#', True))
     self.assertEqual((0, True),
                      xjpath.path_lookup({'a$': 123}, 'a#', True))
Exemplo n.º 6
0
 def test_type_escape_for_float(self):
     self.assertEqual((.1, True),
                      xjpath.path_lookup({'a%': .1}, 'a\%', True))
     self.assertEqual((.0, True),
                      xjpath.path_lookup({'a%': 123}, 'a%', True))
Exemplo n.º 7
0
 def test_path_lookup_array_as_dict(self):
     a = {}
     with self.assertRaises(xjpath.XJPathError):
         xjpath.path_lookup(a, '@first[]')
Exemplo n.º 8
0
 def test_escapes_non_special(self):
     value, exists = xjpath.path_lookup({'v': {'\\': 31}}, r'v.\\')
     self.assertEqual(31, value)
     self.assertTrue(exists)
Exemplo n.º 9
0
 def test_path_create_type_mismatch4(self):
     a = [{}]
     with self.assertRaises(xjpath.XJPathError):
         xjpath.path_lookup(a, '@-1[]')
Exemplo n.º 10
0
 def test_path_lookup_dict_as_array(self):
     a = []
     with self.assertRaises(xjpath.XJPathError):
         xjpath.path_lookup(a, 'a{}')
Exemplo n.º 11
0
 def test_path_create_type_mismatch2(self):
     a = {'a': []}
     with self.assertRaises(xjpath.XJPathError):
         xjpath.path_lookup(a, 'a{}')
Exemplo n.º 12
0
 def test_auto_dict_and_last_array_creations(self):
     a = {}
     xjpath.path_lookup(a, 'a{}.b{}.c[]', True)
     self.assertEqual({'a': {'b': {'c': []}}}, a)
Exemplo n.º 13
0
 def test_auto_dict_creations(self):
     a = {}
     xjpath.path_lookup(a, 'a{}.b{}.c{}', True)
     self.assertEqual({'a': {'b': {'c': {}}}}, a)
Exemplo n.º 14
0
 def test_with_last_escape(self):
     value, exists = xjpath.path_lookup({'v': {'t.t': 31}}, 'v.t\.t')
     self.assertEqual(31, value)
     self.assertTrue(exists)
Exemplo n.º 15
0
 def test_type_escape_for_str(self):
     self.assertEqual(('v', True),
                      xjpath.path_lookup({'a$': 'v'}, 'a\$', True))
     self.assertEqual(('', True),
                      xjpath.path_lookup({'a$': 'a'}, 'a$', True))
Exemplo n.º 16
0
 def test_with_sobachka_escape(self):
     """Sobachka == '@'"""
     value, exists = xjpath.path_lookup({'v': {'@id': 31}}, 'v.\@id')
     self.assertEqual(31, value)
     self.assertTrue(exists)
Exemplo n.º 17
0
 def test_with_star_escape(self):
     value, exists = xjpath.path_lookup({'v': {'*id': 31}}, 'v.\*id')
     self.assertEqual(31, value)
     self.assertTrue(exists)