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
a3c69634
Commit
a3c69634
authored
Nov 08, 2013
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16803: test.test_importlib.frozen now runs both frozen and source code
parent
8ea86509
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
31 deletions
+33
-31
Lib/test/test_importlib/frozen/test_finder.py
Lib/test/test_importlib/frozen/test_finder.py
+8
-8
Lib/test/test_importlib/frozen/test_loader.py
Lib/test/test_importlib/frozen/test_loader.py
+25
-23
No files found.
Lib/test/test_importlib/frozen/test_finder.py
View file @
a3c69634
from
importlib
import
machinery
from
..
import
abc
from
..
import
util
machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
import
unittest
class
FinderTests
(
unittest
.
TestCase
,
abc
.
FinderTests
):
class
FinderTests
(
abc
.
FinderTests
):
"""Test finding frozen modules."""
def
find
(
self
,
name
,
path
=
None
):
finder
=
machinery
.
FrozenImporter
finder
=
self
.
machinery
.
FrozenImporter
return
finder
.
find_module
(
name
,
path
)
def
test_module
(
self
):
...
...
@@ -37,11 +39,9 @@ class FinderTests(unittest.TestCase, abc.FinderTests):
loader
=
self
.
find
(
'<not real>'
)
self
.
assertIsNone
(
loader
)
def
test_main
():
from
test.support
import
run_unittest
run_unittest
(
FinderTests
)
Frozen_FinderTests
,
Source_FinderTests
=
util
.
test_both
(
FinderTests
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
test_
main
()
unittest
.
main
()
Lib/test/test_importlib/frozen/test_loader.py
View file @
a3c69634
from
..
import
abc
from
..
import
util
from
importlib
import
machinery
machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
import
unittest
from
test.support
import
captured_stdout
import
types
class
LoaderTests
(
unittest
.
TestCase
,
abc
.
LoaderTests
):
class
LoaderTests
(
abc
.
LoaderTests
):
def
test_module
(
self
):
with
util
.
uncache
(
'__hello__'
),
captured_stdout
()
as
stdout
:
module
=
machinery
.
FrozenImporter
.
load_module
(
'__hello__'
)
module
=
self
.
machinery
.
FrozenImporter
.
load_module
(
'__hello__'
)
check
=
{
'__name__'
:
'__hello__'
,
'__package__'
:
''
,
'__loader__'
:
machinery
.
FrozenImporter
,
'__loader__'
:
self
.
machinery
.
FrozenImporter
,
}
for
attr
,
value
in
check
.
items
():
self
.
assertEqual
(
getattr
(
module
,
attr
),
value
)
...
...
@@ -23,11 +24,11 @@ class LoaderTests(unittest.TestCase, abc.LoaderTests):
def
test_package
(
self
):
with
util
.
uncache
(
'__phello__'
),
captured_stdout
()
as
stdout
:
module
=
machinery
.
FrozenImporter
.
load_module
(
'__phello__'
)
module
=
self
.
machinery
.
FrozenImporter
.
load_module
(
'__phello__'
)
check
=
{
'__name__'
:
'__phello__'
,
'__package__'
:
'__phello__'
,
'__path__'
:
[],
'__loader__'
:
machinery
.
FrozenImporter
,
'__loader__'
:
self
.
machinery
.
FrozenImporter
,
}
for
attr
,
value
in
check
.
items
():
attr_value
=
getattr
(
module
,
attr
)
...
...
@@ -40,10 +41,10 @@ class LoaderTests(unittest.TestCase, abc.LoaderTests):
def
test_lacking_parent
(
self
):
with
util
.
uncache
(
'__phello__'
,
'__phello__.spam'
),
\
captured_stdout
()
as
stdout
:
module
=
machinery
.
FrozenImporter
.
load_module
(
'__phello__.spam'
)
module
=
self
.
machinery
.
FrozenImporter
.
load_module
(
'__phello__.spam'
)
check
=
{
'__name__'
:
'__phello__.spam'
,
'__package__'
:
'__phello__'
,
'__loader__'
:
machinery
.
FrozenImporter
,
'__loader__'
:
self
.
machinery
.
FrozenImporter
,
}
for
attr
,
value
in
check
.
items
():
attr_value
=
getattr
(
module
,
attr
)
...
...
@@ -55,15 +56,15 @@ class LoaderTests(unittest.TestCase, abc.LoaderTests):
def
test_module_reuse
(
self
):
with
util
.
uncache
(
'__hello__'
),
captured_stdout
()
as
stdout
:
module1
=
machinery
.
FrozenImporter
.
load_module
(
'__hello__'
)
module2
=
machinery
.
FrozenImporter
.
load_module
(
'__hello__'
)
module1
=
self
.
machinery
.
FrozenImporter
.
load_module
(
'__hello__'
)
module2
=
self
.
machinery
.
FrozenImporter
.
load_module
(
'__hello__'
)
self
.
assertIs
(
module1
,
module2
)
self
.
assertEqual
(
stdout
.
getvalue
(),
'Hello world!
\
n
Hello world!
\
n
'
)
def
test_module_repr
(
self
):
with
util
.
uncache
(
'__hello__'
),
captured_stdout
():
module
=
machinery
.
FrozenImporter
.
load_module
(
'__hello__'
)
module
=
self
.
machinery
.
FrozenImporter
.
load_module
(
'__hello__'
)
self
.
assertEqual
(
repr
(
module
),
"<module '__hello__' (frozen)>"
)
...
...
@@ -72,13 +73,16 @@ class LoaderTests(unittest.TestCase, abc.LoaderTests):
pass
def
test_unloadable
(
self
):
assert
machinery
.
FrozenImporter
.
find_module
(
'_not_real'
)
is
None
assert
self
.
machinery
.
FrozenImporter
.
find_module
(
'_not_real'
)
is
None
with
self
.
assertRaises
(
ImportError
)
as
cm
:
machinery
.
FrozenImporter
.
load_module
(
'_not_real'
)
self
.
machinery
.
FrozenImporter
.
load_module
(
'_not_real'
)
self
.
assertEqual
(
cm
.
exception
.
name
,
'_not_real'
)
Frozen_LoaderTests
,
Source_LoaderTests
=
util
.
test_both
(
LoaderTests
,
machinery
=
machinery
)
class
InspectLoaderTests
(
unittest
.
TestCase
)
:
class
InspectLoaderTests
:
"""Tests for the InspectLoader methods for FrozenImporter."""
...
...
@@ -86,7 +90,7 @@ class InspectLoaderTests(unittest.TestCase):
# Make sure that the code object is good.
name
=
'__hello__'
with
captured_stdout
()
as
stdout
:
code
=
machinery
.
FrozenImporter
.
get_code
(
name
)
code
=
self
.
machinery
.
FrozenImporter
.
get_code
(
name
)
mod
=
types
.
ModuleType
(
name
)
exec
(
code
,
mod
.
__dict__
)
self
.
assertTrue
(
hasattr
(
mod
,
'initialized'
))
...
...
@@ -94,7 +98,7 @@ class InspectLoaderTests(unittest.TestCase):
def
test_get_source
(
self
):
# Should always return None.
result
=
machinery
.
FrozenImporter
.
get_source
(
'__hello__'
)
result
=
self
.
machinery
.
FrozenImporter
.
get_source
(
'__hello__'
)
self
.
assertIsNone
(
result
)
def
test_is_package
(
self
):
...
...
@@ -102,22 +106,20 @@ class InspectLoaderTests(unittest.TestCase):
test_for
=
((
'__hello__'
,
False
),
(
'__phello__'
,
True
),
(
'__phello__.spam'
,
False
))
for
name
,
is_package
in
test_for
:
result
=
machinery
.
FrozenImporter
.
is_package
(
name
)
result
=
self
.
machinery
.
FrozenImporter
.
is_package
(
name
)
self
.
assertEqual
(
bool
(
result
),
is_package
)
def
test_failure
(
self
):
# Raise ImportError for modules that are not frozen.
for
meth_name
in
(
'get_code'
,
'get_source'
,
'is_package'
):
method
=
getattr
(
machinery
.
FrozenImporter
,
meth_name
)
method
=
getattr
(
self
.
machinery
.
FrozenImporter
,
meth_name
)
with
self
.
assertRaises
(
ImportError
)
as
cm
:
method
(
'importlib'
)
self
.
assertEqual
(
cm
.
exception
.
name
,
'importlib'
)
def
test_main
():
from
test.support
import
run_unittest
run_unittest
(
LoaderTests
,
InspectLoaderTests
)
Frozen_ILTests
,
Source_ILTests
=
util
.
test_both
(
InspectLoaderTests
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
test_
main
()
unittest
.
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