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
02f006dbc070
Commit
02f006dbc070
authored
12 years ago
by
Bob Ippolito
Browse files
Options
Downloads
Patches
Plain Diff
simplejson.tool tests and bugfix for Python 3.x (#60)
parent
4d9b1fc3c56a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGES.txt
+2
-0
2 additions, 0 deletions
CHANGES.txt
simplejson/tests/__init__.py
+1
-0
1 addition, 0 deletions
simplejson/tests/__init__.py
simplejson/tests/test_tool.py
+80
-0
80 additions, 0 deletions
simplejson/tests/test_tool.py
simplejson/tool.py
+13
-11
13 additions, 11 deletions
simplejson/tool.py
with
96 additions
and
11 deletions
CHANGES.txt
+
2
−
0
View file @
02f006db
Version 3.1.0 released XXXX-XX-XX
* simplejson.tool tests and bugfix for Python 3.x
http://bugs.python.org/issue16549
* Improve error messages for certain kinds of truncated input
http://bugs.python.org/issue16009
* Moved JSONDecodeError to json.scanner (still available for import
...
...
This diff is collapsed.
Click to expand it.
simplejson/tests/__init__.py
+
1
−
0
View file @
02f006db
...
...
@@ -59,6 +59,7 @@
'
simplejson.tests.test_decimal
'
,
'
simplejson.tests.test_tuple
'
,
'
simplejson.tests.test_namedtuple
'
,
'
simplejson.tests.test_tool
'
,
])
suite
=
additional_tests
(
suite
)
return
OptionalExtensionTestSuite
([
suite
])
...
...
This diff is collapsed.
Click to expand it.
simplejson/tests/test_tool.py
0 → 100644
+
80
−
0
View file @
02f006db
import
os
import
sys
import
textwrap
import
unittest
import
subprocess
import
tempfile
class
TestTool
(
unittest
.
TestCase
):
data
=
"""
[[
"
blorpie
"
],[
"
whoops
"
] , [
],
\t
"
d-shtaeou
"
,
\r
"
d-nthiouh
"
,
"
i-vhbjkhnth
"
, {
"
nifty
"
:87}, {
"
morefield
"
:
\t
false,
"
field
"
:
"
yes
"
} ]
"""
expect
=
textwrap
.
dedent
(
"""
\
[
[
"
blorpie
"
],
[
"
whoops
"
],
[],
"
d-shtaeou
"
,
"
d-nthiouh
"
,
"
i-vhbjkhnth
"
,
{
"
nifty
"
: 87
},
{
"
field
"
:
"
yes
"
,
"
morefield
"
: false
}
]
"""
)
def
runTool
(
self
,
args
=
None
,
data
=
None
):
argv
=
[
sys
.
executable
,
'
-m
'
,
'
simplejson.tool
'
]
if
args
:
argv
.
extend
(
args
)
proc
=
subprocess
.
Popen
(
argv
,
stdin
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
out
,
err
=
proc
.
communicate
(
data
)
self
.
assertEqual
(
len
(
err
),
0
)
self
.
assertEqual
(
proc
.
returncode
,
0
)
return
out
def
test_stdin_stdout
(
self
):
self
.
assertEqual
(
self
.
runTool
(
data
=
self
.
data
.
encode
()),
self
.
expect
.
encode
())
def
test_infile_stdout
(
self
):
with
tempfile
.
NamedTemporaryFile
()
as
infile
:
infile
.
write
(
self
.
data
.
encode
())
infile
.
flush
()
self
.
assertEqual
(
self
.
runTool
(
args
=
[
infile
.
name
]),
self
.
expect
.
encode
())
def
test_infile_outfile
(
self
):
with
tempfile
.
NamedTemporaryFile
()
as
infile
:
infile
.
write
(
self
.
data
.
encode
())
infile
.
flush
()
# outfile will get overwritten by tool, so the delete
# may not work on some platforms. Do it manually.
outfile
=
tempfile
.
NamedTemporaryFile
(
delete
=
0
)
try
:
self
.
assertEqual
(
self
.
runTool
(
args
=
[
infile
.
name
,
outfile
.
name
]),
''
.
encode
())
with
open
(
outfile
.
name
,
'
rb
'
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
self
.
expect
.
encode
())
finally
:
outfile
.
close
()
os
.
unlink
(
outfile
.
name
)
This diff is collapsed.
Click to expand it.
simplejson/tool.py
+
13
−
11
View file @
02f006db
...
...
@@ -18,6 +18,6 @@
infile
=
sys
.
stdin
outfile
=
sys
.
stdout
elif
len
(
sys
.
argv
)
==
2
:
infile
=
open
(
sys
.
argv
[
1
],
'
r
b
'
)
infile
=
open
(
sys
.
argv
[
1
],
'
r
'
)
outfile
=
sys
.
stdout
elif
len
(
sys
.
argv
)
==
3
:
...
...
@@ -22,6 +22,6 @@
outfile
=
sys
.
stdout
elif
len
(
sys
.
argv
)
==
3
:
infile
=
open
(
sys
.
argv
[
1
],
'
r
b
'
)
outfile
=
open
(
sys
.
argv
[
2
],
'
w
b
'
)
infile
=
open
(
sys
.
argv
[
1
],
'
r
'
)
outfile
=
open
(
sys
.
argv
[
2
],
'
w
'
)
else
:
raise
SystemExit
(
sys
.
argv
[
0
]
+
"
[infile [outfile]]
"
)
...
...
@@ -26,8 +26,9 @@
else
:
raise
SystemExit
(
sys
.
argv
[
0
]
+
"
[infile [outfile]]
"
)
with
infile
:
try
:
obj
=
json
.
load
(
infile
,
object_pairs_hook
=
json
.
OrderedDict
,
use_decimal
=
True
)
except
ValueError
:
raise
SystemExit
(
sys
.
exc_info
()[
1
])
...
...
@@ -28,9 +29,10 @@
try
:
obj
=
json
.
load
(
infile
,
object_pairs_hook
=
json
.
OrderedDict
,
use_decimal
=
True
)
except
ValueError
:
raise
SystemExit
(
sys
.
exc_info
()[
1
])
with
outfile
:
json
.
dump
(
obj
,
outfile
,
sort_keys
=
True
,
indent
=
'
'
,
use_decimal
=
True
)
outfile
.
write
(
'
\n
'
)
...
...
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