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
277828f5d232
Commit
277828f5d232
authored
7 years ago
by
Bob Ippolito
Browse files
Options
Downloads
Plain Diff
Merge pull request #214 from simplejson/tempfile-py25
Fix tests in Python 2.5.
parents
aba7d1c7658a
7195a7243106
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_tool.py
+18
-9
18 additions, 9 deletions
simplejson/tests/test_tool.py
with
18 additions
and
9 deletions
simplejson/tests/test_tool.py
+
18
−
9
View file @
277828f5
...
...
@@ -21,6 +21,15 @@
""
.
encode
(),
stderr
).
strip
()
def
open_temp_file
():
if
sys
.
version_info
>=
(
2
,
6
):
file
=
tempfile
.
NamedTemporaryFile
(
delete
=
False
)
filename
=
file
.
name
else
:
fd
,
filename
=
tempfile
.
mkstemp
()
file
=
os
.
fdopen
(
fd
,
'
w+b
'
)
return
file
,
filename
class
TestTool
(
unittest
.
TestCase
):
data
=
"""
...
...
@@ -71,8 +80,8 @@
self
.
expect
.
splitlines
())
def
test_infile_stdout
(
self
):
infile
=
temp
file
.
N
ame
dTemporaryFile
(
delete
=
False
)
infile
,
in
file
_n
ame
=
open_temp_file
(
)
try
:
infile
.
write
(
self
.
data
.
encode
())
infile
.
close
()
self
.
assertEqual
(
...
...
@@ -75,7 +84,7 @@
try
:
infile
.
write
(
self
.
data
.
encode
())
infile
.
close
()
self
.
assertEqual
(
self
.
runTool
(
args
=
[
infile
.
name
]),
self
.
runTool
(
args
=
[
infile
_
name
]),
self
.
expect
.
splitlines
())
finally
:
...
...
@@ -80,5 +89,5 @@
self
.
expect
.
splitlines
())
finally
:
os
.
unlink
(
infile
.
name
)
os
.
unlink
(
infile
_
name
)
def
test_infile_outfile
(
self
):
...
...
@@ -83,8 +92,8 @@
def
test_infile_outfile
(
self
):
infile
=
temp
file
.
N
ame
dTemporaryFile
(
delete
=
False
)
infile
,
in
file
_n
ame
=
open_temp_file
(
)
try
:
infile
.
write
(
self
.
data
.
encode
())
infile
.
close
()
# outfile will get overwritten by tool, so the delete
# may not work on some platforms. Do it manually.
...
...
@@ -86,9 +95,9 @@
try
:
infile
.
write
(
self
.
data
.
encode
())
infile
.
close
()
# outfile will get overwritten by tool, so the delete
# may not work on some platforms. Do it manually.
outfile
=
temp
file
.
N
ame
dTemporaryFile
(
delete
=
False
)
outfile
,
out
file
_n
ame
=
open_temp_file
(
)
try
:
outfile
.
close
()
self
.
assertEqual
(
...
...
@@ -92,5 +101,5 @@
try
:
outfile
.
close
()
self
.
assertEqual
(
self
.
runTool
(
args
=
[
infile
.
name
,
outfile
.
name
]),
self
.
runTool
(
args
=
[
infile
_
name
,
outfile
_
name
]),
[])
...
...
@@ -96,7 +105,7 @@
[])
with
open
(
outfile
.
name
,
'
rb
'
)
as
f
:
with
open
(
outfile
_
name
,
'
rb
'
)
as
f
:
self
.
assertEqual
(
f
.
read
().
decode
(
'
utf8
'
).
splitlines
(),
self
.
expect
.
splitlines
()
)
finally
:
...
...
@@ -98,7 +107,7 @@
self
.
assertEqual
(
f
.
read
().
decode
(
'
utf8
'
).
splitlines
(),
self
.
expect
.
splitlines
()
)
finally
:
os
.
unlink
(
outfile
.
name
)
os
.
unlink
(
outfile
_
name
)
finally
:
...
...
@@ -104,2 +113,2 @@
finally
:
os
.
unlink
(
infile
.
name
)
os
.
unlink
(
infile
_
name
)
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