def test_test_no_values_deep(self): with self.assertRaises(xjpath.XJPathError): xjpath.strict_path_lookup({'path': {'test': [1]}}, 'path.test.num')
def test_get_all_dict_values_from_top(self): d = {'t1': 1, 't2': 2, 't3': 3, 't4': 4} v = xjpath.strict_path_lookup(d, '*') self.assertTrue(isinstance(v, tuple)) self.assertEqual([1, 2, 3, 4], sorted(v))
def test_test_no_values(self): with self.assertRaises(xjpath.XJPathError): xjpath.strict_path_lookup({}, 'path')
def test_get_element_from_dict_that_is_second_element_in_array(self): d = ['1', {'element': 999}, '3'] v = xjpath.strict_path_lookup(d, '@1.element') self.assertEqual(999, v)
def test_get_element_from_wrong_index_with_exception(self): d = [1, 2, 3] with self.assertRaises(xjpath.XJPathError): xjpath.strict_path_lookup(d, '@10')
def test_get_second_array_element(self): d = [1, 2, 3] v = xjpath.strict_path_lookup(d, '@1') self.assertEqual(2, v)
def test_get_first_array_element(self): d = [1, 2, 3] v = xjpath.strict_path_lookup(d, '@first') self.assertEqual(1, v)
def test_get_all_same_attribute_values_if_dict(self): d = {'l1': {'t0': {'s': 5, 'r': ''}, 't1': {'s': 6, 'r': ''}, 't2': {'s': 7}}} v = xjpath.strict_path_lookup(d, 'l1.*.s') self.assertEqual([5, 6, 7], sorted(v))
def test_get_all_same_attribute_values_if_list(self): d = {'l1': [{'s': 5, 'r': ''}, {'s': 6, 'r': ''}, {'s': 7}]} v = xjpath.strict_path_lookup(d, 'l1.*.s') self.assertEqual((5, 6, 7), v)
def test_get_all_list_values_copy(self): d = {'l1': [1, 2, 3, 4]} v = xjpath.strict_path_lookup(d, 'l1.*') self.assertEqual((1, 2, 3, 4), v)