Пример #1
0
 def test_resolve_jsonpointer_empty_path(self):
     doc = {}
     path = ''
     self.assertEqual(pandel.resolve_jsonpointer(doc, path), doc)
     
     doc = {'foo':1}
     self.assertEqual(pandel.resolve_jsonpointer(doc, path), doc)
Пример #2
0
    def test_resolve_jsonpointer_empty_path(self):
        doc = {}
        path = ''
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), doc)

        doc = {'foo': 1}
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), doc)
Пример #3
0
 def test_set_jsonpointer_append_path_preserves_intermediate(self):
     doc = {'foo': {'bar': 1}, 1:2}
     path = '/foo/foo2'
     value = 'value'
     pandel.set_jsonpointer(doc, path, value)
     print(doc)
     self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
     self.assertEqual(doc[1], 2)
     self.assertEqual(pandel.resolve_jsonpointer(doc, '/foo/bar'), 1)
Пример #4
0
 def test_set_jsonpointer_append_path_preserves_intermediate(self):
     doc = {'foo': {'bar': 1}, 1: 2}
     path = '/foo/foo2'
     value = 'value'
     pandel.set_jsonpointer(doc, path, value)
     print(doc)
     self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
     self.assertEqual(doc[1], 2)
     self.assertEqual(pandel.resolve_jsonpointer(doc, '/foo/bar'), 1)
Пример #5
0
    def test_resolve_jsonpointer_existing(self):
        doc = {'foo': 1, 'bar': [11, {'a': 222}]}

        path = '/foo'
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), 1)

        path = '/bar/0'
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), 11)

        path = '/bar/1/a'
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), 222)
Пример #6
0
    def test_set_jsonpointer_empty_doc(self):
        doc = {}
        path = '/foo'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)

        doc = {}
        path = '/foo/bar'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
Пример #7
0
    def test_set_jsonpointer_sequence(self):
        doc = [1,2]
        path = '/1'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)

        doc = [1,2]
        path = '/1/foo/bar'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
Пример #8
0
    def test_resolve_jsonpointer_root_path_only(self):
        doc = {}
        path = '/'
        with self.assertRaises(JsonPointerException):
            self.assertEqual(pandel.resolve_jsonpointer(doc, path), doc)

        doc = {'foo': 1}
        with self.assertRaises(JsonPointerException):
            self.assertEqual(pandel.resolve_jsonpointer(doc, path), doc)

        doc = {'': 1}
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), doc[''])
Пример #9
0
    def test_resolve_jsonpointer_root_path_only(self):
        doc = {}
        path = '/'
        with self.assertRaises(JsonPointerException):
            self.assertEqual(pandel.resolve_jsonpointer(doc, path), doc)
        
        doc = {'foo':1}
        with self.assertRaises(JsonPointerException):
            self.assertEqual(pandel.resolve_jsonpointer(doc, path), doc)

        doc = {'':1}
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), doc[''])
Пример #10
0
    def test_set_jsonpointer_empty_doc(self):
        doc = {}
        path = '/foo'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)

        doc = {}
        path = '/foo/bar'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
Пример #11
0
    def test_set_jsonpointer_sequence(self):
        doc = [1, 2]
        path = '/1'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)

        doc = [1, 2]
        path = '/1/foo/bar'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
Пример #12
0
 def test_resolve_jsonpointer_sequence(self):
     doc = [1, [22, 33]]
     
     path = '/0'
     self.assertEqual(pandel.resolve_jsonpointer(doc, path), 1)
     
     path = '/1'
     self.assertEqual(pandel.resolve_jsonpointer(doc, path), [22, 33])
     
     path = '/1/0'
     self.assertEqual(pandel.resolve_jsonpointer(doc, path), 22)
     path = '/1/1'
     self.assertEqual(pandel.resolve_jsonpointer(doc, path), 33)
Пример #13
0
    def test_resolve_jsonpointer_sequence(self):
        doc = [1, [22, 33]]

        path = '/0'
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), 1)

        path = '/1'
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), [22, 33])

        path = '/1/0'
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), 22)
        path = '/1/1'
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), 33)
Пример #14
0
    def test_set_jsonpointer_missing(self):
        doc = {'foo': 1, 1:2}
        path = '/foo/bar'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
        self.assertEqual(doc[1], 2)

        doc = {'foo': 1, 1:2}
        path = '/foo/bar/some/other'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
        self.assertEqual(doc[1], 2)
Пример #15
0
 def test_resolve_jsonpointer_existing(self):
     doc = {
         'foo': 1, 
         'bar': [11,{'a':222}]
     }
     
     path = '/foo'
     self.assertEqual(pandel.resolve_jsonpointer(doc, path), 1)
     
     path = '/bar/0'
     self.assertEqual(pandel.resolve_jsonpointer(doc, path), 11)
     
     path = '/bar/1/a'
     self.assertEqual(pandel.resolve_jsonpointer(doc, path), 222)
Пример #16
0
    def test_set_jsonpointer_missing(self):
        doc = {'foo': 1, 1: 2}
        path = '/foo/bar'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
        self.assertEqual(doc[1], 2)

        doc = {'foo': 1, 1: 2}
        path = '/foo/bar/some/other'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
        self.assertEqual(doc[1], 2)
