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
89ecb4ac
Commit
89ecb4ac
authored
Oct 23, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #28115: Added tests for CLI of the zipfile module.
parents
662cef66
61c4c44b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
1 deletion
+67
-1
Lib/test/test_zipfile.py
Lib/test/test_zipfile.py
+67
-1
No files found.
Lib/test/test_zipfile.py
View file @
89ecb4ac
...
...
@@ -12,7 +12,8 @@ import unittest
from
tempfile
import
TemporaryFile
from
random
import
randint
,
random
,
getrandbits
from
test.support
import
(
TESTFN
,
findfile
,
unlink
,
rmtree
,
from
test.support
import
script_helper
from
test.support
import
(
TESTFN
,
findfile
,
unlink
,
rmtree
,
temp_dir
,
requires_zlib
,
requires_bz2
,
requires_lzma
,
captured_stdout
,
check_warnings
)
...
...
@@ -2041,5 +2042,70 @@ class ZipInfoTests(unittest.TestCase):
self
.
assertEqual
(
zi
.
compress_type
,
zipfile
.
ZIP_STORED
)
self
.
assertEqual
(
zi
.
file_size
,
0
)
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'
)
t
=
io
.
StringIO
()
with
zipfile
.
ZipFile
(
zip_name
,
'r'
)
as
tf
:
tf
.
printdir
(
t
)
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'
)
with
temp_dir
()
as
extdir
:
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
.
is_dir
():
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
))
if
__name__
==
"__main__"
:
unittest
.
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