Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1b8a14d3
Commit
1b8a14d3
authored
May 06, 2012
by
Nadeem Vawda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate tests for gzip.GzipFile and gzip.open.
parent
7e126205
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
15 deletions
+14
-15
Lib/test/test_gzip.py
Lib/test/test_gzip.py
+14
-15
No files found.
Lib/test/test_gzip.py
View file @
1b8a14d3
...
...
@@ -33,7 +33,7 @@ class UnseekableIO(io.BytesIO):
raise
io
.
UnsupportedOperation
class
TestGzip
(
unittest
.
TestCase
):
class
BaseTest
(
unittest
.
TestCase
):
filename
=
support
.
TESTFN
def
setUp
(
self
):
...
...
@@ -43,6 +43,7 @@ class TestGzip(unittest.TestCase):
support
.
unlink
(
self
.
filename
)
class
TestGzip
(
BaseTest
):
def
test_write
(
self
):
with
gzip
.
GzipFile
(
self
.
filename
,
'wb'
)
as
f
:
f
.
write
(
data1
*
50
)
...
...
@@ -115,14 +116,14 @@ class TestGzip(unittest.TestCase):
# Bug #1074261 was triggered when reading a file that contained
# many, many members. Create such a file and verify that reading it
# works.
with
gzip
.
open
(
self
.
filename
,
'wb'
,
9
)
as
f
:
with
gzip
.
GzipFile
(
self
.
filename
,
'wb'
,
9
)
as
f
:
f
.
write
(
b'a'
)
for
i
in
range
(
0
,
200
):
with
gzip
.
open
(
self
.
filename
,
"ab"
,
9
)
as
f
:
# append
with
gzip
.
GzipFile
(
self
.
filename
,
"ab"
,
9
)
as
f
:
# append
f
.
write
(
b'a'
)
# Try reading the file
with
gzip
.
open
(
self
.
filename
,
"rb"
)
as
zgfile
:
with
gzip
.
GzipFile
(
self
.
filename
,
"rb"
)
as
zgfile
:
contents
=
b""
while
1
:
ztxt
=
zgfile
.
read
(
8192
)
...
...
@@ -374,10 +375,9 @@ class TestGzip(unittest.TestCase):
datac
=
gzip
.
compress
(
data
)
self
.
assertEqual
(
gzip
.
decompress
(
datac
),
data
)
# Test the 'open' convenience function.
def
test_open_binary
(
self
):
# Test explicit binary modes.
class
TestOpen
(
BaseTest
):
def
test_binary_modes
(
self
):
uncompressed
=
data1
*
50
with
gzip
.
open
(
self
.
filename
,
"wb"
)
as
f
:
f
.
write
(
uncompressed
)
...
...
@@ -392,7 +392,7 @@ class TestGzip(unittest.TestCase):
file_data
=
gzip
.
decompress
(
f
.
read
())
self
.
assertEqual
(
file_data
,
uncompressed
*
2
)
def
test_
open_default_binary
(
self
):
def
test_
implicit_binary_modes
(
self
):
# Test implicit binary modes (no "b" or "t" in mode string).
uncompressed
=
data1
*
50
with
gzip
.
open
(
self
.
filename
,
"w"
)
as
f
:
...
...
@@ -408,8 +408,7 @@ class TestGzip(unittest.TestCase):
file_data
=
gzip
.
decompress
(
f
.
read
())
self
.
assertEqual
(
file_data
,
uncompressed
*
2
)
def
test_open_text
(
self
):
# Test text modes.
def
test_text_modes
(
self
):
uncompressed
=
data1
.
decode
(
"ascii"
)
*
50
with
gzip
.
open
(
self
.
filename
,
"wt"
)
as
f
:
f
.
write
(
uncompressed
)
...
...
@@ -424,7 +423,7 @@ class TestGzip(unittest.TestCase):
file_data
=
gzip
.
decompress
(
f
.
read
()).
decode
(
"ascii"
)
self
.
assertEqual
(
file_data
,
uncompressed
*
2
)
def
test_
open_
bad_params
(
self
):
def
test_bad_params
(
self
):
# Test invalid parameter combinations.
with
self
.
assertRaises
(
ValueError
):
gzip
.
open
(
self
.
filename
,
"wbt"
)
...
...
@@ -435,7 +434,7 @@ class TestGzip(unittest.TestCase):
with
self
.
assertRaises
(
ValueError
):
gzip
.
open
(
self
.
filename
,
"rb"
,
newline
=
"
\
n
"
)
def
test_
open_with_
encoding
(
self
):
def
test_encoding
(
self
):
# Test non-default encoding.
uncompressed
=
data1
.
decode
(
"ascii"
)
*
50
with
gzip
.
open
(
self
.
filename
,
"wt"
,
encoding
=
"utf-16"
)
as
f
:
...
...
@@ -446,7 +445,7 @@ class TestGzip(unittest.TestCase):
with
gzip
.
open
(
self
.
filename
,
"rt"
,
encoding
=
"utf-16"
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
uncompressed
)
def
test_
open_with_
encoding_error_handler
(
self
):
def
test_encoding_error_handler
(
self
):
# Test with non-default encoding error handler.
with
gzip
.
open
(
self
.
filename
,
"wb"
)
as
f
:
f
.
write
(
b"foo
\
xff
bar"
)
...
...
@@ -454,7 +453,7 @@ class TestGzip(unittest.TestCase):
as
f
:
self
.
assertEqual
(
f
.
read
(),
"foobar"
)
def
test_
open_with_
newline
(
self
):
def
test_newline
(
self
):
# Test with explicit newline (universal newline mode disabled).
uncompressed
=
data1
.
decode
(
"ascii"
)
*
50
with
gzip
.
open
(
self
.
filename
,
"wt"
)
as
f
:
...
...
@@ -463,7 +462,7 @@ class TestGzip(unittest.TestCase):
self
.
assertEqual
(
f
.
readlines
(),
[
uncompressed
])
def
test_main
(
verbose
=
None
):
support
.
run_unittest
(
TestGzip
)
support
.
run_unittest
(
TestGzip
,
TestOpen
)
if
__name__
==
"__main__"
:
test_main
(
verbose
=
True
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment