Beispiel #1
0
 def test_iter_jsonpointer_massive(self):
     cases = [
         ('/a', ['a']),
         ('/a/', ['a', '']),
         ('/a/b', ['a', 'b']),
         ('/a/b/', ['a', 'b', '']),
         ('/a//b', ['a', '', 'b']),
         ('/a/../b', ['a', '..', 'b']),
         ('/', ['']),
         ('', []),
         ('/ some ', [' some ']),
         ('/ some /', [' some ', '']),
         ('/ some /  ', [' some ', '  ']),
         ('/ some /  /', [' some ', '  ', '']),
         (None, AttributeError),
         ('a', RefResolutionError),
     ]
     for i, (inp, out) in enumerate(cases):
         msg = 'case #%i' % i
         try:
             if issubclass(out, Exception):
                 with self.assertRaises(out, msg=msg):
                     list(iter_jsonpointer_parts(inp))
             continue
         except TypeError as ex:
             if ex.args[0].startswith('issubclass()'):
                 self.assertEqual(
                     list(iter_jsonpointer_parts(inp)), out, msg)
             else:
                 raise ex
Beispiel #2
0
 def test_iter_jsonpointer_massive(self):
     cases = [
         ("/a", ["a"]),
         ("/a/", ["a", ""]),
         ("/a/b", ["a", "b"]),
         ("/a/b/", ["a", "b", ""]),
         ("/a//b", ["a", "", "b"]),
         ("/a/../b", ["a", "..", "b"]),
         ("/", [""]),
         ("", []),
         ("/ some ", [" some "]),
         ("/ some /", [" some ", ""]),
         ("/ some /  ", [" some ", "  "]),
         ("/ some /  /", [" some ", "  ", ""]),
         (None, AttributeError),
         ("a", RefResolutionError),
     ]
     for i, (inp, out) in enumerate(cases):
         msg = "case #%i" % i
         try:
             if issubclass(out, Exception):
                 with self.assertRaises(out, msg=msg):
                     list(iter_jsonpointer_parts(inp))
             continue
         except TypeError as ex:
             if ex.args[0].startswith("issubclass()"):
                 self.assertEqual(list(iter_jsonpointer_parts(inp)), out,
                                  msg)
             else:
                 raise ex
Beispiel #3
0
    def test_iter_jsonpointer_regular(self):
        self.assertListEqual(list(iter_jsonpointer_parts('/a')), ['a'])
        self.assertListEqual(
            list(iter_jsonpointer_parts_relaxed('/a')), ['', 'a'])

        self.assertListEqual(list(iter_jsonpointer_parts('/a/b')), ['a', 'b'])
        self.assertListEqual(
            list(iter_jsonpointer_parts_relaxed('/a/b')), ['', 'a', 'b'])
Beispiel #4
0
    def test_iter_jsonpointer_regular(self):
        self.assertListEqual(list(iter_jsonpointer_parts("/a")), ["a"])
        self.assertListEqual(list(iter_jsonpointer_parts_relaxed("/a")),
                             ["", "a"])

        self.assertListEqual(list(iter_jsonpointer_parts("/a/b")), ["a", "b"])
        self.assertListEqual(list(iter_jsonpointer_parts_relaxed("/a/b")),
                             ["", "a", "b"])
Beispiel #5
0
    def test_iter_jsonpointer_with_spaces(self):
        self.assertListEqual(
            list(iter_jsonpointer_parts('/ some ')), [' some '])
        self.assertListEqual(
            list(iter_jsonpointer_parts('/ some /  ')), [' some ', '  '])

        self.assertListEqual(
            list(iter_jsonpointer_parts_relaxed(' some ')), [' some '])
        self.assertListEqual(
            list(iter_jsonpointer_parts_relaxed(' some /  ')), [' some ', '  '])
Beispiel #6
0
    def test_iter_jsonpointer_with_spaces(self):
        self.assertListEqual(list(iter_jsonpointer_parts("/ some ")),
                             [" some "])
        self.assertListEqual(list(iter_jsonpointer_parts("/ some /  ")),
                             [" some ", "  "])

        self.assertListEqual(list(iter_jsonpointer_parts_relaxed(" some ")),
                             [" some "])
        self.assertListEqual(list(iter_jsonpointer_parts_relaxed(" some /  ")),
                             [" some ", "  "])
Beispiel #7
0
 def test_iter_jsonpointer_None(self):
     with self.assertRaises(AttributeError):
         list(iter_jsonpointer_parts(None))
     with self.assertRaises(AttributeError):
         list(iter_jsonpointer_parts_relaxed(None))
Beispiel #8
0
 def test_iter_jsonpointer_non_absolute(self):
     with self.assertRaises(RefResolutionError):
         list(iter_jsonpointer_parts('a'))
     with self.assertRaises(RefResolutionError):
         list(iter_jsonpointer_parts('a/b'))
Beispiel #9
0
 def test_iter_jsonpointer_folder(self):
     self.assertListEqual(list(iter_jsonpointer_parts('/a/')), ['a', ''])
     self.assertListEqual(
         list(iter_jsonpointer_parts_relaxed('/a/')), ['', 'a', ''])
Beispiel #10
0
 def test_iter_jsonpointer_root(self):
     self.assertListEqual(list(iter_jsonpointer_parts('/')), [''])
     self.assertListEqual(
         list(iter_jsonpointer_parts_relaxed('/')), ['', ''])
Beispiel #11
0
 def test_iter_jsonpointer_empty(self):
     self.assertListEqual(list(iter_jsonpointer_parts('')), [])
     self.assertListEqual(list(iter_jsonpointer_parts_relaxed('')), [''])
Beispiel #12
0
 def test_iter_jsonpointer_None(self):
     with self.assertRaises(AttributeError):
         list(iter_jsonpointer_parts(None))
     with self.assertRaises(AttributeError):
         list(iter_jsonpointer_parts_relaxed(None))
Beispiel #13
0
 def test_iter_jsonpointer_non_absolute(self):
     with self.assertRaises(RefResolutionError):
         list(iter_jsonpointer_parts("a"))
     with self.assertRaises(RefResolutionError):
         list(iter_jsonpointer_parts("a/b"))
Beispiel #14
0
 def test_iter_jsonpointer_folder(self):
     self.assertListEqual(list(iter_jsonpointer_parts("/a/")), ["a", ""])
     self.assertListEqual(list(iter_jsonpointer_parts_relaxed("/a/")),
                          ["", "a", ""])
Beispiel #15
0
 def test_iter_jsonpointer_root(self):
     self.assertListEqual(list(iter_jsonpointer_parts("/")), [""])
     self.assertListEqual(list(iter_jsonpointer_parts_relaxed("/")),
                          ["", ""])
Beispiel #16
0
 def test_iter_jsonpointer_empty(self):
     self.assertListEqual(list(iter_jsonpointer_parts("")), [])
     self.assertListEqual(list(iter_jsonpointer_parts_relaxed("")), [""])