Пример #1
0
    def test_replace(self):
        obj = {'foo': 'bar'}
        response = replace(obj, '/foo', 'quux')
        assert response == {'foo': 'quux'}
        assert response != obj

        with self.assertRaises(Error):
            replace(obj, '/baz', 'quux')
Пример #2
0
    def test_replace(self):
        obj = {'foo': 'bar'}
        response = replace(obj, '/foo', 'quux')
        assert response == {'foo': 'quux'}
        assert response != obj

        with self.assertRaises(Error):
            replace(obj, '/baz', 'quux')
Пример #3
0
 def test_replace_value(self):
     obj = {
         'baz': 'qux',
         'foo': 'bar'
     }
     assert replace(obj, '/baz', 'boo') == {
         'baz': 'boo',
         'foo': 'bar'
     }
Пример #4
0
    def run(self, args):
        parse_pointer(args)
        parse_document(args)
        parse_fragment(args)

        from jsonspec.operations import replace, Error
        from jsonspec.pointer import ParseError

        try:
            response = replace(args.document, args.pointer, args.fragment)
            return driver.dumps(response, indent=args.indent)
        except Error as error:
            raise Exception(error)
        except ParseError as error:
            raise Exception('{} is not a valid pointer'.format(args.pointer))
Пример #5
0
    def run(self, args):
        parse_pointer(args)
        parse_document(args)
        parse_fragment(args)

        from jsonspec.operations import replace, Error
        from jsonspec.pointer import ParseError

        try:
            response = replace(args.document, args.pointer, args.fragment)
            return driver.dumps(response, indent=args.indent)
        except Error as error:
            raise Exception(error)
        except ParseError as error:
            raise Exception('{} is not a valid pointer'.format(args.pointer))
Пример #6
0
 def test_replace_value(self):
     obj = {'baz': 'qux', 'foo': 'bar'}
     assert replace(obj, '/baz', 'boo') == {'baz': 'boo', 'foo': 'bar'}