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
e5e7a7cb
Commit
e5e7a7cb
authored
Mar 16, 2013
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Plain Diff
#11420: merge with 3.2.
parents
e3eb0615
c28f6fa5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
31 deletions
+54
-31
Lib/distutils/tests/test_bdist_dumb.py
Lib/distutils/tests/test_bdist_dumb.py
+3
-3
Lib/test/test_imp.py
Lib/test/test_imp.py
+4
-2
Lib/test/test_import.py
Lib/test/test_import.py
+13
-0
Lib/test/test_importlib/source/test_file_loader.py
Lib/test/test_importlib/source/test_file_loader.py
+2
-1
Lib/test/test_runpy.py
Lib/test/test_runpy.py
+29
-25
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/distutils/tests/test_bdist_dumb.py
View file @
e5e7a7cb
...
...
@@ -88,9 +88,9 @@ class BuildDumbTestCase(support.TempdirManager,
fp
.
close
()
contents
=
sorted
(
os
.
path
.
basename
(
fn
)
for
fn
in
contents
)
wanted
=
[
'foo-0.1-py%s.%s.egg-info'
%
sys
.
version_info
[:
2
],
'foo.%s.pyc'
%
imp
.
get_tag
(),
'foo.py'
]
wanted
=
[
'foo-0.1-py%s.%s.egg-info'
%
sys
.
version_info
[:
2
],
'foo.py'
]
if
not
sys
.
dont_write_bytecode
:
wanted
.
append
(
'foo.%s.pyc'
%
imp
.
get_tag
())
self
.
assertEqual
(
contents
,
sorted
(
wanted
))
def
test_suite
():
...
...
Lib/test/test_imp.py
View file @
e5e7a7cb
...
...
@@ -162,8 +162,10 @@ class ImportTests(unittest.TestCase):
with
warnings
.
catch_warnings
():
warnings
.
simplefilter
(
'ignore'
)
mod
=
imp
.
load_compiled
(
temp_mod_name
,
imp
.
cache_from_source
(
temp_mod_name
+
'.py'
))
if
not
sys
.
dont_write_bytecode
:
mod
=
imp
.
load_compiled
(
temp_mod_name
,
imp
.
cache_from_source
(
temp_mod_name
+
'.py'
))
self
.
assertEqual
(
mod
.
a
,
1
)
if
not
os
.
path
.
exists
(
test_package_name
):
...
...
Lib/test/test_import.py
View file @
e5e7a7cb
...
...
@@ -24,6 +24,10 @@ from test.support import (
from
test
import
script_helper
skip_if_dont_write_bytecode
=
unittest
.
skipIf
(
sys
.
dont_write_bytecode
,
"test meaningful only when writing bytecode"
)
def
remove_files
(
name
):
for
f
in
(
name
+
".py"
,
name
+
".pyc"
,
...
...
@@ -120,6 +124,7 @@ class ImportTests(unittest.TestCase):
finally
:
del
sys
.
path
[
0
]
@
skip_if_dont_write_bytecode
def
test_bug7732
(
self
):
source
=
TESTFN
+
'.py'
os
.
mkdir
(
source
)
...
...
@@ -230,6 +235,7 @@ class ImportTests(unittest.TestCase):
remove_files
(
TESTFN
)
unload
(
TESTFN
)
@
skip_if_dont_write_bytecode
def
test_file_to_source
(
self
):
# check if __file__ points to the source file where available
source
=
TESTFN
+
".py"
...
...
@@ -316,6 +322,7 @@ class ImportTests(unittest.TestCase):
self
.
fail
(
"fromlist must allow bogus names"
)
@
skip_if_dont_write_bytecode
class
FilePermissionTests
(
unittest
.
TestCase
):
# tests for file mode on cached .pyc/.pyo files
...
...
@@ -642,6 +649,7 @@ class PycacheTests(unittest.TestCase):
del
sys
.
path
[
0
]
self
.
_clean
()
@
skip_if_dont_write_bytecode
def
test_import_pyc_path
(
self
):
self
.
assertFalse
(
os
.
path
.
exists
(
'__pycache__'
))
__import__
(
TESTFN
)
...
...
@@ -654,6 +662,7 @@ class PycacheTests(unittest.TestCase):
"test meaningful only on posix systems"
)
@
unittest
.
skipIf
(
hasattr
(
os
,
'geteuid'
)
and
os
.
geteuid
()
==
0
,
"due to varying filesystem permission semantics (issue #11956)"
)
@
skip_if_dont_write_bytecode
def
test_unwritable_directory
(
self
):
# When the umask causes the new __pycache__ directory to be
# unwritable, the import still succeeds but no .pyc file is written.
...
...
@@ -663,6 +672,7 @@ class PycacheTests(unittest.TestCase):
self
.
assertFalse
(
os
.
path
.
exists
(
os
.
path
.
join
(
'__pycache__'
,
'{}.{}.pyc'
.
format
(
TESTFN
,
self
.
tag
))))
@
skip_if_dont_write_bytecode
def
test_missing_source
(
self
):
# With PEP 3147 cache layout, removing the source but leaving the pyc
# file does not satisfy the import.
...
...
@@ -673,6 +683,7 @@ class PycacheTests(unittest.TestCase):
forget
(
TESTFN
)
self
.
assertRaises
(
ImportError
,
__import__
,
TESTFN
)
@
skip_if_dont_write_bytecode
def
test_missing_source_legacy
(
self
):
# Like test_missing_source() except that for backward compatibility,
# when the pyc file lives where the py file would have been (and named
...
...
@@ -694,6 +705,7 @@ class PycacheTests(unittest.TestCase):
pyc_file
=
imp
.
cache_from_source
(
TESTFN
+
'.py'
)
self
.
assertEqual
(
m
.
__cached__
,
os
.
path
.
join
(
os
.
curdir
,
pyc_file
))
@
skip_if_dont_write_bytecode
def
test___cached___legacy_pyc
(
self
):
# Like test___cached__() except that for backward compatibility,
# when the pyc file lives where the py file would have been (and named
...
...
@@ -709,6 +721,7 @@ class PycacheTests(unittest.TestCase):
self
.
assertEqual
(
m
.
__cached__
,
os
.
path
.
join
(
os
.
curdir
,
os
.
path
.
relpath
(
pyc_file
)))
@
skip_if_dont_write_bytecode
def
test_package___cached__
(
self
):
# Like test___cached__ but for packages.
def
cleanup
():
...
...
Lib/test/test_importlib/source/test_file_loader.py
View file @
e5e7a7cb
...
...
@@ -159,7 +159,8 @@ class SimpleTest(unittest.TestCase):
finally
:
os
.
unlink
(
file_path
)
pycache
=
os
.
path
.
dirname
(
imp
.
cache_from_source
(
file_path
))
shutil
.
rmtree
(
pycache
)
if
os
.
path
.
exists
(
pycache
):
shutil
.
rmtree
(
pycache
)
def
test_timestamp_overflow
(
self
):
# When a modification timestamp is larger than 2**32, it should be
...
...
Lib/test/test_runpy.py
View file @
e5e7a7cb
...
...
@@ -258,12 +258,13 @@ class RunModuleTestCase(unittest.TestCase, CodeExecutionMixin):
importlib
.
invalidate_caches
()
__import__
(
mod_name
)
os
.
remove
(
mod_fname
)
make_legacy_pyc
(
mod_fname
)
unload
(
mod_name
)
# In case loader caches paths
importlib
.
invalidate_caches
()
if
verbose
>
1
:
print
(
"Running from compiled:"
,
mod_name
)
self
.
_fix_ns_for_legacy_pyc
(
expected_ns
,
alter_sys
)
self
.
check_code_execution
(
create_ns
,
expected_ns
)
if
not
sys
.
dont_write_bytecode
:
make_legacy_pyc
(
mod_fname
)
unload
(
mod_name
)
# In case loader caches paths
importlib
.
invalidate_caches
()
if
verbose
>
1
:
print
(
"Running from compiled:"
,
mod_name
)
self
.
_fix_ns_for_legacy_pyc
(
expected_ns
,
alter_sys
)
self
.
check_code_execution
(
create_ns
,
expected_ns
)
finally
:
self
.
_del_pkg
(
pkg_dir
,
depth
,
mod_name
)
if
verbose
>
1
:
print
(
"Module executed successfully"
)
...
...
@@ -293,12 +294,13 @@ class RunModuleTestCase(unittest.TestCase, CodeExecutionMixin):
importlib
.
invalidate_caches
()
__import__
(
mod_name
)
os
.
remove
(
mod_fname
)
make_legacy_pyc
(
mod_fname
)
unload
(
mod_name
)
# In case loader caches paths
if
verbose
>
1
:
print
(
"Running from compiled:"
,
pkg_name
)
importlib
.
invalidate_caches
()
self
.
_fix_ns_for_legacy_pyc
(
expected_ns
,
alter_sys
)
self
.
check_code_execution
(
create_ns
,
expected_ns
)
if
not
sys
.
dont_write_bytecode
:
make_legacy_pyc
(
mod_fname
)
unload
(
mod_name
)
# In case loader caches paths
if
verbose
>
1
:
print
(
"Running from compiled:"
,
pkg_name
)
importlib
.
invalidate_caches
()
self
.
_fix_ns_for_legacy_pyc
(
expected_ns
,
alter_sys
)
self
.
check_code_execution
(
create_ns
,
expected_ns
)
finally
:
self
.
_del_pkg
(
pkg_dir
,
depth
,
pkg_name
)
if
verbose
>
1
:
print
(
"Package executed successfully"
)
...
...
@@ -351,16 +353,17 @@ from ..uncle.cousin import nephew
importlib
.
invalidate_caches
()
__import__
(
mod_name
)
os
.
remove
(
mod_fname
)
make_legacy_pyc
(
mod_fname
)
unload
(
mod_name
)
# In case the loader caches paths
if
verbose
>
1
:
print
(
"Running from compiled:"
,
mod_name
)
importlib
.
invalidate_caches
()
d2
=
run_module
(
mod_name
,
run_name
=
run_name
)
# Read from bytecode
self
.
assertEqual
(
d2
[
"__name__"
],
expected_name
)
self
.
assertEqual
(
d2
[
"__package__"
],
pkg_name
)
self
.
assertIn
(
"sibling"
,
d2
)
self
.
assertIn
(
"nephew"
,
d2
)
del
d2
# Ensure __loader__ entry doesn't keep file open
if
not
sys
.
dont_write_bytecode
:
make_legacy_pyc
(
mod_fname
)
unload
(
mod_name
)
# In case the loader caches paths
if
verbose
>
1
:
print
(
"Running from compiled:"
,
mod_name
)
importlib
.
invalidate_caches
()
d2
=
run_module
(
mod_name
,
run_name
=
run_name
)
# Read from bytecode
self
.
assertEqual
(
d2
[
"__name__"
],
expected_name
)
self
.
assertEqual
(
d2
[
"__package__"
],
pkg_name
)
self
.
assertIn
(
"sibling"
,
d2
)
self
.
assertIn
(
"nephew"
,
d2
)
del
d2
# Ensure __loader__ entry doesn't keep file open
finally
:
self
.
_del_pkg
(
pkg_dir
,
depth
,
mod_name
)
if
verbose
>
1
:
print
(
"Module executed successfully"
)
...
...
@@ -513,9 +516,10 @@ class RunPathTestCase(unittest.TestCase, CodeExecutionMixin):
script_name
=
self
.
_make_test_script
(
script_dir
,
mod_name
)
compiled_name
=
py_compile
.
compile
(
script_name
,
doraise
=
True
)
os
.
remove
(
script_name
)
legacy_pyc
=
make_legacy_pyc
(
script_name
)
self
.
_check_script
(
script_dir
,
"<run_path>"
,
legacy_pyc
,
script_dir
)
if
not
sys
.
dont_write_bytecode
:
legacy_pyc
=
make_legacy_pyc
(
script_name
)
self
.
_check_script
(
script_dir
,
"<run_path>"
,
legacy_pyc
,
script_dir
)
def
test_directory_error
(
self
):
with
temp_dir
()
as
script_dir
:
...
...
Misc/NEWS
View file @
e5e7a7cb
...
...
@@ -654,6 +654,9 @@ Library
Tests
-----
- Issue #11420: make test suite pass with -B/DONTWRITEBYTECODE set.
Initial patch by Thomas Wouters.
- Issue #10652: make tcl/tk tests run after __all__ test, patch by
Zachary Ware.
...
...
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