aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/json_tests
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/json_tests')
-rw-r--r--Lib/test/json_tests/test_decode.py5
-rw-r--r--Lib/test/json_tests/test_scanstring.py9
-rw-r--r--Lib/test/json_tests/test_speedups.py14
3 files changed, 22 insertions, 6 deletions
diff --git a/Lib/test/json_tests/test_decode.py b/Lib/test/json_tests/test_decode.py
index f41e5b72231..07dadfe26fc 100644
--- a/Lib/test/json_tests/test_decode.py
+++ b/Lib/test/json_tests/test_decode.py
@@ -31,6 +31,11 @@ class TestDecode(TestCase):
self.assertTrue(isinstance(rval, float))
self.assertEqual(rval, 1.0)
+ def test_empty_objects(self):
+ self.assertEqual(json.loads('{}'), {})
+ self.assertEqual(json.loads('[]'), [])
+ self.assertEqual(json.loads('""'), "")
+
def test_object_pairs_hook(self):
s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4),
diff --git a/Lib/test/json_tests/test_scanstring.py b/Lib/test/json_tests/test_scanstring.py
index d503851e56d..abd325324dd 100644
--- a/Lib/test/json_tests/test_scanstring.py
+++ b/Lib/test/json_tests/test_scanstring.py
@@ -1,14 +1,19 @@
import sys
-import decimal
-from unittest import TestCase
+from unittest import TestCase, skipUnless
import json
import json.decoder
+try:
+ import _json
+except ImportError:
+ _json = None
+
class TestScanString(TestCase):
def test_py_scanstring(self):
self._test_scanstring(json.decoder.py_scanstring)
+ @skipUnless(_json, 'test requires the _json module')
def test_c_scanstring(self):
if json.decoder.c_scanstring is not None:
self._test_scanstring(json.decoder.c_scanstring)
diff --git a/Lib/test/json_tests/test_speedups.py b/Lib/test/json_tests/test_speedups.py
index 271840978c5..b7c141f7f6f 100644
--- a/Lib/test/json_tests/test_speedups.py
+++ b/Lib/test/json_tests/test_speedups.py
@@ -1,16 +1,22 @@
-from unittest import TestCase
+from unittest import TestCase, skipUnless
from json import decoder, encoder, scanner
+try:
+ import _json
+except ImportError:
+ _json = None
+
+@skipUnless(_json, 'test requires the _json module')
class TestSpeedups(TestCase):
def test_scanstring(self):
self.assertEqual(decoder.scanstring.__module__, "_json")
- self.assertTrue(decoder.scanstring is decoder.c_scanstring)
+ self.assertIs(decoder.scanstring, decoder.c_scanstring)
def test_encode_basestring_ascii(self):
self.assertEqual(encoder.encode_basestring_ascii.__module__, "_json")
- self.assertTrue(encoder.encode_basestring_ascii is
- encoder.c_encode_basestring_ascii)
+ self.assertIs(encoder.encode_basestring_ascii,
+ encoder.c_encode_basestring_ascii)
class TestDecode(TestCase):
def test_make_scanner(self):