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
709d0563
Commit
709d0563
authored
May 03, 2014
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve test coverage of filecmp (closes #21357)
Patch by Diana Clarke.
parent
71a61aa3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
5 deletions
+75
-5
Lib/test/test_filecmp.py
Lib/test/test_filecmp.py
+75
-5
No files found.
Lib/test/test_filecmp.py
View file @
709d0563
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