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
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
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'])
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"])
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 ', ' '])
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 ", " "])
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))
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'))
def test_iter_jsonpointer_folder(self): self.assertListEqual(list(iter_jsonpointer_parts('/a/')), ['a', '']) self.assertListEqual( list(iter_jsonpointer_parts_relaxed('/a/')), ['', 'a', ''])
def test_iter_jsonpointer_root(self): self.assertListEqual(list(iter_jsonpointer_parts('/')), ['']) self.assertListEqual( list(iter_jsonpointer_parts_relaxed('/')), ['', ''])
def test_iter_jsonpointer_empty(self): self.assertListEqual(list(iter_jsonpointer_parts('')), []) self.assertListEqual(list(iter_jsonpointer_parts_relaxed('')), [''])
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"))
def test_iter_jsonpointer_folder(self): self.assertListEqual(list(iter_jsonpointer_parts("/a/")), ["a", ""]) self.assertListEqual(list(iter_jsonpointer_parts_relaxed("/a/")), ["", "a", ""])
def test_iter_jsonpointer_root(self): self.assertListEqual(list(iter_jsonpointer_parts("/")), [""]) self.assertListEqual(list(iter_jsonpointer_parts_relaxed("/")), ["", ""])
def test_iter_jsonpointer_empty(self): self.assertListEqual(list(iter_jsonpointer_parts("")), []) self.assertListEqual(list(iter_jsonpointer_parts_relaxed("")), [""])