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
f24600eb
Kaydet (Commit)
f24600eb
authored
May 04, 2014
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
improve test coverage of filecmp (closes #21357)
Patch by Diana Clarke.
üst
c9926088
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
5 deletions
+75
-5
test_filecmp.py
Lib/test/test_filecmp.py
+75
-5
No files found.
Lib/test/test_filecmp.py
Dosyayı görüntüle @
f24600eb
import
os
,
filecmp
,
shutil
,
tempfile
import
filecmp
import
os
import
shutil
import
tempfile
import
unittest
from
test
import
support
class
FileCompareTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
name
=
support
.
TESTFN
...
...
@@ -120,30 +125,95 @@ class DirCompareTestCase(unittest.TestCase):
else
:
self
.
assertEqual
([
d
.
left_list
,
d
.
right_list
],[[
'file'
],
[
'file'
]])
self
.
assertEqual
(
d
.
common
,
[
'file'
])
self
.
assertTrue
(
d
.
left_only
==
d
.
right_only
==
[])
self
.
assertEqual
(
d
.
left_only
,
[])
self
.
assertEqual
(
d
.
right_only
,
[])
self
.
assertEqual
(
d
.
same_files
,
[
'file'
])
self
.
assertEqual
(
d
.
diff_files
,
[])
expected_report
=
[
"diff {} {}"
.
format
(
self
.
dir
,
self
.
dir_same
),
"Identical files : ['file']"
,
]
self
.
_assert_report
(
d
.
report
,
expected_report
)
# Check attributes for comparison of two different directories
# Check attributes for comparison of two different directories
(right)
left_dir
,
right_dir
=
self
.
dir
,
self
.
dir_diff
d
=
filecmp
.
dircmp
(
left_dir
,
right_dir
)
self
.
assertEqual
(
d
.
left
,
left_dir
)
self
.
assertEqual
(
d
.
right
,
right_dir
)
self
.
assertEqual
(
d
.
left_list
,
[
'file'
])
self
.
assert
True
(
d
.
right_list
==
[
'file'
,
'file2'
])
self
.
assert
Equal
(
d
.
right_list
,
[
'file'
,
'file2'
])
self
.
assertEqual
(
d
.
common
,
[
'file'
])
self
.
assertEqual
(
d
.
left_only
,
[])
self
.
assertEqual
(
d
.
right_only
,
[
'file2'
])
self
.
assertEqual
(
d
.
same_files
,
[
'file'
])
self
.
assertEqual
(
d
.
diff_files
,
[])
expected_report
=
[
"diff {} {}"
.
format
(
self
.
dir
,
self
.
dir_diff
),
"Only in {} : ['file2']"
.
format
(
self
.
dir_diff
),
"Identical files : ['file']"
,
]
self
.
_assert_report
(
d
.
report
,
expected_report
)
# Check attributes for comparison of two different directories (left)
left_dir
,
right_dir
=
self
.
dir
,
self
.
dir_diff
shutil
.
move
(
os
.
path
.
join
(
self
.
dir_diff
,
'file2'
),
os
.
path
.
join
(
self
.
dir
,
'file2'
)
)
d
=
filecmp
.
dircmp
(
left_dir
,
right_dir
)
self
.
assertEqual
(
d
.
left
,
left_dir
)
self
.
assertEqual
(
d
.
right
,
right_dir
)
self
.
assertEqual
(
d
.
left_list
,
[
'file'
,
'file2'
])
self
.
assertEqual
(
d
.
right_list
,
[
'file'
])
self
.
assertEqual
(
d
.
common
,
[
'file'
])
self
.
assertEqual
(
d
.
left_only
,
[
'file2'
])
self
.
assertEqual
(
d
.
right_only
,
[])
self
.
assertEqual
(
d
.
same_files
,
[
'file'
])
self
.
assertEqual
(
d
.
diff_files
,
[])
expected_report
=
[
"diff {} {}"
.
format
(
self
.
dir
,
self
.
dir_diff
),
"Only in {} : ['file2']"
.
format
(
self
.
dir
),
"Identical files : ['file']"
,
]
self
.
_assert_report
(
d
.
report
,
expected_report
)
# Add different file2
output
=
open
(
os
.
path
.
join
(
self
.
dir
,
'file2'
),
'w'
)
output
=
open
(
os
.
path
.
join
(
self
.
dir
_diff
,
'file2'
),
'w'
)
output
.
write
(
'Different contents.
\n
'
)
output
.
close
()
d
=
filecmp
.
dircmp
(
self
.
dir
,
self
.
dir_diff
)
self
.
assertEqual
(
d
.
same_files
,
[
'file'
])
self
.
assertEqual
(
d
.
diff_files
,
[
'file2'
])
expected_report
=
[
"diff {} {}"
.
format
(
self
.
dir
,
self
.
dir_diff
),
"Identical files : ['file']"
,
"Differing files : ['file2']"
,
]
self
.
_assert_report
(
d
.
report
,
expected_report
)
def
test_report_partial_closure
(
self
):
left_dir
,
right_dir
=
self
.
dir
,
self
.
dir_same
d
=
filecmp
.
dircmp
(
left_dir
,
right_dir
)
expected_report
=
[
"diff {} {}"
.
format
(
self
.
dir
,
self
.
dir_same
),
"Identical files : ['file']"
,
]
self
.
_assert_report
(
d
.
report_partial_closure
,
expected_report
)
def
test_report_full_closure
(
self
):
left_dir
,
right_dir
=
self
.
dir
,
self
.
dir_same
d
=
filecmp
.
dircmp
(
left_dir
,
right_dir
)
expected_report
=
[
"diff {} {}"
.
format
(
self
.
dir
,
self
.
dir_same
),
"Identical files : ['file']"
,
]
self
.
_assert_report
(
d
.
report_full_closure
,
expected_report
)
def
_assert_report
(
self
,
dircmp_report
,
expected_report_lines
):
with
support
.
captured_stdout
()
as
stdout
:
dircmp_report
()
report_lines
=
stdout
.
getvalue
()
.
strip
()
.
split
(
'
\n
'
)
self
.
assertEqual
(
report_lines
,
expected_report_lines
)
def
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