summaryrefslogtreecommitdiffstats
path: root/Lib/json/tests/test_scanstring.py
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-05-14 03:24:53 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-05-14 03:24:53 (GMT)
commite3992eb7430101f5bc6725d5f74290777a2ef939 (patch)
tree8300fe6afce165f52da14b5229cdb4ec50161602 /Lib/json/tests/test_scanstring.py
parent720f8dea196640a053135f31be89b652d685e55c (diff)
downloadcpython-e3992eb7430101f5bc6725d5f74290777a2ef939.zip
cpython-e3992eb7430101f5bc6725d5f74290777a2ef939.tar.gz
cpython-e3992eb7430101f5bc6725d5f74290777a2ef939.tar.bz2
#5723: Improve json tests to be executed with and without accelerations.
Diffstat (limited to 'Lib/json/tests/test_scanstring.py')
-rw-r--r--Lib/json/tests/test_scanstring.py32
1 files changed, 12 insertions, 20 deletions
diff --git a/Lib/json/tests/test_scanstring.py b/Lib/json/tests/test_scanstring.py
index d858161..4fef8cb 100644
--- a/Lib/json/tests/test_scanstring.py
+++ b/Lib/json/tests/test_scanstring.py
@@ -1,23 +1,10 @@
import sys
-from unittest import TestCase, skipUnless
+from json.tests import PyTest, CTest
-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):
- self._test_scanstring(json.decoder.c_scanstring)
-
- def _test_scanstring(self, scanstring):
+class TestScanstring(object):
+ def test_scanstring(self):
+ scanstring = self.json.decoder.scanstring
self.assertEqual(
scanstring('"z\\ud834\\udd20x"', 1, None, True),
(u'z\U0001d120x', 16))
@@ -108,10 +95,15 @@ class TestScanString(TestCase):
(u'Bad value', 12))
def test_issue3623(self):
- self.assertRaises(ValueError, json.decoder.scanstring, b"xxx", 1,
+ self.assertRaises(ValueError, self.json.decoder.scanstring, b"xxx", 1,
"xxx")
self.assertRaises(UnicodeDecodeError,
- json.encoder.encode_basestring_ascii, b"xx\xff")
+ self.json.encoder.encode_basestring_ascii, b"xx\xff")
def test_overflow(self):
- self.assertRaises(OverflowError, json.decoder.scanstring, b"xxx", sys.maxsize+1)
+ with self.assertRaises(OverflowError):
+ self.json.decoder.scanstring(b"xxx", sys.maxsize+1)
+
+
+class TestPyScanstring(TestScanstring, PyTest): pass
+class TestCScanstring(TestScanstring, CTest): pass