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
cfc2c7bb
Commit
cfc2c7bb
authored
Feb 05, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #19920: Added tests for TarFile.list(). Based on patch by Vajrasky Kok.
parent
dd9d64eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
0 deletions
+79
-0
Lib/test/test_tarfile.py
Lib/test/test_tarfile.py
+77
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_tarfile.py
View file @
cfc2c7bb
...
...
@@ -158,6 +158,80 @@ class UstarReadTest(ReadTest):
self
.
_test_fileobj_link
(
"symtype2"
,
"ustar/regtype"
)
class
ListTest
(
ReadTest
,
unittest
.
TestCase
):
# Override setUp to use default encoding (UTF-8)
def
setUp
(
self
):
self
.
tar
=
tarfile
.
open
(
self
.
tarname
,
mode
=
self
.
mode
)
def
test_list
(
self
):
with
test_support
.
captured_stdout
()
as
t
:
self
.
tar
.
list
(
verbose
=
False
)
out
=
t
.
getvalue
()
self
.
assertIn
(
'ustar/conttype'
,
out
)
self
.
assertIn
(
'ustar/regtype'
,
out
)
self
.
assertIn
(
'ustar/lnktype'
,
out
)
self
.
assertIn
(
'ustar'
+
(
'/12345'
*
40
)
+
'67/longname'
,
out
)
self
.
assertIn
(
'./ustar/linktest2/symtype'
,
out
)
self
.
assertIn
(
'./ustar/linktest2/lnktype'
,
out
)
# Make sure it puts trailing slash for directory
self
.
assertIn
(
'ustar/dirtype/'
,
out
)
self
.
assertIn
(
'ustar/dirtype-with-size/'
,
out
)
# Make sure it is able to print non-ASCII characters
self
.
assertIn
(
'ustar/umlauts-'
'
\
xc4
\
xd6
\
xdc
\
xe4
\
xf6
\
xfc
\
xdf
'
,
out
)
self
.
assertIn
(
'misc/regtype-hpux-signed-chksum-'
'
\
xc4
\
xd6
\
xdc
\
xe4
\
xf6
\
xfc
\
xdf
'
,
out
)
self
.
assertIn
(
'misc/regtype-old-v7-signed-chksum-'
'
\
xc4
\
xd6
\
xdc
\
xe4
\
xf6
\
xfc
\
xdf
'
,
out
)
# Make sure it prints files separated by one newline without any
# 'ls -l'-like accessories if verbose flag is not being used
# ...
# ustar/conttype
# ustar/regtype
# ...
self
.
assertRegexpMatches
(
out
,
r'ustar/conttype ?\r?\n'
r'ustar/regtype ?\r?\n'
)
# Make sure it does not print the source of link without verbose flag
self
.
assertNotIn
(
'link to'
,
out
)
self
.
assertNotIn
(
'->'
,
out
)
def
test_list_verbose
(
self
):
with
test_support
.
captured_stdout
()
as
t
:
self
.
tar
.
list
(
verbose
=
True
)
out
=
t
.
getvalue
()
# Make sure it prints files separated by one newline with 'ls -l'-like
# accessories if verbose flag is being used
# ...
# ?rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/conttype
# ?rw-r--r-- tarfile/tarfile 7011 2003-01-06 07:19:43 ustar/regtype
# ...
self
.
assertRegexpMatches
(
out
,
(
r'-rw-r--r-- tarfile/tarfile\
s+
7011 '
r'\
d{
4}-\
d
\d-\
d
\d\
s+
\d\
d:
\d\
d:
\d\
d
'
r'
ustar
/
\
w
+
type
?
\
r
?
\
n
') * 2)
# Make sure it prints the source of link with verbose flag
self.assertIn('
ustar
/
symtype
->
regtype
', out)
self.assertIn('
.
/
ustar
/
linktest2
/
symtype
->
..
/
linktest1
/
regtype
', out)
self.assertIn('
.
/
ustar
/
linktest2
/
lnktype
link
to
'
'
.
/
ustar
/
linktest1
/
regtype
', out)
self.assertIn('
gnu
' + ('
/
123
' * 125) + '
/
longlink
link
to
gnu
' +
('
/
123
' * 125) + '
/
longname
', out)
self.assertIn('
pax
' + ('
/
123
' * 125) + '
/
longlink
link
to
pax
' +
('
/
123
' * 125) + '
/
longname
', out)
class GzipListTest(ListTest):
tarname = gzipname
mode = "r:gz"
taropen = tarfile.TarFile.gzopen
class Bz2ListTest(ListTest):
tarname = bz2name
mode = "r:bz2"
taropen = tarfile.TarFile.bz2open
class CommonReadTest(ReadTest):
def test_empty_tarfile(self):
...
...
@@ -1646,6 +1720,7 @@ def test_main():
MemberReadTest
,
GNUReadTest
,
PaxReadTest
,
ListTest
,
WriteTest
,
StreamWriteTest
,
GNUWriteTest
,
...
...
@@ -1677,6 +1752,7 @@ def test_main():
GzipMiscReadTest
,
GzipUstarReadTest
,
GzipStreamReadTest
,
GzipListTest
,
GzipWriteTest
,
GzipStreamWriteTest
,
]
...
...
@@ -1691,6 +1767,7 @@ def test_main():
Bz2MiscReadTest
,
Bz2UstarReadTest
,
Bz2StreamReadTest
,
Bz2ListTest
,
Bz2WriteTest
,
Bz2StreamWriteTest
,
Bz2PartialReadTest
,
...
...
Misc/NEWS
View file @
cfc2c7bb
...
...
@@ -224,6 +224,8 @@ IDLE
Tests
-----
- Issue #19920: Added tests for TarFile.list(). Based on patch by Vajrasky Kok.
- Issue #19990: Added tests for the imghdr module. Based on patch by
Claudiu Popa.
...
...
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