示例#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
示例#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
示例#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'])
示例#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"])
示例#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 ', '  '])
示例#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 ", "  "])
示例#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))
示例#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'))
示例#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', ''])
示例#10
0
 def test_iter_jsonpointer_root(self):
     self.assertListEqual(list(iter_jsonpointer_parts('/')), [''])
     self.assertListEqual(
         list(iter_jsonpointer_parts_relaxed('/')), ['', ''])
示例#11
0
 def test_iter_jsonpointer_empty(self):
     self.assertListEqual(list(iter_jsonpointer_parts('')), [])
     self.assertListEqual(list(iter_jsonpointer_parts_relaxed('')), [''])
示例#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))
示例#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"))
示例#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", ""])
示例#15
0
 def test_iter_jsonpointer_root(self):
     self.assertListEqual(list(iter_jsonpointer_parts("/")), [""])
     self.assertListEqual(list(iter_jsonpointer_parts_relaxed("/")),
                          ["", ""])
示例#16
0
 def test_iter_jsonpointer_empty(self):
     self.assertListEqual(list(iter_jsonpointer_parts("")), [])
     self.assertListEqual(list(iter_jsonpointer_parts_relaxed("")), [""])