Пример #17
0
 def test_resolve_jsonpointer_examples_from_spec(self):
     def _doc():
         return {
           r"foo": ["bar", r"baz"],
           r"": 0,
           r"a/b": 1,
           r"c%d": 2,
           r"e^f": 3,
           r"g|h": 4,
           r"i\\j": 5,
           r"k\"l": 6,
           r" ": 7,
           r"m~n": 8
        }
     cases = [
         (r"",            _doc()),
         (r"/foo",        ["bar", "baz"]),
         (r"/foo/0",      "bar"),
         (r"/",           0),
         (r"/a~1b",       1),
         (r"/c%d",      2),
         (r"/e^f",      3),
         (r"/g|h",      4),
         (r"/i\\j",      5),
         (r"/k\"l",      6),
         (r"/ ",        7),
         (r"/m~0n",       8),
     ]
     for path, exp in cases:
         doc = _doc()
         self.assertEqual(pandel.resolve_jsonpointer(doc, path), exp)
Пример #18
0
    def test_resolve_jsonpointer_examples_from_spec(self):
        def _doc():
            return {
                r"foo": ["bar", r"baz"],
                r"": 0,
                r"a/b": 1,
                r"c%d": 2,
                r"e^f": 3,
                r"g|h": 4,
                r"i\\j": 5,
                r"k\"l": 6,
                r" ": 7,
                r"m~n": 8
            }

        cases = [
            (r"", _doc()),
            (r"/foo", ["bar", "baz"]),
            (r"/foo/0", "bar"),
            (r"/", 0),
            (r"/a~1b", 1),
            (r"/c%d", 2),
            (r"/e^f", 3),
            (r"/g|h", 4),
            (r"/i\\j", 5),
            (r"/k\"l", 6),
            (r"/ ", 7),
            (r"/m~0n", 8),
        ]
        for path, exp in cases:
            doc = _doc()
            self.assertEqual(pandel.resolve_jsonpointer(doc, path), exp)
Пример #19
0
def store_model_parts(mdl, outfiles):
    for filespec in outfiles:
        try:
            try:
                part = pandel.resolve_jsonpointer(mdl, filespec.path)
            except JsonPointerException:
                log.warning('Nothing found at model(%s) to write to file(%s).', filespec.path, filespec.fname)
            else:
                store_part_as_df(filespec, part)
        except Exception as ex:
            raise six.reraise(Exception, ("Failed storing %s due to: %s" %(filespec, ex)), ex.__traceback__) ## Python-2 :-(
Пример #20
0
    def test_set_jsonpointer_replace_value(self):
        doc = {'foo': 'bar', 1: 2}
        path = '/foo'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
        self.assertEqual(doc[1], 2)

        doc = {'foo': 1, 1: 2}
        path = '/foo'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
        self.assertEqual(doc[1], 2)

        doc = {'foo': {'bar': 1}, 1: 2}
        path = '/foo'
        value = 2
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
        self.assertEqual(doc[1], 2)
Пример #21
0
    def test_set_jsonpointer_replace_value(self):
        doc = {'foo': 'bar', 1:2}
        path = '/foo'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
        self.assertEqual(doc[1], 2)

        doc = {'foo': 1, 1:2}
        path = '/foo'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
        self.assertEqual(doc[1], 2)

        doc = {'foo': {'bar': 1}, 1:2}
        path = '/foo'
        value = 2
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
        self.assertEqual(doc[1], 2)
Пример #22
0
def store_model_parts(mdl, outfiles):
    for filespec in outfiles:
        try:
            try:
                part = pandel.resolve_jsonpointer(mdl, filespec.path)
            except JsonPointerException:
                log.warning('Nothing found at model(%s) to write to file(%s).',
                            filespec.path, filespec.fname)
            else:
                store_part_as_df(filespec, part)
        except Exception as ex:
            raise six.reraise(Exception, ("Failed storing %s due to: %s" %
                                          (filespec, ex)),
                              ex.__traceback__)  ## Python-2 :-(
Пример #23
0
    def test_set_jsonpointer_sequence_insert_end(self):
        doc = [0, 1]
        path = '/2'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, '/0'), 0)
        self.assertEqual(pandel.resolve_jsonpointer(doc, '/1'), 1)

        doc = [0, 1]
        path = '/-'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, '/2'), value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, '/0'), 0)
        self.assertEqual(pandel.resolve_jsonpointer(doc, '/1'), 1)
Пример #24
0
    def test_set_jsonpointer_sequence_insert_end(self):
        doc = [0, 1]
        path = '/2'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, path), value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, '/0'), 0)
        self.assertEqual(pandel.resolve_jsonpointer(doc, '/1'), 1)

        doc = [0, 1]
        path = '/-'
        value = 'value'
        pandel.set_jsonpointer(doc, path, value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, '/2'), value)
        self.assertEqual(pandel.resolve_jsonpointer(doc, '/0'), 0)
        self.assertEqual(pandel.resolve_jsonpointer(doc, '/1'), 1)
Пример #25
0
 def test_resolve_jsonpointer_missing_screams(self):
     doc = {}
     
     path = '/foo'
     with self.assertRaises(JsonPointerException):
         pandel.resolve_jsonpointer(doc, path)
Пример #26
0
    def test_resolve_jsonpointer_missing_screams(self):
        doc = {}

        path = '/foo'
        with self.assertRaises(JsonPointerException):
            pandel.resolve_jsonpointer(doc, path)