Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
1b8a14d3
Kaydet (Commit)
1b8a14d3
authored
May 06, 2012
tarafından
Nadeem Vawda
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Separate tests for gzip.GzipFile and gzip.open.
üst
7e126205
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
15 deletions
+14
-15
test_gzip.py
Lib/test/test_gzip.py
+14
-15
No files found.
Lib/test/test_gzip.py
Dosyayı görüntüle @
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