Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
simplejson
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OpenVMS
Python
Modules
simplejson
Commits
095c46b8a562
Commit
095c46b8a562
authored
8 years ago
by
Serhiy Storchaka
Browse files
Options
Downloads
Patches
Plain Diff
Make test_speedups compatible with Python 2.5 and 2.6.
parent
83df0321467e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
simplejson/tests/test_speedups.py
+25
-37
25 additions, 37 deletions
simplejson/tests/test_speedups.py
with
25 additions
and
37 deletions
simplejson/tests/test_speedups.py
+
25
−
37
View file @
095c46b8
from
__future__
import
with_statement
import
sys
import
unittest
from
unittest
import
TestCase
import
simplejson
from
simplejson
import
encoder
,
decoder
,
scanner
...
...
@@ -3,10 +1,10 @@
import
sys
import
unittest
from
unittest
import
TestCase
import
simplejson
from
simplejson
import
encoder
,
decoder
,
scanner
from
simplejson.compat
import
PY3
from
simplejson.compat
import
PY3
,
long_type
def
has_speedups
():
...
...
@@ -39,8 +37,8 @@
@skip_if_speedups_missing
def
test_bad_bool_args
(
self
):
with
self
.
assertRaises
(
ZeroDivisionError
):
decoder
.
JSONDecoder
(
strict
=
BadBool
()).
decode
(
'""'
)
with
self
.
assertRaises
(
ZeroDivisionError
)
:
decoder
.
JSONDecoder
(
strict
=
BadBool
()).
decode
(
'
{}
'
)
def
test
(
value
):
decoder
.
JSONDecoder
(
strict
=
BadBool
()).
decode
(
value
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'""'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
{}
'
)
if
not
PY3
:
...
...
@@ -46,8 +44,6 @@
if
not
PY3
:
with
self
.
assertRaises
(
ZeroDivisionError
):
decoder
.
JSONDecoder
(
strict
=
BadBool
()).
decode
(
u
'""'
)
with
self
.
assertRaises
(
ZeroDivisionError
):
decoder
.
JSONDecoder
(
strict
=
BadBool
()).
decode
(
u
'
{}
'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
u
'""'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
u
'
{}
'
)
class
TestEncode
(
TestCase
):
@skip_if_speedups_missing
...
...
@@ -63,30 +59,20 @@
@skip_if_speedups_missing
def
test_bad_bool_args
(
self
):
with
self
.
assertRaises
(
ZeroDivisionError
):
encoder
.
JSONEncoder
(
skipkeys
=
BadBool
()).
encode
({})
with
self
.
assertRaises
(
ZeroDivisionError
):
encoder
.
JSONEncoder
(
ensure_ascii
=
BadBool
()).
encode
({})
with
self
.
assertRaises
(
ZeroDivisionError
):
encoder
.
JSONEncoder
(
check_circular
=
BadBool
()).
encode
({})
with
self
.
assertRaises
(
ZeroDivisionError
):
encoder
.
JSONEncoder
(
allow_nan
=
BadBool
()).
encode
({})
with
self
.
assertRaises
(
ZeroDivisionError
):
encoder
.
JSONEncoder
(
sort_keys
=
BadBool
()).
encode
({})
with
self
.
assertRaises
(
ZeroDivisionError
):
encoder
.
JSONEncoder
(
use_decimal
=
BadBool
()).
encode
({})
with
self
.
assertRaises
(
ZeroDivisionError
):
encoder
.
JSONEncoder
(
namedtuple_as_object
=
BadBool
()).
encode
({})
with
self
.
assertRaises
(
ZeroDivisionError
):
encoder
.
JSONEncoder
(
tuple_as_array
=
BadBool
()).
encode
({})
with
self
.
assertRaises
(
ZeroDivisionError
):
encoder
.
JSONEncoder
(
bigint_as_string
=
BadBool
()).
encode
({})
with
self
.
assertRaises
(
ZeroDivisionError
):
encoder
.
JSONEncoder
(
for_json
=
BadBool
()).
encode
({})
with
self
.
assertRaises
(
ZeroDivisionError
):
encoder
.
JSONEncoder
(
ignore_nan
=
BadBool
()).
encode
({})
with
self
.
assertRaises
(
ZeroDivisionError
):
encoder
.
JSONEncoder
(
iterable_as_array
=
BadBool
()).
encode
({})
def
test
(
name
):
encoder
.
JSONEncoder
(
**
{
name
:
BadBool
()}).
encode
({})
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
skipkeys
'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
ensure_ascii
'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
check_circular
'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
allow_nan
'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
sort_keys
'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
use_decimal
'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
namedtuple_as_object
'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
tuple_as_array
'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
bigint_as_string
'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
for_json
'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
ignore_nan
'
)
self
.
assertRaises
(
ZeroDivisionError
,
test
,
'
iterable_as_array
'
)
@skip_if_speedups_missing
def
test_int_as_string_bitcount_overflow
(
self
):
...
...
@@ -90,5 +76,7 @@
@skip_if_speedups_missing
def
test_int_as_string_bitcount_overflow
(
self
):
with
self
.
assertRaises
((
TypeError
,
OverflowError
)):
encoder
.
JSONEncoder
(
int_as_string_bitcount
=
2
**
32
+
31
).
encode
(
0
)
long_count
=
long_type
(
2
)
**
32
+
31
def
test
():
encoder
.
JSONEncoder
(
int_as_string_bitcount
=
long_count
).
encode
(
0
)
self
.
assertRaises
((
TypeError
,
OverflowError
),
test
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment