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
6722ac2f
Commit
6722ac2f
authored
May 21, 2010
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use addCleanup
parent
233eb540
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
30 deletions
+27
-30
Lib/test/test_linecache.py
Lib/test/test_linecache.py
+27
-30
No files found.
Lib/test/test_linecache.py
View file @
6722ac2f
...
...
@@ -81,39 +81,36 @@ class LineCacheTests(unittest.TestCase):
def
test_checkcache
(
self
):
getline
=
linecache
.
getline
try
:
# Create a source file and cache its contents
source_name
=
support
.
TESTFN
+
'.py'
with
open
(
source_name
,
'w'
)
as
source
:
source
.
write
(
SOURCE_1
)
getline
(
source_name
,
1
)
# Keep a copy of the old contents
source_list
=
[]
with
open
(
source_name
)
as
source
:
for
index
,
line
in
enumerate
(
source
):
self
.
assertEquals
(
line
,
getline
(
source_name
,
index
+
1
))
source_list
.
append
(
line
)
with
open
(
source_name
,
'w'
)
as
source
:
source
.
write
(
SOURCE_2
)
# Try to update a bogus cache entry
linecache
.
checkcache
(
'dummy'
)
# Check that the cache matches the old contents
for
index
,
line
in
enumerate
(
source_list
):
# Create a source file and cache its contents
source_name
=
support
.
TESTFN
+
'.py'
self
.
addCleanup
(
test_support
.
unlink
,
source_name
)
with
open
(
source_name
,
'w'
)
as
source
:
source
.
write
(
SOURCE_1
)
getline
(
source_name
,
1
)
# Keep a copy of the old contents
source_list
=
[]
with
open
(
source_name
)
as
source
:
for
index
,
line
in
enumerate
(
source
):
self
.
assertEquals
(
line
,
getline
(
source_name
,
index
+
1
))
source_list
.
append
(
line
)
# Update the cache and check whether it matches the new source file
linecache
.
checkcache
(
source_name
)
with
open
(
source_name
)
as
source
:
for
index
,
line
in
enumerate
(
source
):
self
.
assertEquals
(
line
,
getline
(
source_name
,
index
+
1
))
source_list
.
append
(
line
)
with
open
(
source_name
,
'w'
)
as
source
:
source
.
write
(
SOURCE_2
)
finally
:
support
.
unlink
(
source_name
)
# Try to update a bogus cache entry
linecache
.
checkcache
(
'dummy'
)
# Check that the cache matches the old contents
for
index
,
line
in
enumerate
(
source_list
):
self
.
assertEquals
(
line
,
getline
(
source_name
,
index
+
1
))
# Update the cache and check whether it matches the new source file
linecache
.
checkcache
(
source_name
)
with
open
(
source_name
)
as
source
:
for
index
,
line
in
enumerate
(
source
):
self
.
assertEquals
(
line
,
getline
(
source_name
,
index
+
1
))
source_list
.
append
(
line
)
def
test_main
():
support
.
run_unittest
(
LineCacheTests
)
...
...
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