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
e2a3c775
Kaydet (Commit)
e2a3c775
authored
Eki 23, 2016
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #28115: Added tests for CLI of the zipfile module.
üst
58bd36b9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
2 deletions
+72
-2
test_zipfile.py
Lib/test/test_zipfile.py
+72
-2
No files found.
Lib/test/test_zipfile.py
Dosyayı görüntüle @
e2a3c775
...
...
@@ -17,8 +17,10 @@ from tempfile import TemporaryFile
from
random
import
randint
,
random
,
getrandbits
from
unittest
import
skipUnless
from
test
import
script_helper
from
test.test_support
import
TESTFN
,
TESTFN_UNICODE
,
TESTFN_ENCODING
,
\
run_unittest
,
findfile
,
unlink
,
rmtree
,
check_warnings
run_unittest
,
findfile
,
unlink
,
rmtree
,
\
check_warnings
,
captured_stdout
try
:
TESTFN_UNICODE
.
encode
(
TESTFN_ENCODING
)
except
(
UnicodeError
,
TypeError
):
...
...
@@ -1770,11 +1772,79 @@ class UniversalNewlineTests(unittest.TestCase):
unlink
(
TESTFN2
)
class
CommandLineTest
(
unittest
.
TestCase
):
def
zipfilecmd
(
self
,
*
args
,
**
kwargs
):
rc
,
out
,
err
=
script_helper
.
assert_python_ok
(
'-m'
,
'zipfile'
,
*
args
,
**
kwargs
)
return
out
.
replace
(
os
.
linesep
.
encode
(),
b
'
\n
'
)
def
zipfilecmd_failure
(
self
,
*
args
):
return
script_helper
.
assert_python_failure
(
'-m'
,
'zipfile'
,
*
args
)
def
test_test_command
(
self
):
zip_name
=
findfile
(
'zipdir.zip'
)
out
=
self
.
zipfilecmd
(
'-t'
,
zip_name
)
self
.
assertEqual
(
out
.
rstrip
(),
b
'Done testing'
)
zip_name
=
findfile
(
'testtar.tar'
)
rc
,
out
,
err
=
self
.
zipfilecmd_failure
(
'-t'
,
zip_name
)
self
.
assertEqual
(
out
,
b
''
)
def
test_list_command
(
self
):
zip_name
=
findfile
(
'zipdir.zip'
)
with
captured_stdout
()
as
t
,
zipfile
.
ZipFile
(
zip_name
,
'r'
)
as
tf
:
tf
.
printdir
()
expected
=
t
.
getvalue
()
.
encode
(
'ascii'
,
'backslashreplace'
)
out
=
self
.
zipfilecmd
(
'-l'
,
zip_name
,
PYTHONIOENCODING
=
'ascii:backslashreplace'
)
self
.
assertEqual
(
out
,
expected
)
def
test_create_command
(
self
):
self
.
addCleanup
(
unlink
,
TESTFN
)
with
open
(
TESTFN
,
'w'
)
as
f
:
f
.
write
(
'test 1'
)
os
.
mkdir
(
TESTFNDIR
)
self
.
addCleanup
(
rmtree
,
TESTFNDIR
)
with
open
(
os
.
path
.
join
(
TESTFNDIR
,
'file.txt'
),
'w'
)
as
f
:
f
.
write
(
'test 2'
)
files
=
[
TESTFN
,
TESTFNDIR
]
namelist
=
[
TESTFN
,
TESTFNDIR
+
'/'
,
TESTFNDIR
+
'/file.txt'
]
try
:
out
=
self
.
zipfilecmd
(
'-c'
,
TESTFN2
,
*
files
)
self
.
assertEqual
(
out
,
b
''
)
with
zipfile
.
ZipFile
(
TESTFN2
)
as
zf
:
self
.
assertEqual
(
zf
.
namelist
(),
namelist
)
self
.
assertEqual
(
zf
.
read
(
namelist
[
0
]),
b
'test 1'
)
self
.
assertEqual
(
zf
.
read
(
namelist
[
2
]),
b
'test 2'
)
finally
:
unlink
(
TESTFN2
)
def
test_extract_command
(
self
):
zip_name
=
findfile
(
'zipdir.zip'
)
extdir
=
TESTFNDIR
os
.
mkdir
(
extdir
)
try
:
out
=
self
.
zipfilecmd
(
'-e'
,
zip_name
,
extdir
)
self
.
assertEqual
(
out
,
b
''
)
with
zipfile
.
ZipFile
(
zip_name
)
as
zf
:
for
zi
in
zf
.
infolist
():
path
=
os
.
path
.
join
(
extdir
,
zi
.
filename
.
replace
(
'/'
,
os
.
sep
))
if
zi
.
filename
.
endswith
(
'/'
):
self
.
assertTrue
(
os
.
path
.
isdir
(
path
))
else
:
self
.
assertTrue
(
os
.
path
.
isfile
(
path
))
with
open
(
path
,
'rb'
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
zf
.
read
(
zi
))
finally
:
rmtree
(
extdir
)
def
test_main
():
run_unittest
(
TestsWithSourceFile
,
TestZip64InSmallFiles
,
OtherTests
,
PyZipFileTests
,
DecryptionTests
,
TestsWithMultipleOpens
,
TestWithDirectory
,
UniversalNewlineTests
,
TestsWithRandomBinaryFiles
)
TestsWithRandomBinaryFiles
,
CommandLineTest
)
if
__name__
==
"__main__"
:
test_main
()
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