예제 #1
0
    def test_it_can_be_used_as_a_document_to_resolve_a_pointer_in(self):
        ctx = _TestContext(self.id(), {'a': 1, 'b': 2, 'c': 3})
        ref = Reference(ctx, '')

        self.assertEqual(Pointer.resolve_in('/a', ref), 1)
        self.assertEqual(Pointer.resolve_in('/b', ref), 2)
        self.assertEqual(Pointer.resolve_in('/c', ref), 3)
예제 #2
0
    def test_it_offers_support_for_lazy_loaded_values(self):
        class LazyValue:
            def __lazy_eval__(self):
                return {'a': 1, 'b': 2, 'c': 3}

        value = LazyValue()
        self.assertEqual(Pointer.resolve_in('/a', value), 1)
        self.assertEqual(Pointer.resolve_in('/b', value), 2)
        self.assertEqual(Pointer.resolve_in('/c', value), 3)
예제 #3
0
 def test_pointer_resolve_in_can_be_called_as_a_static_method(self):
     self.assertEqual(Pointer.resolve_in('key', {'key': self.sentinel}),
                      self.sentinel)
     self.assertEqual(
         Pointer.resolve_in('key', document={'key': self.sentinel}),
         self.sentinel)
예제 #4
0
 def test_pointer_resolve_in_can_be_called_as_an_instance_method(self):
     self.assertEqual(
         Pointer('key').resolve_in({'key': self.sentinel}), self.sentinel)
     self.assertEqual(
         Pointer('key').resolve_in(document={'key': self.sentinel}),
         self.sentinel)
예제 #5
0
    def test_it_raises_an_error_if_unable_to_resolve_token(self):
        with self.assertRaises(error.UnreferenceableValue):
            Pointer.resolve_in('/key', document=object())

        with self.assertRaises(error.UnreferenceableValue):
            Pointer.resolve_in('key', document=object())
예제 #6
0
    def test_it_raises_an_error_on_unescaped_tilde(self):
        with self.assertRaises(error.UnescapedTilde):
            Pointer.resolve_in('/~', document={})

        with self.assertRaises(error.UnescapedTilde):
            Pointer.resolve_in('~', document={})
예제 #7
0
    def test_it_raises_an_error_on_unrecognized_escape_sequences(self):
        with self.assertRaises(error.UnrecognizedEscapeSequence):
            Pointer.resolve_in('/~2', document={})

        with self.assertRaises(error.UnrecognizedEscapeSequence):
            Pointer.resolve_in('~2', document={})
예제 #8
0
    def check_pointer_equal(self, document, pointer, value):
        self.assertEqual(Pointer.resolve_in(pointer, document), value)

        # test that starting slash in non-empty pointer is optional
        if (len(pointer) > 1 and pointer[0] == '/'):
            self.assertEqual(Pointer.resolve_in(pointer[1:], document), value)
예제 #9
0
    def test_it_raises_an_error_if_key_not_in_document(self):
        with self.assertRaises(error.MemberNotDefined):
            Pointer.resolve_in('/key', document={})

        with self.assertRaises(error.MemberNotDefined):
            Pointer.resolve_in('key', document={})
예제 #10
0
    def test_it_raises_an_error_for_non_numeric_array_index(self):
        with self.assertRaises(error.InvalidArrayIndex):
            Pointer.resolve_in('/key', document=[])

        with self.assertRaises(error.InvalidArrayIndex):
            Pointer.resolve_in('key', document=[])
예제 #11
0
    def test_it_raises_an_error_for_array_index_out_of_range(self):
        with self.assertRaises(error.IndexOutOfRange):
            Pointer.resolve_in('/5', document=[])

        with self.assertRaises(error.IndexOutOfRange):
            Pointer.resolve_in('5', document=[])
예제 #12
0
    def test_it_raises_an_error_for_dash_as_an_array_index(self):
        with self.assertRaises(error.DashArrayIndexNotSupported):
            Pointer.resolve_in('/-', document=[])

        with self.assertRaises(error.DashArrayIndexNotSupported):
            Pointer.resolve_in('-', document=[])