]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.10/Lib/json/tests/test_fail.py
AppPkg/Applications/Python/Python-2.7.10: Initial Checkin part 4/5.
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Lib / json / tests / test_fail.py
diff --git a/AppPkg/Applications/Python/Python-2.7.10/Lib/json/tests/test_fail.py b/AppPkg/Applications/Python/Python-2.7.10/Lib/json/tests/test_fail.py
new file mode 100644 (file)
index 0000000..2f249cb
--- /dev/null
@@ -0,0 +1,105 @@
+from json.tests import PyTest, CTest\r
+\r
+# 2007-10-05\r
+JSONDOCS = [\r
+    # http://json.org/JSON_checker/test/fail1.json\r
+    '"A JSON payload should be an object or array, not a string."',\r
+    # http://json.org/JSON_checker/test/fail2.json\r
+    '["Unclosed array"',\r
+    # http://json.org/JSON_checker/test/fail3.json\r
+    '{unquoted_key: "keys must be quoted"}',\r
+    # http://json.org/JSON_checker/test/fail4.json\r
+    '["extra comma",]',\r
+    # http://json.org/JSON_checker/test/fail5.json\r
+    '["double extra comma",,]',\r
+    # http://json.org/JSON_checker/test/fail6.json\r
+    '[   , "<-- missing value"]',\r
+    # http://json.org/JSON_checker/test/fail7.json\r
+    '["Comma after the close"],',\r
+    # http://json.org/JSON_checker/test/fail8.json\r
+    '["Extra close"]]',\r
+    # http://json.org/JSON_checker/test/fail9.json\r
+    '{"Extra comma": true,}',\r
+    # http://json.org/JSON_checker/test/fail10.json\r
+    '{"Extra value after close": true} "misplaced quoted value"',\r
+    # http://json.org/JSON_checker/test/fail11.json\r
+    '{"Illegal expression": 1 + 2}',\r
+    # http://json.org/JSON_checker/test/fail12.json\r
+    '{"Illegal invocation": alert()}',\r
+    # http://json.org/JSON_checker/test/fail13.json\r
+    '{"Numbers cannot have leading zeroes": 013}',\r
+    # http://json.org/JSON_checker/test/fail14.json\r
+    '{"Numbers cannot be hex": 0x14}',\r
+    # http://json.org/JSON_checker/test/fail15.json\r
+    '["Illegal backslash escape: \\x15"]',\r
+    # http://json.org/JSON_checker/test/fail16.json\r
+    '[\\naked]',\r
+    # http://json.org/JSON_checker/test/fail17.json\r
+    '["Illegal backslash escape: \\017"]',\r
+    # http://json.org/JSON_checker/test/fail18.json\r
+    '[[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]]',\r
+    # http://json.org/JSON_checker/test/fail19.json\r
+    '{"Missing colon" null}',\r
+    # http://json.org/JSON_checker/test/fail20.json\r
+    '{"Double colon":: null}',\r
+    # http://json.org/JSON_checker/test/fail21.json\r
+    '{"Comma instead of colon", null}',\r
+    # http://json.org/JSON_checker/test/fail22.json\r
+    '["Colon instead of comma": false]',\r
+    # http://json.org/JSON_checker/test/fail23.json\r
+    '["Bad value", truth]',\r
+    # http://json.org/JSON_checker/test/fail24.json\r
+    "['single quote']",\r
+    # http://json.org/JSON_checker/test/fail25.json\r
+    '["\ttab\tcharacter\tin\tstring\t"]',\r
+    # http://json.org/JSON_checker/test/fail26.json\r
+    '["tab\\   character\\   in\\  string\\  "]',\r
+    # http://json.org/JSON_checker/test/fail27.json\r
+    '["line\nbreak"]',\r
+    # http://json.org/JSON_checker/test/fail28.json\r
+    '["line\\\nbreak"]',\r
+    # http://json.org/JSON_checker/test/fail29.json\r
+    '[0e]',\r
+    # http://json.org/JSON_checker/test/fail30.json\r
+    '[0e+]',\r
+    # http://json.org/JSON_checker/test/fail31.json\r
+    '[0e+-1]',\r
+    # http://json.org/JSON_checker/test/fail32.json\r
+    '{"Comma instead if closing brace": true,',\r
+    # http://json.org/JSON_checker/test/fail33.json\r
+    '["mismatch"}',\r
+    # http://code.google.com/p/simplejson/issues/detail?id=3\r
+    u'["A\u001FZ control characters in string"]',\r
+]\r
+\r
+SKIPS = {\r
+    1: "why not have a string payload?",\r
+    18: "spec doesn't specify any nesting limitations",\r
+}\r
+\r
+class TestFail(object):\r
+    def test_failures(self):\r
+        for idx, doc in enumerate(JSONDOCS):\r
+            idx = idx + 1\r
+            if idx in SKIPS:\r
+                self.loads(doc)\r
+                continue\r
+            try:\r
+                self.loads(doc)\r
+            except ValueError:\r
+                pass\r
+            else:\r
+                self.fail("Expected failure for fail{0}.json: {1!r}".format(idx, doc))\r
+\r
+    def test_non_string_keys_dict(self):\r
+        data = {'a' : 1, (1, 2) : 2}\r
+\r
+        #This is for c encoder\r
+        self.assertRaises(TypeError, self.dumps, data)\r
+\r
+        #This is for python encoder\r
+        self.assertRaises(TypeError, self.dumps, data, indent=True)\r
+\r
+\r
+class TestPyFail(TestFail, PyTest): pass\r
+class TestCFail(TestFail, CTest): pass\r