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
410e88d5
Commit
410e88d5
authored
Apr 22, 2012
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change tests for imp.cache_from_source() to follow os.path.join/split
semantics.
parent
6240bd11
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
43 deletions
+32
-43
Lib/test/test_imp.py
Lib/test/test_imp.py
+32
-43
No files found.
Lib/test/test_imp.py
View file @
410e88d5
...
...
@@ -227,73 +227,62 @@ class PEP3147Tests(unittest.TestCase):
def
test_cache_from_source
(
self
):
# Given the path to a .py file, return the path to its PEP 3147
# defined .pyc file (i.e. under __pycache__).
self
.
assertEqual
(
imp
.
cache_from_source
(
'/foo/bar/baz/qux.py'
,
True
),
'/foo/bar/baz/__pycache__/qux.{}.pyc'
.
format
(
self
.
tag
))
# Directory with a dot, filename without dot
self
.
assertEqual
(
imp
.
cache_from_source
(
'/foo.bar/file'
,
True
),
'/foo.bar/__pycache__/file{}.pyc'
.
format
(
self
.
tag
))
path
=
os
.
path
.
join
(
'foo'
,
'bar'
,
'baz'
,
'qux.py'
)
expect
=
os
.
path
.
join
(
'foo'
,
'bar'
,
'baz'
,
'__pycache__'
,
'qux.{}.pyc'
.
format
(
self
.
tag
))
self
.
assertEqual
(
imp
.
cache_from_source
(
path
,
True
),
expect
)
def
test_cache_from_source_no_dot
(
self
):
# Directory with a dot, filename without dot.
path
=
os
.
path
.
join
(
'foo.bar'
,
'file'
)
expect
=
os
.
path
.
join
(
'foo.bar'
,
'__pycache__'
,
'file{}.pyc'
.
format
(
self
.
tag
))
self
.
assertEqual
(
imp
.
cache_from_source
(
path
,
True
),
expect
)
def
test_cache_from_source_optimized
(
self
):
# Given the path to a .py file, return the path to its PEP 3147
# defined .pyo file (i.e. under __pycache__).
self
.
assertEqual
(
imp
.
cache_from_source
(
'/foo/bar/baz/qux.py'
,
False
),
'/foo/bar/baz/__pycache__/qux.{}.pyo'
.
format
(
self
.
tag
))
path
=
os
.
path
.
join
(
'foo'
,
'bar'
,
'baz'
,
'qux.py'
)
expect
=
os
.
path
.
join
(
'foo'
,
'bar'
,
'baz'
,
'__pycache__'
,
'qux.{}.pyo'
.
format
(
self
.
tag
))
self
.
assertEqual
(
imp
.
cache_from_source
(
path
,
False
),
expect
)
def
test_cache_from_source_cwd
(
self
):
self
.
assertEqual
(
imp
.
cache_from_source
(
'foo.py'
,
True
),
os
.
sep
.
join
((
'__pycache__'
,
'foo.{}.pyc'
.
format
(
self
.
tag
)))
)
path
=
'foo.py'
expect
=
os
.
path
.
join
(
'__pycache__'
,
'foo.{}.pyc'
.
format
(
self
.
tag
))
self
.
assertEqual
(
imp
.
cache_from_source
(
path
,
True
),
expect
)
def
test_cache_from_source_override
(
self
):
# When debug_override is not None, it can be any true-ish or false-ish
# value.
self
.
assertEqual
(
imp
.
cache_from_source
(
'/foo/bar/baz.py'
,
[])
,
'/foo/bar/__pycache__/baz.{}.pyo
'
.
format
(
self
.
tag
))
self
.
assertEqual
(
imp
.
cache_from_source
(
'/foo/bar/baz.py'
,
[
17
]),
'/foo/bar/__pycache__/baz.{}.pyc'
.
format
(
self
.
tag
)
)
path
=
os
.
path
.
join
(
'foo'
,
'bar'
,
'baz.py'
)
partial_expect
=
os
.
path
.
join
(
'foo'
,
'bar'
,
'__pycache__'
,
'baz.{}.py
'
.
format
(
self
.
tag
))
self
.
assertEqual
(
imp
.
cache_from_source
(
path
,
[]),
partial_expect
+
'o'
)
self
.
assertEqual
(
imp
.
cache_from_source
(
path
,
[
17
]),
partial_expect
+
'c'
)
# However if the bool-ishness can't be determined, the exception
# propagates.
class
Bearish
:
def
__bool__
(
self
):
raise
RuntimeError
self
.
assertRaises
(
RuntimeError
,
imp
.
cache_from_source
,
'/foo/bar/baz.py'
,
Bearish
())
@
unittest
.
skipIf
(
os
.
altsep
is
None
,
'test meaningful only where os.altsep is defined'
)
def
test_altsep_cache_from_source
(
self
):
# Windows path and PEP 3147.
self
.
assertEqual
(
imp
.
cache_from_source
(
'
\
\
foo
\
\
bar
\
\
baz
\
\
qux.py'
,
True
),
'
\
\
foo
\
\
bar
\
\
baz
\
\
__pycache__
\
\
qux.{}.pyc'
.
format
(
self
.
tag
))
with
self
.
assertRaises
(
RuntimeError
):
imp
.
cache_from_source
(
'/foo/bar/baz.py'
,
Bearish
())
@
unittest
.
skipIf
(
os
.
altsep
is
None
,
'test meaningful only where os.altsep is defined'
)
def
test_altsep_and_sep_cache_from_source
(
self
):
# Windows path and PEP 3147 where altsep is right of sep.
self
.
assertEqual
(
imp
.
cache_from_source
(
'
\
\
foo
\
\
bar/baz
\
\
qux.py'
,
True
),
'
\
\
foo
\
\
bar/baz
\
\
__pycache__
\
\
qux.{}.pyc'
.
format
(
self
.
tag
))
@
unittest
.
skipIf
(
os
.
altsep
is
None
,
@
unittest
.
skipUnless
(
os
.
sep
==
'
\
\
'
and
os
.
altsep
==
'/'
,
'test meaningful only where os.altsep is defined'
)
def
test_sep_altsep_and_sep_cache_from_source
(
self
):
# Windows path and PEP 3147 where sep is right of altsep.
self
.
assertEqual
(
imp
.
cache_from_source
(
'
\
\
foo
\
\
bar
\
\
baz/qux.py'
,
True
),
'
\
\
foo
\
\
bar
\
\
baz
/__pycache__/
qux.{}.pyc'
.
format
(
self
.
tag
))
'
\
\
foo
\
\
bar
\
\
baz
\
\
__pycache__
\
\
qux.{}.pyc'
.
format
(
self
.
tag
))
def
test_source_from_cache
(
self
):
# Given the path to a PEP 3147 defined .pyc file, return the path to
# its source. This tests the good path.
self
.
assertEqual
(
imp
.
source_from_cache
(
'/foo/bar/baz/__pycache__/qux.{}.pyc'
.
format
(
self
.
tag
)),
'/foo/bar/baz/qux.py'
)
path
=
os
.
path
.
join
(
'foo'
,
'bar'
,
'baz'
,
'__pycache__'
,
'qux.{}.pyc'
.
format
(
self
.
tag
))
expect
=
os
.
path
.
join
(
'foo'
,
'bar'
,
'baz'
,
'qux.py'
)
self
.
assertEqual
(
imp
.
source_from_cache
(
path
),
expect
)
def
test_source_from_cache_bad_path
(
self
):
# When the path to a pyc file is not in PEP 3147 format, a ValueError
...
...
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