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
e3228d63
Commit
e3228d63
authored
May 03, 2014
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use with blocks to make sure files are closed
parent
709d0563
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
18 deletions
+12
-18
Lib/test/test_filecmp.py
Lib/test/test_filecmp.py
+12
-18
No files found.
Lib/test/test_filecmp.py
View file @
e3228d63
...
...
@@ -14,13 +14,11 @@ class FileCompareTestCase(unittest.TestCase):
self
.
name_diff
=
support
.
TESTFN
+
'-diff'
data
=
'Contents of file go here.
\
n
'
for
name
in
[
self
.
name
,
self
.
name_same
,
self
.
name_diff
]:
output
=
open
(
name
,
'w'
)
with
open
(
name
,
'w'
)
as
output
:
output
.
write
(
data
)
output
.
close
()
output
=
open
(
self
.
name_diff
,
'a+'
)
with
open
(
self
.
name_diff
,
'a+'
)
as
output
:
output
.
write
(
'An extra line.
\
n
'
)
output
.
close
()
self
.
dir
=
tempfile
.
gettempdir
()
def
tearDown
(
self
):
...
...
@@ -71,13 +69,11 @@ class DirCompareTestCase(unittest.TestCase):
fn
=
'FiLe'
# Verify case-insensitive comparison
else
:
fn
=
'file'
output
=
open
(
os
.
path
.
join
(
dir
,
fn
),
'w'
)
with
open
(
os
.
path
.
join
(
dir
,
fn
),
'w'
)
as
output
:
output
.
write
(
data
)
output
.
close
()
output
=
open
(
os
.
path
.
join
(
self
.
dir_diff
,
'file2'
),
'w'
)
with
open
(
os
.
path
.
join
(
self
.
dir_diff
,
'file2'
),
'w'
)
as
output
:
output
.
write
(
'An extra file.
\
n
'
)
output
.
close
()
def
tearDown
(
self
):
for
dir
in
(
self
.
dir
,
self
.
dir_same
,
self
.
dir_diff
):
...
...
@@ -104,9 +100,8 @@ class DirCompareTestCase(unittest.TestCase):
"Comparing directory to same fails"
)
# Add different file2
output
=
open
(
os
.
path
.
join
(
self
.
dir
,
'file2'
),
'w'
)
with
open
(
os
.
path
.
join
(
self
.
dir
,
'file2'
),
'w'
)
as
output
:
output
.
write
(
'Different contents.
\
n
'
)
output
.
close
()
self
.
assertFalse
(
filecmp
.
cmpfiles
(
self
.
dir
,
self
.
dir_same
,
[
'file'
,
'file2'
])
==
...
...
@@ -178,9 +173,8 @@ class DirCompareTestCase(unittest.TestCase):
self
.
_assert_report
(
d
.
report
,
expected_report
)
# Add different file2
output
=
open
(
os
.
path
.
join
(
self
.
dir_diff
,
'file2'
),
'w'
)
with
open
(
os
.
path
.
join
(
self
.
dir_diff
,
'file2'
),
'w'
)
as
output
:
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'
])
...
...
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