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
e0bd2c5f
Kaydet (Commit)
e0bd2c5f
authored
May 06, 2014
tarafından
Tim Golden
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue21440 Use support.rmtree in test_zipfile & test_tarfile
üst
3080d926
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
32 deletions
+30
-32
test_tarfile.py
Lib/test/test_tarfile.py
+19
-20
test_zipfile.py
Lib/test/test_zipfile.py
+11
-12
No files found.
Lib/test/test_tarfile.py
Dosyayı görüntüle @
e0bd2c5f
import
sys
import
sys
import
os
import
os
import
io
import
io
import
shutil
from
hashlib
import
md5
from
hashlib
import
md5
import
unittest
import
unittest
...
@@ -456,16 +455,16 @@ class MiscReadTestBase(CommonReadTest):
...
@@ -456,16 +455,16 @@ class MiscReadTestBase(CommonReadTest):
# Test hardlink extraction (e.g. bug #857297).
# Test hardlink extraction (e.g. bug #857297).
with
tarfile
.
open
(
tarname
,
errorlevel
=
1
,
encoding
=
"iso8859-1"
)
as
tar
:
with
tarfile
.
open
(
tarname
,
errorlevel
=
1
,
encoding
=
"iso8859-1"
)
as
tar
:
tar
.
extract
(
"ustar/regtype"
,
TEMPDIR
)
tar
.
extract
(
"ustar/regtype"
,
TEMPDIR
)
self
.
addCleanup
(
os
.
remove
,
os
.
path
.
join
(
TEMPDIR
,
"ustar/regtype"
))
self
.
addCleanup
(
support
.
unlink
,
os
.
path
.
join
(
TEMPDIR
,
"ustar/regtype"
))
tar
.
extract
(
"ustar/lnktype"
,
TEMPDIR
)
tar
.
extract
(
"ustar/lnktype"
,
TEMPDIR
)
self
.
addCleanup
(
os
.
remove
,
os
.
path
.
join
(
TEMPDIR
,
"ustar/lnktype"
))
self
.
addCleanup
(
support
.
unlink
,
os
.
path
.
join
(
TEMPDIR
,
"ustar/lnktype"
))
with
open
(
os
.
path
.
join
(
TEMPDIR
,
"ustar/lnktype"
),
"rb"
)
as
f
:
with
open
(
os
.
path
.
join
(
TEMPDIR
,
"ustar/lnktype"
),
"rb"
)
as
f
:
data
=
f
.
read
()
data
=
f
.
read
()
self
.
assertEqual
(
md5sum
(
data
),
md5_regtype
)
self
.
assertEqual
(
md5sum
(
data
),
md5_regtype
)
tar
.
extract
(
"ustar/symtype"
,
TEMPDIR
)
tar
.
extract
(
"ustar/symtype"
,
TEMPDIR
)
self
.
addCleanup
(
os
.
remove
,
os
.
path
.
join
(
TEMPDIR
,
"ustar/symtype"
))
self
.
addCleanup
(
support
.
unlink
,
os
.
path
.
join
(
TEMPDIR
,
"ustar/symtype"
))
with
open
(
os
.
path
.
join
(
TEMPDIR
,
"ustar/symtype"
),
"rb"
)
as
f
:
with
open
(
os
.
path
.
join
(
TEMPDIR
,
"ustar/symtype"
),
"rb"
)
as
f
:
data
=
f
.
read
()
data
=
f
.
read
()
self
.
assertEqual
(
md5sum
(
data
),
md5_regtype
)
self
.
assertEqual
(
md5sum
(
data
),
md5_regtype
)
...
@@ -498,7 +497,7 @@ class MiscReadTestBase(CommonReadTest):
...
@@ -498,7 +497,7 @@ class MiscReadTestBase(CommonReadTest):
self
.
assertEqual
(
tarinfo
.
mtime
,
file_mtime
,
errmsg
)
self
.
assertEqual
(
tarinfo
.
mtime
,
file_mtime
,
errmsg
)
finally
:
finally
:
tar
.
close
()
tar
.
close
()
s
hutil
.
rmtree
(
DIR
)
s
upport
.
rmtree
(
DIR
)
def
test_extract_directory
(
self
):
def
test_extract_directory
(
self
):
dirtype
=
"ustar/dirtype"
dirtype
=
"ustar/dirtype"
...
@@ -513,7 +512,7 @@ class MiscReadTestBase(CommonReadTest):
...
@@ -513,7 +512,7 @@ class MiscReadTestBase(CommonReadTest):
if
sys
.
platform
!=
"win32"
:
if
sys
.
platform
!=
"win32"
:
self
.
assertEqual
(
os
.
stat
(
extracted
)
.
st_mode
&
0
o777
,
0
o755
)
self
.
assertEqual
(
os
.
stat
(
extracted
)
.
st_mode
&
0
o777
,
0
o755
)
finally
:
finally
:
s
hutil
.
rmtree
(
DIR
)
s
upport
.
rmtree
(
DIR
)
def
test_init_close_fobj
(
self
):
def
test_init_close_fobj
(
self
):
# Issue #7341: Close the internal file object in the TarFile
# Issue #7341: Close the internal file object in the TarFile
...
@@ -877,7 +876,7 @@ class GNUReadTest(LongnameTest, ReadTest, unittest.TestCase):
...
@@ -877,7 +876,7 @@ class GNUReadTest(LongnameTest, ReadTest, unittest.TestCase):
fobj
.
seek
(
4096
)
fobj
.
seek
(
4096
)
fobj
.
truncate
()
fobj
.
truncate
()
s
=
os
.
stat
(
name
)
s
=
os
.
stat
(
name
)
os
.
remove
(
name
)
support
.
unlink
(
name
)
return
s
.
st_blocks
==
0
return
s
.
st_blocks
==
0
else
:
else
:
return
False
return
False
...
@@ -1010,7 +1009,7 @@ class WriteTest(WriteTestBase, unittest.TestCase):
...
@@ -1010,7 +1009,7 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally
:
finally
:
tar
.
close
()
tar
.
close
()
finally
:
finally
:
os
.
rmdir
(
path
)
support
.
rmdir
(
path
)
@unittest.skipUnless
(
hasattr
(
os
,
"link"
),
@unittest.skipUnless
(
hasattr
(
os
,
"link"
),
"Missing hardlink implementation"
)
"Missing hardlink implementation"
)
...
@@ -1030,8 +1029,8 @@ class WriteTest(WriteTestBase, unittest.TestCase):
...
@@ -1030,8 +1029,8 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally
:
finally
:
tar
.
close
()
tar
.
close
()
finally
:
finally
:
os
.
remove
(
target
)
support
.
unlink
(
target
)
os
.
remove
(
link
)
support
.
unlink
(
link
)
@support.skip_unless_symlink
@support.skip_unless_symlink
def
test_symlink_size
(
self
):
def
test_symlink_size
(
self
):
...
@@ -1045,7 +1044,7 @@ class WriteTest(WriteTestBase, unittest.TestCase):
...
@@ -1045,7 +1044,7 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally
:
finally
:
tar
.
close
()
tar
.
close
()
finally
:
finally
:
os
.
remove
(
path
)
support
.
unlink
(
path
)
def
test_add_self
(
self
):
def
test_add_self
(
self
):
# Test for #1257255.
# Test for #1257255.
...
@@ -1092,7 +1091,7 @@ class WriteTest(WriteTestBase, unittest.TestCase):
...
@@ -1092,7 +1091,7 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally
:
finally
:
tar
.
close
()
tar
.
close
()
finally
:
finally
:
s
hutil
.
rmtree
(
tempdir
)
s
upport
.
rmtree
(
tempdir
)
def
test_filter
(
self
):
def
test_filter
(
self
):
tempdir
=
os
.
path
.
join
(
TEMPDIR
,
"filter"
)
tempdir
=
os
.
path
.
join
(
TEMPDIR
,
"filter"
)
...
@@ -1128,7 +1127,7 @@ class WriteTest(WriteTestBase, unittest.TestCase):
...
@@ -1128,7 +1127,7 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally
:
finally
:
tar
.
close
()
tar
.
close
()
finally
:
finally
:
s
hutil
.
rmtree
(
tempdir
)
s
upport
.
rmtree
(
tempdir
)
# Guarantee that stored pathnames are not modified. Don't
# Guarantee that stored pathnames are not modified. Don't
# remove ./ or ../ or double slashes. Still make absolute
# remove ./ or ../ or double slashes. Still make absolute
...
@@ -1156,9 +1155,9 @@ class WriteTest(WriteTestBase, unittest.TestCase):
...
@@ -1156,9 +1155,9 @@ class WriteTest(WriteTestBase, unittest.TestCase):
tar
.
close
()
tar
.
close
()
if
not
dir
:
if
not
dir
:
os
.
remove
(
foo
)
support
.
unlink
(
foo
)
else
:
else
:
os
.
rmdir
(
foo
)
support
.
rmdir
(
foo
)
self
.
assertEqual
(
t
.
name
,
cmp_path
or
path
.
replace
(
os
.
sep
,
"/"
))
self
.
assertEqual
(
t
.
name
,
cmp_path
or
path
.
replace
(
os
.
sep
,
"/"
))
...
@@ -1189,8 +1188,8 @@ class WriteTest(WriteTestBase, unittest.TestCase):
...
@@ -1189,8 +1188,8 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally
:
finally
:
tar
.
close
()
tar
.
close
()
finally
:
finally
:
os
.
unlink
(
temparchive
)
support
.
unlink
(
temparchive
)
s
hutil
.
rmtree
(
tempdir
)
s
upport
.
rmtree
(
tempdir
)
def
test_pathnames
(
self
):
def
test_pathnames
(
self
):
self
.
_test_pathname
(
"foo"
)
self
.
_test_pathname
(
"foo"
)
...
@@ -1290,7 +1289,7 @@ class StreamWriteTest(WriteTestBase, unittest.TestCase):
...
@@ -1290,7 +1289,7 @@ class StreamWriteTest(WriteTestBase, unittest.TestCase):
# Test for issue #8464: Create files with correct
# Test for issue #8464: Create files with correct
# permissions.
# permissions.
if
os
.
path
.
exists
(
tmpname
):
if
os
.
path
.
exists
(
tmpname
):
os
.
remove
(
tmpname
)
support
.
unlink
(
tmpname
)
original_umask
=
os
.
umask
(
0
o022
)
original_umask
=
os
.
umask
(
0
o022
)
try
:
try
:
...
@@ -1644,7 +1643,7 @@ class AppendTestBase:
...
@@ -1644,7 +1643,7 @@ class AppendTestBase:
def
setUp
(
self
):
def
setUp
(
self
):
self
.
tarname
=
tmpname
self
.
tarname
=
tmpname
if
os
.
path
.
exists
(
self
.
tarname
):
if
os
.
path
.
exists
(
self
.
tarname
):
os
.
remove
(
self
.
tarname
)
support
.
unlink
(
self
.
tarname
)
def
_create_testtar
(
self
,
mode
=
"w:"
):
def
_create_testtar
(
self
,
mode
=
"w:"
):
with
tarfile
.
open
(
tarname
,
encoding
=
"iso8859-1"
)
as
src
:
with
tarfile
.
open
(
tarname
,
encoding
=
"iso8859-1"
)
as
src
:
...
@@ -2151,7 +2150,7 @@ def setUpModule():
...
@@ -2151,7 +2150,7 @@ def setUpModule():
def
tearDownModule
():
def
tearDownModule
():
if
os
.
path
.
exists
(
TEMPDIR
):
if
os
.
path
.
exists
(
TEMPDIR
):
s
hutil
.
rmtree
(
TEMPDIR
)
s
upport
.
rmtree
(
TEMPDIR
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
Lib/test/test_zipfile.py
Dosyayı görüntüle @
e0bd2c5f
...
@@ -3,7 +3,6 @@ import os
...
@@ -3,7 +3,6 @@ import os
import
sys
import
sys
import
importlib.util
import
importlib.util
import
time
import
time
import
shutil
import
struct
import
struct
import
zipfile
import
zipfile
import
unittest
import
unittest
...
@@ -12,7 +11,7 @@ import unittest
...
@@ -12,7 +11,7 @@ import unittest
from
tempfile
import
TemporaryFile
from
tempfile
import
TemporaryFile
from
random
import
randint
,
random
,
getrandbits
from
random
import
randint
,
random
,
getrandbits
from
test.support
import
(
TESTFN
,
findfile
,
unlink
,
from
test.support
import
(
TESTFN
,
findfile
,
unlink
,
rmtree
,
requires_zlib
,
requires_bz2
,
requires_lzma
,
requires_zlib
,
requires_bz2
,
requires_lzma
,
captured_stdout
,
check_warnings
)
captured_stdout
,
check_warnings
)
...
@@ -691,7 +690,7 @@ class PyZipFileTests(unittest.TestCase):
...
@@ -691,7 +690,7 @@ class PyZipFileTests(unittest.TestCase):
self
.
assertNotIn
(
'mod2.txt'
,
names
)
self
.
assertNotIn
(
'mod2.txt'
,
names
)
finally
:
finally
:
shutil
.
rmtree
(
TESTFN2
)
rmtree
(
TESTFN2
)
def
test_write_python_directory_filtered
(
self
):
def
test_write_python_directory_filtered
(
self
):
os
.
mkdir
(
TESTFN2
)
os
.
mkdir
(
TESTFN2
)
...
@@ -711,7 +710,7 @@ class PyZipFileTests(unittest.TestCase):
...
@@ -711,7 +710,7 @@ class PyZipFileTests(unittest.TestCase):
self
.
assertNotIn
(
'mod2.py'
,
names
)
self
.
assertNotIn
(
'mod2.py'
,
names
)
finally
:
finally
:
shutil
.
rmtree
(
TESTFN2
)
rmtree
(
TESTFN2
)
def
test_write_non_pyfile
(
self
):
def
test_write_non_pyfile
(
self
):
with
TemporaryFile
()
as
t
,
zipfile
.
PyZipFile
(
t
,
"w"
)
as
zipfp
:
with
TemporaryFile
()
as
t
,
zipfile
.
PyZipFile
(
t
,
"w"
)
as
zipfp
:
...
@@ -741,7 +740,7 @@ class PyZipFileTests(unittest.TestCase):
...
@@ -741,7 +740,7 @@ class PyZipFileTests(unittest.TestCase):
self
.
assertNotIn
(
'mod1.pyo'
,
names
)
self
.
assertNotIn
(
'mod1.pyo'
,
names
)
finally
:
finally
:
shutil
.
rmtree
(
TESTFN2
)
rmtree
(
TESTFN2
)
class
ExtractTests
(
unittest
.
TestCase
):
class
ExtractTests
(
unittest
.
TestCase
):
...
@@ -767,7 +766,7 @@ class ExtractTests(unittest.TestCase):
...
@@ -767,7 +766,7 @@ class ExtractTests(unittest.TestCase):
os
.
remove
(
writtenfile
)
os
.
remove
(
writtenfile
)
# remove the test file subdirectories
# remove the test file subdirectories
shutil
.
rmtree
(
os
.
path
.
join
(
os
.
getcwd
(),
'ziptest2dir'
))
rmtree
(
os
.
path
.
join
(
os
.
getcwd
(),
'ziptest2dir'
))
def
test_extract_all
(
self
):
def
test_extract_all
(
self
):
with
zipfile
.
ZipFile
(
TESTFN2
,
"w"
,
zipfile
.
ZIP_STORED
)
as
zipfp
:
with
zipfile
.
ZipFile
(
TESTFN2
,
"w"
,
zipfile
.
ZIP_STORED
)
as
zipfp
:
...
@@ -785,7 +784,7 @@ class ExtractTests(unittest.TestCase):
...
@@ -785,7 +784,7 @@ class ExtractTests(unittest.TestCase):
os
.
remove
(
outfile
)
os
.
remove
(
outfile
)
# remove the test file subdirectories
# remove the test file subdirectories
shutil
.
rmtree
(
os
.
path
.
join
(
os
.
getcwd
(),
'ziptest2dir'
))
rmtree
(
os
.
path
.
join
(
os
.
getcwd
(),
'ziptest2dir'
))
def
check_file
(
self
,
filename
,
content
):
def
check_file
(
self
,
filename
,
content
):
self
.
assertTrue
(
os
.
path
.
isfile
(
filename
))
self
.
assertTrue
(
os
.
path
.
isfile
(
filename
))
...
@@ -867,12 +866,12 @@ class ExtractTests(unittest.TestCase):
...
@@ -867,12 +866,12 @@ class ExtractTests(unittest.TestCase):
msg
=
'extract
%
r:
%
r !=
%
r'
%
msg
=
'extract
%
r:
%
r !=
%
r'
%
(
arcname
,
writtenfile
,
correctfile
))
(
arcname
,
writtenfile
,
correctfile
))
self
.
check_file
(
correctfile
,
content
)
self
.
check_file
(
correctfile
,
content
)
shutil
.
rmtree
(
'target'
)
rmtree
(
'target'
)
with
zipfile
.
ZipFile
(
TESTFN2
,
'r'
)
as
zipfp
:
with
zipfile
.
ZipFile
(
TESTFN2
,
'r'
)
as
zipfp
:
zipfp
.
extractall
(
targetpath
)
zipfp
.
extractall
(
targetpath
)
self
.
check_file
(
correctfile
,
content
)
self
.
check_file
(
correctfile
,
content
)
shutil
.
rmtree
(
'target'
)
rmtree
(
'target'
)
correctfile
=
os
.
path
.
join
(
os
.
getcwd
(),
*
fixedname
.
split
(
'/'
))
correctfile
=
os
.
path
.
join
(
os
.
getcwd
(),
*
fixedname
.
split
(
'/'
))
...
@@ -881,12 +880,12 @@ class ExtractTests(unittest.TestCase):
...
@@ -881,12 +880,12 @@ class ExtractTests(unittest.TestCase):
self
.
assertEqual
(
writtenfile
,
correctfile
,
self
.
assertEqual
(
writtenfile
,
correctfile
,
msg
=
"extract
%
r"
%
arcname
)
msg
=
"extract
%
r"
%
arcname
)
self
.
check_file
(
correctfile
,
content
)
self
.
check_file
(
correctfile
,
content
)
shutil
.
rmtree
(
fixedname
.
split
(
'/'
)[
0
])
rmtree
(
fixedname
.
split
(
'/'
)[
0
])
with
zipfile
.
ZipFile
(
TESTFN2
,
'r'
)
as
zipfp
:
with
zipfile
.
ZipFile
(
TESTFN2
,
'r'
)
as
zipfp
:
zipfp
.
extractall
()
zipfp
.
extractall
()
self
.
check_file
(
correctfile
,
content
)
self
.
check_file
(
correctfile
,
content
)
shutil
.
rmtree
(
fixedname
.
split
(
'/'
)[
0
])
rmtree
(
fixedname
.
split
(
'/'
)[
0
])
os
.
remove
(
TESTFN2
)
os
.
remove
(
TESTFN2
)
...
@@ -1628,7 +1627,7 @@ class TestWithDirectory(unittest.TestCase):
...
@@ -1628,7 +1627,7 @@ class TestWithDirectory(unittest.TestCase):
self
.
assertTrue
(
zipf
.
filelist
[
0
]
.
filename
.
endswith
(
"x/"
))
self
.
assertTrue
(
zipf
.
filelist
[
0
]
.
filename
.
endswith
(
"x/"
))
def
tearDown
(
self
):
def
tearDown
(
self
):
shutil
.
rmtree
(
TESTFN2
)
rmtree
(
TESTFN2
)
if
os
.
path
.
exists
(
TESTFN
):
if
os
.
path
.
exists
(
TESTFN
):
unlink
(
TESTFN
)
unlink
(
TESTFN
)
...
...
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