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
3497c0bf
Commit
3497c0bf
authored
May 16, 2014
by
Eric Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #21503: Use test_both() consistently in test_importlib.
parent
d50cee20
Changes
30
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
527 additions
and
429 deletions
+527
-429
Lib/test/test_importlib/builtin/test_finder.py
Lib/test/test_importlib/builtin/test_finder.py
+9
-5
Lib/test/test_importlib/builtin/test_loader.py
Lib/test/test_importlib/builtin/test_loader.py
+8
-6
Lib/test/test_importlib/extension/test_case_sensitivity.py
Lib/test/test_importlib/extension/test_case_sensitivity.py
+5
-4
Lib/test/test_importlib/extension/test_finder.py
Lib/test/test_importlib/extension/test_finder.py
+4
-2
Lib/test/test_importlib/extension/test_loader.py
Lib/test/test_importlib/extension/test_loader.py
+3
-2
Lib/test/test_importlib/extension/test_path_hook.py
Lib/test/test_importlib/extension/test_path_hook.py
+4
-2
Lib/test/test_importlib/frozen/test_finder.py
Lib/test/test_importlib/frozen/test_finder.py
+8
-4
Lib/test/test_importlib/frozen/test_loader.py
Lib/test/test_importlib/frozen/test_loader.py
+11
-6
Lib/test/test_importlib/import_/test___loader__.py
Lib/test/test_importlib/import_/test___loader__.py
+7
-4
Lib/test/test_importlib/import_/test___package__.py
Lib/test/test_importlib/import_/test___package__.py
+11
-5
Lib/test/test_importlib/import_/test_api.py
Lib/test/test_importlib/import_/test_api.py
+8
-4
Lib/test/test_importlib/import_/test_caching.py
Lib/test/test_importlib/import_/test_caching.py
+5
-3
Lib/test/test_importlib/import_/test_fromlist.py
Lib/test/test_importlib/import_/test_fromlist.py
+8
-4
Lib/test/test_importlib/import_/test_meta_path.py
Lib/test/test_importlib/import_/test_meta_path.py
+14
-6
Lib/test/test_importlib/import_/test_packages.py
Lib/test/test_importlib/import_/test_packages.py
+4
-2
Lib/test/test_importlib/import_/test_path.py
Lib/test/test_importlib/import_/test_path.py
+8
-4
Lib/test/test_importlib/import_/test_relative_imports.py
Lib/test/test_importlib/import_/test_relative_imports.py
+4
-2
Lib/test/test_importlib/source/test_case_sensitivity.py
Lib/test/test_importlib/source/test_case_sensitivity.py
+12
-4
Lib/test/test_importlib/source/test_file_loader.py
Lib/test/test_importlib/source/test_file_loader.py
+35
-15
Lib/test/test_importlib/source/test_finder.py
Lib/test/test_importlib/source/test_finder.py
+11
-6
Lib/test/test_importlib/source/test_path_hook.py
Lib/test/test_importlib/source/test_path_hook.py
+4
-1
Lib/test/test_importlib/source/test_source_encoding.py
Lib/test/test_importlib/source/test_source_encoding.py
+20
-8
Lib/test/test_importlib/test_abc.py
Lib/test/test_importlib/test_abc.py
+142
-150
Lib/test/test_importlib/test_api.py
Lib/test/test_importlib/test_api.py
+46
-53
Lib/test/test_importlib/test_locks.py
Lib/test/test_importlib/test_locks.py
+26
-21
Lib/test/test_importlib/test_spec.py
Lib/test/test_importlib/test_spec.py
+29
-43
Lib/test/test_importlib/test_util.py
Lib/test/test_importlib/test_util.py
+44
-41
Lib/test/test_importlib/test_windows.py
Lib/test/test_importlib/test_windows.py
+5
-10
Lib/test/test_importlib/util.py
Lib/test/test_importlib/util.py
+30
-12
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_importlib/builtin/test_finder.py
View file @
3497c0bf
from
..
import
abc
from
..
import
util
frozen_machinery
,
source_
machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
import
sys
import
unittest
...
...
@@ -44,8 +44,10 @@ class FindSpecTests(abc.FinderTests):
[
'pkg'
])
self
.
assertIsNone
(
spec
)
Frozen_FindSpecTests
,
Source_FindSpecTests
=
util
.
test_both
(
FindSpecTests
,
machinery
=
[
frozen_machinery
,
source_machinery
])
(
Frozen_FindSpecTests
,
Source_FindSpecTests
)
=
util
.
test_both
(
FindSpecTests
,
machinery
=
machinery
)
@
unittest
.
skipIf
(
util
.
BUILTINS
.
good_name
is
None
,
'no reasonable builtin module'
)
...
...
@@ -78,8 +80,10 @@ class FinderTests(abc.FinderTests):
[
'pkg'
])
self
.
assertIsNone
(
loader
)
Frozen_FinderTests
,
Source_FinderTests
=
util
.
test_both
(
FinderTests
,
machinery
=
[
frozen_machinery
,
source_machinery
])
(
Frozen_FinderTests
,
Source_FinderTests
)
=
util
.
test_both
(
FinderTests
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/builtin/test_loader.py
View file @
3497c0bf
from
..
import
abc
from
..
import
util
frozen_machinery
,
source_
machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
import
sys
import
types
...
...
@@ -65,8 +65,9 @@ class LoaderTests(abc.LoaderTests):
self
.
assertEqual
(
cm
.
exception
.
name
,
module_name
)
Frozen_LoaderTests
,
Source_LoaderTests
=
util
.
test_both
(
LoaderTests
,
machinery
=
[
frozen_machinery
,
source_machinery
])
(
Frozen_LoaderTests
,
Source_LoaderTests
)
=
util
.
test_both
(
LoaderTests
,
machinery
=
machinery
)
@
unittest
.
skipIf
(
util
.
BUILTINS
.
good_name
is
None
,
'no reasonable builtin module'
)
...
...
@@ -98,9 +99,10 @@ class InspectLoaderTests:
method
(
util
.
BUILTINS
.
bad_name
)
self
.
assertRaises
(
util
.
BUILTINS
.
bad_name
)
Frozen_InspectLoaderTests
,
Source_InspectLoaderTests
=
util
.
test_both
(
InspectLoaderTests
,
machinery
=
[
frozen_machinery
,
source_machinery
])
(
Frozen_InspectLoaderTests
,
Source_InspectLoaderTests
)
=
util
.
test_both
(
InspectLoaderTests
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/extension/test_case_sensitivity.py
View file @
3497c0bf
...
...
@@ -5,7 +5,7 @@ import unittest
from
..
import
util
frozen_machinery
,
source_
machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
# XXX find_spec tests
...
...
@@ -41,9 +41,10 @@ class ExtensionModuleCaseSensitivityTest:
loader
=
self
.
find_module
()
self
.
assertTrue
(
hasattr
(
loader
,
'load_module'
))
Frozen_ExtensionCaseSensitivity
,
Source_ExtensionCaseSensitivity
=
util
.
test_both
(
ExtensionModuleCaseSensitivityTest
,
machinery
=
[
frozen_machinery
,
source_machinery
])
(
Frozen_ExtensionCaseSensitivity
,
Source_ExtensionCaseSensitivity
)
=
util
.
test_both
(
ExtensionModuleCaseSensitivityTest
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/extension/test_finder.py
View file @
3497c0bf
...
...
@@ -35,8 +35,10 @@ class FinderTests(abc.FinderTests):
def
test_failure
(
self
):
self
.
assertIsNone
(
self
.
find_module
(
'asdfjkl;'
))
Frozen_FinderTests
,
Source_FinderTests
=
util
.
test_both
(
FinderTests
,
machinery
=
machinery
)
(
Frozen_FinderTests
,
Source_FinderTests
)
=
util
.
test_both
(
FinderTests
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/extension/test_loader.py
View file @
3497c0bf
...
...
@@ -76,8 +76,9 @@ class LoaderTests(abc.LoaderTests):
loader
=
self
.
machinery
.
ExtensionFileLoader
(
'pkg'
,
path
)
self
.
assertTrue
(
loader
.
is_package
(
'pkg'
))
Frozen_LoaderTests
,
Source_LoaderTests
=
util
.
test_both
(
LoaderTests
,
machinery
=
machinery
)
(
Frozen_LoaderTests
,
Source_LoaderTests
)
=
util
.
test_both
(
LoaderTests
,
machinery
=
machinery
)
...
...
Lib/test/test_importlib/extension/test_path_hook.py
View file @
3497c0bf
...
...
@@ -23,8 +23,10 @@ class PathHookTests:
# exists.
self
.
assertTrue
(
hasattr
(
self
.
hook
(
util
.
EXTENSIONS
.
path
),
'find_module'
))
Frozen_PathHooksTests
,
Source_PathHooksTests
=
util
.
test_both
(
PathHookTests
,
machinery
=
machinery
)
(
Frozen_PathHooksTests
,
Source_PathHooksTests
)
=
util
.
test_both
(
PathHookTests
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/frozen/test_finder.py
View file @
3497c0bf
...
...
@@ -37,8 +37,10 @@ class FindSpecTests(abc.FinderTests):
spec
=
self
.
find
(
'<not real>'
)
self
.
assertIsNone
(
spec
)
Frozen_FindSpecTests
,
Source_FindSpecTests
=
util
.
test_both
(
FindSpecTests
,
machinery
=
machinery
)
(
Frozen_FindSpecTests
,
Source_FindSpecTests
)
=
util
.
test_both
(
FindSpecTests
,
machinery
=
machinery
)
class
FinderTests
(
abc
.
FinderTests
):
...
...
@@ -72,8 +74,10 @@ class FinderTests(abc.FinderTests):
loader
=
self
.
find
(
'<not real>'
)
self
.
assertIsNone
(
loader
)
Frozen_FinderTests
,
Source_FinderTests
=
util
.
test_both
(
FinderTests
,
machinery
=
machinery
)
(
Frozen_FinderTests
,
Source_FinderTests
)
=
util
.
test_both
(
FinderTests
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/frozen/test_loader.py
View file @
3497c0bf
...
...
@@ -85,8 +85,10 @@ class ExecModuleTests(abc.LoaderTests):
self
.
exec_module
(
'_not_real'
)
self
.
assertEqual
(
cm
.
exception
.
name
,
'_not_real'
)
Frozen_ExecModuleTests
,
Source_ExecModuleTests
=
util
.
test_both
(
ExecModuleTests
,
machinery
=
machinery
)
(
Frozen_ExecModuleTests
,
Source_ExecModuleTests
)
=
util
.
test_both
(
ExecModuleTests
,
machinery
=
machinery
)
class
LoaderTests
(
abc
.
LoaderTests
):
...
...
@@ -175,8 +177,10 @@ class LoaderTests(abc.LoaderTests):
self
.
machinery
.
FrozenImporter
.
load_module
(
'_not_real'
)
self
.
assertEqual
(
cm
.
exception
.
name
,
'_not_real'
)
Frozen_LoaderTests
,
Source_LoaderTests
=
util
.
test_both
(
LoaderTests
,
machinery
=
machinery
)
(
Frozen_LoaderTests
,
Source_LoaderTests
)
=
util
.
test_both
(
LoaderTests
,
machinery
=
machinery
)
class
InspectLoaderTests
:
...
...
@@ -214,8 +218,9 @@ class InspectLoaderTests:
method
(
'importlib'
)
self
.
assertEqual
(
cm
.
exception
.
name
,
'importlib'
)
Frozen_ILTests
,
Source_ILTests
=
util
.
test_both
(
InspectLoaderTests
,
machinery
=
machinery
)
(
Frozen_ILTests
,
Source_ILTests
)
=
util
.
test_both
(
InspectLoaderTests
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/import_/test___loader__.py
View file @
3497c0bf
...
...
@@ -23,8 +23,10 @@ class SpecLoaderAttributeTests:
module
=
self
.
__import__
(
'blah'
)
self
.
assertEqual
(
loader
,
module
.
__loader__
)
Frozen_SpecTests
,
Source_SpecTests
=
util
.
test_both
(
SpecLoaderAttributeTests
,
__import__
=
util
.
__import__
)
(
Frozen_SpecTests
,
Source_SpecTests
)
=
util
.
test_both
(
SpecLoaderAttributeTests
,
__import__
=
util
.
__import__
)
class
LoaderMock
:
...
...
@@ -61,8 +63,9 @@ class LoaderAttributeTests:
self
.
assertEqual
(
loader
,
module
.
__loader__
)
Frozen_Tests
,
Source_Tests
=
util
.
test_both
(
LoaderAttributeTests
,
__import__
=
util
.
__import__
)
(
Frozen_Tests
,
Source_Tests
)
=
util
.
test_both
(
LoaderAttributeTests
,
__import__
=
util
.
__import__
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/import_/test___package__.py
View file @
3497c0bf
...
...
@@ -69,17 +69,23 @@ class Using__package__:
with
self
.
assertRaises
(
TypeError
):
self
.
__import__
(
''
,
globals
,
{},
[
'relimport'
],
1
)
class
Using__package__PEP302
(
Using__package__
):
mock_modules
=
util
.
mock_modules
Frozen_UsingPackagePEP302
,
Source_UsingPackagePEP302
=
util
.
test_both
(
Using__package__PEP302
,
__import__
=
util
.
__import__
)
(
Frozen_UsingPackagePEP302
,
Source_UsingPackagePEP302
)
=
util
.
test_both
(
Using__package__PEP302
,
__import__
=
util
.
__import__
)
class
Using__package__PEP451
(
Using__package__
):
mock_modules
=
util
.
mock_spec
Frozen_UsingPackagePEP451
,
Source_UsingPackagePEP451
=
util
.
test_both
(
Using__package__PEP451
,
__import__
=
util
.
__import__
)
(
Frozen_UsingPackagePEP451
,
Source_UsingPackagePEP451
)
=
util
.
test_both
(
Using__package__PEP451
,
__import__
=
util
.
__import__
)
class
Setting__package__
:
...
...
@@ -94,7 +100,7 @@ class Setting__package__:
"""
__import__
=
util
.
__import__
[
1
]
__import__
=
util
.
__import__
[
'Source'
]
# [top-level]
def
test_top_level
(
self
):
...
...
Lib/test/test_importlib/import_/test_api.py
View file @
3497c0bf
...
...
@@ -78,15 +78,19 @@ class APITest:
class
OldAPITests
(
APITest
):
bad_finder_loader
=
BadLoaderFinder
Frozen_OldAPITests
,
Source_OldAPITests
=
util
.
test_both
(
OldAPITests
,
__import__
=
util
.
__import__
)
(
Frozen_OldAPITests
,
Source_OldAPITests
)
=
util
.
test_both
(
OldAPITests
,
__import__
=
util
.
__import__
)
class
SpecAPITests
(
APITest
):
bad_finder_loader
=
BadSpecFinderLoader
Frozen_SpecAPITests
,
Source_SpecAPITests
=
util
.
test_both
(
SpecAPITests
,
__import__
=
util
.
__import__
)
(
Frozen_SpecAPITests
,
Source_SpecAPITests
)
=
util
.
test_both
(
SpecAPITests
,
__import__
=
util
.
__import__
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/import_/test_caching.py
View file @
3497c0bf
...
...
@@ -38,15 +38,17 @@ class UseCache:
self
.
__import__
(
name
)
self
.
assertEqual
(
cm
.
exception
.
name
,
name
)
Frozen_UseCache
,
Source_UseCache
=
util
.
test_both
(
UseCache
,
__import__
=
util
.
__import__
)
(
Frozen_UseCache
,
Source_UseCache
)
=
util
.
test_both
(
UseCache
,
__import__
=
util
.
__import__
)
class
ImportlibUseCache
(
UseCache
,
unittest
.
TestCase
):
# Pertinent only to PEP 302; exec_module() doesn't return a module.
__import__
=
util
.
__import__
[
1
]
__import__
=
util
.
__import__
[
'Source'
]
def
create_mock
(
self
,
*
names
,
return_
=
None
):
mock
=
util
.
mock_modules
(
*
names
)
...
...
Lib/test/test_importlib/import_/test_fromlist.py
View file @
3497c0bf
...
...
@@ -28,8 +28,10 @@ class ReturnValue:
module
=
self
.
__import__
(
'pkg.module'
,
fromlist
=
[
'attr'
])
self
.
assertEqual
(
module
.
__name__
,
'pkg.module'
)
Frozen_ReturnValue
,
Source_ReturnValue
=
util
.
test_both
(
ReturnValue
,
__import__
=
util
.
__import__
)
(
Frozen_ReturnValue
,
Source_ReturnValue
)
=
util
.
test_both
(
ReturnValue
,
__import__
=
util
.
__import__
)
class
HandlingFromlist
:
...
...
@@ -120,8 +122,10 @@ class HandlingFromlist:
self
.
assertEqual
(
module
.
module1
.
__name__
,
'pkg.module1'
)
self
.
assertEqual
(
module
.
module2
.
__name__
,
'pkg.module2'
)
Frozen_FromList
,
Source_FromList
=
util
.
test_both
(
HandlingFromlist
,
__import__
=
util
.
__import__
)
(
Frozen_FromList
,
Source_FromList
)
=
util
.
test_both
(
HandlingFromlist
,
__import__
=
util
.
__import__
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/import_/test_meta_path.py
View file @
3497c0bf
...
...
@@ -45,8 +45,10 @@ class CallingOrder:
self
.
assertEqual
(
len
(
w
),
1
)
self
.
assertTrue
(
issubclass
(
w
[
-
1
].
category
,
ImportWarning
))
Frozen_CallingOrder
,
Source_CallingOrder
=
util
.
test_both
(
CallingOrder
,
__import__
=
util
.
__import__
)
(
Frozen_CallingOrder
,
Source_CallingOrder
)
=
util
.
test_both
(
CallingOrder
,
__import__
=
util
.
__import__
)
class
CallSignature
:
...
...
@@ -99,19 +101,25 @@ class CallSignature:
self
.
assertEqual
(
args
[
0
],
mod_name
)
self
.
assertIs
(
args
[
1
],
path
)
class
CallSignaturePEP302
(
CallSignature
):
mock_modules
=
util
.
mock_modules
finder_name
=
'find_module'
Frozen_CallSignaturePEP302
,
Source_CallSignaturePEP302
=
util
.
test_both
(
CallSignaturePEP302
,
__import__
=
util
.
__import__
)
(
Frozen_CallSignaturePEP302
,
Source_CallSignaturePEP302
)
=
util
.
test_both
(
CallSignaturePEP302
,
__import__
=
util
.
__import__
)
class
CallSignaturePEP451
(
CallSignature
):
mock_modules
=
util
.
mock_spec
finder_name
=
'find_spec'
Frozen_CallSignaturePEP451
,
Source_CallSignaturePEP451
=
util
.
test_both
(
CallSignaturePEP451
,
__import__
=
util
.
__import__
)
(
Frozen_CallSignaturePEP451
,
Source_CallSignaturePEP451
)
=
util
.
test_both
(
CallSignaturePEP451
,
__import__
=
util
.
__import__
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/import_/test_packages.py
View file @
3497c0bf
...
...
@@ -101,8 +101,10 @@ class ParentModuleTests:
finally
:
support
.
unload
(
subname
)
Frozen_ParentTests
,
Source_ParentTests
=
util
.
test_both
(
ParentModuleTests
,
__import__
=
util
.
__import__
)
(
Frozen_ParentTests
,
Source_ParentTests
)
=
util
.
test_both
(
ParentModuleTests
,
__import__
=
util
.
__import__
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/import_/test_path.py
View file @
3497c0bf
...
...
@@ -158,8 +158,10 @@ class FinderTests:
got
=
self
.
machinery
.
PathFinder
.
find_spec
(
'whatever'
,
[
path
])
self
.
assertEqual
(
got
,
success_finder
.
spec
)
Frozen_FinderTests
,
Source_FinderTests
=
util
.
test_both
(
FinderTests
,
importlib
=
importlib
,
machinery
=
machinery
)
(
Frozen_FinderTests
,
Source_FinderTests
)
=
util
.
test_both
(
FinderTests
,
importlib
=
importlib
,
machinery
=
machinery
)
class
PathEntryFinderTests
:
...
...
@@ -182,8 +184,10 @@ class PathEntryFinderTests:
path_hooks
=
[
Finder
]):
self
.
machinery
.
PathFinder
.
find_spec
(
'importlib'
)
Frozen_PEFTests
,
Source_PEFTests
=
util
.
test_both
(
PathEntryFinderTests
,
machinery
=
machinery
)
(
Frozen_PEFTests
,
Source_PEFTests
)
=
util
.
test_both
(
PathEntryFinderTests
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/import_/test_relative_imports.py
View file @
3497c0bf
...
...
@@ -207,8 +207,10 @@ class RelativeImports:
with
self
.
assertRaises
(
KeyError
):
self
.
__import__
(
'sys'
,
level
=
1
)
Frozen_RelativeImports
,
Source_RelativeImports
=
util
.
test_both
(
RelativeImports
,
__import__
=
util
.
__import__
)
(
Frozen_RelativeImports
,
Source_RelativeImports
)
=
util
.
test_both
(
RelativeImports
,
__import__
=
util
.
__import__
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/source/test_case_sensitivity.py
View file @
3497c0bf
...
...
@@ -62,20 +62,28 @@ class CaseSensitivityTest:
self
.
assertIsNotNone
(
insensitive
)
self
.
assertIn
(
self
.
name
,
insensitive
.
get_filename
(
self
.
name
))
class
CaseSensitivityTestPEP302
(
CaseSensitivityTest
):
def
find
(
self
,
finder
):
return
finder
.
find_module
(
self
.
name
)
Frozen_CaseSensitivityTestPEP302
,
Source_CaseSensitivityTestPEP302
=
util
.
test_both
(
CaseSensitivityTestPEP302
,
importlib
=
importlib
,
machinery
=
machinery
)
(
Frozen_CaseSensitivityTestPEP302
,
Source_CaseSensitivityTestPEP302
)
=
util
.
test_both
(
CaseSensitivityTestPEP302
,
importlib
=
importlib
,
machinery
=
machinery
)
class
CaseSensitivityTestPEP451
(
CaseSensitivityTest
):
def
find
(
self
,
finder
):
found
=
finder
.
find_spec
(
self
.
name
)
return
found
.
loader
if
found
is
not
None
else
found
Frozen_CaseSensitivityTestPEP451
,
Source_CaseSensitivityTestPEP451
=
util
.
test_both
(
CaseSensitivityTestPEP451
,
importlib
=
importlib
,
machinery
=
machinery
)
(
Frozen_CaseSensitivityTestPEP451
,
Source_CaseSensitivityTestPEP451
)
=
util
.
test_both
(
CaseSensitivityTestPEP451
,
importlib
=
importlib
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/source/test_file_loader.py
View file @
3497c0bf
...
...
@@ -235,9 +235,11 @@ class SimpleTest(abc.LoaderTests):
warnings
.
simplefilter
(
'ignore'
,
DeprecationWarning
)
loader
.
load_module
(
'bad name'
)
Frozen_SimpleTest
,
Source_SimpleTest
=
util
.
test_both
(
SimpleTest
,
importlib
=
importlib
,
machinery
=
machinery
,
abc
=
importlib_abc
,
util
=
importlib_util
)
(
Frozen_SimpleTest
,
Source_SimpleTest
)
=
util
.
test_both
(
SimpleTest
,
importlib
=
importlib
,
machinery
=
machinery
,
abc
=
importlib_abc
,
util
=
importlib_util
)
class
BadBytecodeTest
:
...
...
@@ -346,6 +348,7 @@ class BadBytecodeTest:
lambda
bc
:
b'
\
x00
\
x00
\
x00
\
x00
'
+
bc
[
4
:])
test
(
'_temp'
,
mapping
,
bc_path
)
class
BadBytecodeTestPEP451
(
BadBytecodeTest
):
def
import_
(
self
,
file
,
module_name
):
...
...
@@ -354,6 +357,7 @@ class BadBytecodeTestPEP451(BadBytecodeTest):
module
.
__spec__
=
self
.
util
.
spec_from_loader
(
module_name
,
loader
)
loader
.
exec_module
(
module
)
class
BadBytecodeTestPEP302
(
BadBytecodeTest
):
def
import_
(
self
,
file
,
module_name
):
...
...
@@ -490,21 +494,29 @@ class SourceLoaderBadBytecodeTest:
# Make writable for eventual clean-up.
os
.
chmod
(
bytecode_path
,
stat
.
S_IWUSR
)
class
SourceLoaderBadBytecodeTestPEP451
(
SourceLoaderBadBytecodeTest
,
BadBytecodeTestPEP451
):
pass
Frozen_SourceBadBytecodePEP451
,
Source_SourceBadBytecodePEP451
=
util
.
test_both
(
SourceLoaderBadBytecodeTestPEP451
,
importlib
=
importlib
,
machinery
=
machinery
,
abc
=
importlib_abc
,
util
=
importlib_util
)
(
Frozen_SourceBadBytecodePEP451
,
Source_SourceBadBytecodePEP451
)
=
util
.
test_both
(
SourceLoaderBadBytecodeTestPEP451
,
importlib
=
importlib
,
machinery
=
machinery
,
abc
=
importlib_abc
,
util
=
importlib_util
)
class
SourceLoaderBadBytecodeTestPEP302
(
SourceLoaderBadBytecodeTest
,
BadBytecodeTestPEP302
):
pass
Frozen_SourceBadBytecodePEP302
,
Source_SourceBadBytecodePEP302
=
util
.
test_both
(
SourceLoaderBadBytecodeTestPEP302
,
importlib
=
importlib
,
machinery
=
machinery
,
abc
=
importlib_abc
,
util
=
importlib_util
)
(
Frozen_SourceBadBytecodePEP302
,
Source_SourceBadBytecodePEP302
)
=
util
.
test_both
(
SourceLoaderBadBytecodeTestPEP302
,
importlib
=
importlib
,
machinery
=
machinery
,
abc
=
importlib_abc
,
util
=
importlib_util
)
class
SourcelessLoaderBadBytecodeTest
:
...
...
@@ -566,21 +578,29 @@ class SourcelessLoaderBadBytecodeTest:
def
test_non_code_marshal
(
self
):
self
.
_test_non_code_marshal
(
del_source
=
True
)
class
SourcelessLoaderBadBytecodeTestPEP451
(
SourcelessLoaderBadBytecodeTest
,
BadBytecodeTestPEP451
):
pass
Frozen_SourcelessBadBytecodePEP451
,
Source_SourcelessBadBytecodePEP451
=
util
.
test_both
(
SourcelessLoaderBadBytecodeTestPEP451
,
importlib
=
importlib
,
machinery
=
machinery
,
abc
=
importlib_abc
,
util
=
importlib_util
)
(
Frozen_SourcelessBadBytecodePEP451
,
Source_SourcelessBadBytecodePEP451
)
=
util
.
test_both
(
SourcelessLoaderBadBytecodeTestPEP451
,
importlib
=
importlib
,
machinery
=
machinery
,
abc
=
importlib_abc
,
util
=
importlib_util
)
class
SourcelessLoaderBadBytecodeTestPEP302
(
SourcelessLoaderBadBytecodeTest
,
BadBytecodeTestPEP302
):
pass
Frozen_SourcelessBadBytecodePEP302
,
Source_SourcelessBadBytecodePEP302
=
util
.
test_both
(
SourcelessLoaderBadBytecodeTestPEP302
,
importlib
=
importlib
,
machinery
=
machinery
,
abc
=
importlib_abc
,
util
=
importlib_util
)
(
Frozen_SourcelessBadBytecodePEP302
,
Source_SourcelessBadBytecodePEP302
)
=
util
.
test_both
(
SourcelessLoaderBadBytecodeTestPEP302
,
importlib
=
importlib
,
machinery
=
machinery
,
abc
=
importlib_abc
,
util
=
importlib_util
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/source/test_finder.py
View file @
3497c0bf
...
...
@@ -195,8 +195,10 @@ class FinderTestsPEP451(FinderTests):
spec
=
finder
.
find_spec
(
name
)
return
spec
.
loader
if
spec
is
not
None
else
spec
Frozen_FinderTestsPEP451
,
Source_FinderTestsPEP451
=
util
.
test_both
(
FinderTestsPEP451
,
machinery
=
machinery
)
(
Frozen_FinderTestsPEP451
,
Source_FinderTestsPEP451
)
=
util
.
test_both
(
FinderTestsPEP451
,
machinery
=
machinery
)
class
FinderTestsPEP420
(
FinderTests
):
...
...
@@ -209,8 +211,10 @@ class FinderTestsPEP420(FinderTests):
loader_portions
=
finder
.
find_loader
(
name
)
return
loader_portions
[
0
]
if
loader_only
else
loader_portions
Frozen_FinderTestsPEP420
,
Source_FinderTestsPEP420
=
util
.
test_both
(
FinderTestsPEP420
,
machinery
=
machinery
)
(
Frozen_FinderTestsPEP420
,
Source_FinderTestsPEP420
)
=
util
.
test_both
(
FinderTestsPEP420
,
machinery
=
machinery
)
class
FinderTestsPEP302
(
FinderTests
):
...
...
@@ -222,9 +226,10 @@ class FinderTestsPEP302(FinderTests):
warnings
.
simplefilter
(
"ignore"
,
DeprecationWarning
)
return
finder
.
find_module
(
name
)
Frozen_FinderTestsPEP302
,
Source_FinderTestsPEP302
=
util
.
test_both
(
FinderTestsPEP302
,
machinery
=
machinery
)
(
Frozen_FinderTestsPEP302
,
Source_FinderTestsPEP302
)
=
util
.
test_both
(
FinderTestsPEP302
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/source/test_path_hook.py
View file @
3497c0bf
...
...
@@ -22,7 +22,10 @@ class PathHookTest:
# The empty string represents the cwd.
self
.
assertTrue
(
hasattr
(
self
.
path_hook
()(
''
),
'find_module'
))
Frozen_PathHookTest
,
Source_PathHooktest
=
util
.
test_both
(
PathHookTest
,
machinery
=
machinery
)
(
Frozen_PathHookTest
,
Source_PathHooktest
)
=
util
.
test_both
(
PathHookTest
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/source/test_source_encoding.py
View file @
3497c0bf
...
...
@@ -88,6 +88,7 @@ class EncodingTest:
with self.assertRaises(SyntaxError):
self.run_test(source)
class EncodingTestPEP451(EncodingTest):
def load(self, loader):
...
...
@@ -96,8 +97,11 @@ class EncodingTestPEP451(EncodingTest):
loader.exec_module(module)
return module
Frozen_EncodingTestPEP451, Source_EncodingTestPEP451 = util.test_both(
EncodingTestPEP451, machinery=machinery)
(Frozen_EncodingTestPEP451,
Source_EncodingTestPEP451
) = util.test_both(EncodingTestPEP451, machinery=machinery)
class EncodingTestPEP302(EncodingTest):
...
...
@@ -106,8 +110,10 @@ class EncodingTestPEP302(EncodingTest):
warnings.simplefilter('
ignore
', DeprecationWarning)
return loader.load_module(self.module_name)
Frozen_EncodingTestPEP302, Source_EncodingTestPEP302 = util.test_both(
EncodingTestPEP302, machinery=machinery)
(Frozen_EncodingTestPEP302,
Source_EncodingTestPEP302
) = util.test_both(EncodingTestPEP302, machinery=machinery)
class LineEndingTest:
...
...
@@ -138,6 +144,7 @@ class LineEndingTest:
def test_lf(self):
self.run_test(b'
\
n
')
class LineEndingTestPEP451(LineEndingTest):
def load(self, loader, module_name):
...
...
@@ -146,8 +153,11 @@ class LineEndingTestPEP451(LineEndingTest):
loader.exec_module(module)
return module
Frozen_LineEndingTestPEP451, Source_LineEndingTestPEP451 = util.test_both(
LineEndingTestPEP451, machinery=machinery)
(Frozen_LineEndingTestPEP451,
Source_LineEndingTestPEP451
) = util.test_both(LineEndingTestPEP451, machinery=machinery)
class LineEndingTestPEP302(LineEndingTest):
...
...
@@ -156,8 +166,10 @@ class LineEndingTestPEP302(LineEndingTest):
warnings.simplefilter('
ignore
', DeprecationWarning)
return loader.load_module(module_name)
Frozen_LineEndingTestPEP302, Source_LineEndingTestPEP302 = util.test_both(
LineEndingTestPEP302, machinery=machinery)
(Frozen_LineEndingTestPEP302,
Source_LineEndingTestPEP302
) = util.test_both(LineEndingTestPEP302, machinery=machinery)
if __name__ == '
__main__
':
...
...
Lib/test/test_importlib/test_abc.py
View file @
3497c0bf
This diff is collapsed.
Click to expand it.
Lib/test/test_importlib/test_api.py
View file @
3497c0bf
This diff is collapsed.
Click to expand it.
Lib/test/test_importlib/test_locks.py
View file @
3497c0bf
from
.
import
util
frozen_init
,
source_init
=
util
.
import_importlib
(
'importlib'
)
frozen_bootstrap
=
frozen_init
.
_bootstrap
source_bootstrap
=
source_init
.
_bootstrap
from
.
import
util
as
test_util
init
=
test_util
.
import_importlib
(
'importlib'
)
import
sys
import
time
...
...
@@ -33,13 +32,16 @@ if threading is not None:
# _release_save() unsupported
test_release_save_unacquired
=
None
class
Frozen_ModuleLockAsRLockTests
(
ModuleLockAsRLockTests
,
lock_tests
.
RLockTests
):
LockType
=
frozen_bootstrap
.
_ModuleLock
class
Source_ModuleLockAsRLockTests
(
ModuleLockAsRLockTests
,
lock_tests
.
RLockTests
):
LockType
=
source_bootstrap
.
_ModuleLock
LOCK_TYPES
=
{
kind
:
splitinit
.
_bootstrap
.
_ModuleLock
for
kind
,
splitinit
in
init
.
items
()}
(
Frozen_ModuleLockAsRLockTests
,
Source_ModuleLockAsRLockTests
)
=
test_util
.
test_both
(
ModuleLockAsRLockTests
,
lock_tests
.
RLockTests
,
LockType
=
LOCK_TYPES
)
else
:
LOCK_TYPES
=
{}
class
Frozen_ModuleLockAsRLockTests
(
unittest
.
TestCase
):
pass
...
...
@@ -47,6 +49,7 @@ else:
pass
@
unittest
.
skipUnless
(
threading
,
"threads needed for this test"
)
class
DeadlockAvoidanceTests
:
def
setUp
(
self
):
...
...
@@ -106,19 +109,22 @@ class DeadlockAvoidanceTests:
self
.
assertEqual
(
results
.
count
((
True
,
False
)),
0
)
self
.
assertEqual
(
results
.
count
((
True
,
True
)),
len
(
results
))
@
unittest
.
skipUnless
(
threading
,
"threads needed for this test"
)
class
Frozen_DeadlockAvoidanceTests
(
DeadlockAvoidanceTests
,
unittest
.
TestCase
):
LockType
=
frozen_bootstrap
.
_ModuleLock
DeadlockError
=
frozen_bootstrap
.
_DeadlockError
@
unittest
.
skipUnless
(
threading
,
"threads needed for this test"
)
class
Source_DeadlockAvoidanceTests
(
DeadlockAvoidanceTests
,
unittest
.
TestCase
):
LockType
=
source_bootstrap
.
_ModuleLock
DeadlockError
=
source_bootstrap
.
_DeadlockError
DEADLOCK_ERRORS
=
{
kind
:
splitinit
.
_bootstrap
.
_DeadlockError
for
kind
,
splitinit
in
init
.
items
()}
(
Frozen_DeadlockAvoidanceTests
,
Source_DeadlockAvoidanceTests
)
=
test_util
.
test_both
(
DeadlockAvoidanceTests
,
LockType
=
LOCK_TYPES
,
DeadlockError
=
DEADLOCK_ERRORS
)
class
LifetimeTests
:
@
property
def
bootstrap
(
self
):
return
self
.
init
.
_bootstrap
def
test_lock_lifetime
(
self
):
name
=
"xyzzy"
self
.
assertNotIn
(
name
,
self
.
bootstrap
.
_module_locks
)
...
...
@@ -135,11 +141,10 @@ class LifetimeTests:
self
.
assertEqual
(
0
,
len
(
self
.
bootstrap
.
_module_locks
),
self
.
bootstrap
.
_module_locks
)
class
Frozen_LifetimeTests
(
LifetimeTests
,
unittest
.
TestCase
):
bootstrap
=
frozen_bootstrap
class
Source_LifetimeTests
(
LifetimeTests
,
unittest
.
TestCase
):
bootstrap
=
source_bootstrap
(
Frozen_LifetimeTests
,
Source_LifetimeTests
)
=
test_util
.
test_both
(
LifetimeTests
,
init
=
init
)
@
support
.
reap_threads
...
...
Lib/test/test_importlib/test_spec.py
View file @
3497c0bf
from
.
import
util
from
.
import
util
as
test_util
frozen_init
,
source_init
=
util
.
import_importlib
(
'importlib'
)
frozen_bootstrap
=
frozen_init
.
_bootstrap
source_bootstrap
=
source_init
.
_bootstrap
frozen_machinery
,
source_machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
frozen_util
,
source_util
=
util
.
import_importlib
(
'importlib.util'
)
init
=
test_util
.
import_importlib
(
'importlib'
)
machinery
=
test_util
.
import_importlib
(
'importlib.machinery'
)
util
=
test_util
.
import_importlib
(
'importlib.util'
)
import
os.path
from
test.support
import
CleanImport
...
...
@@ -52,6 +50,8 @@ class LegacyLoader(TestLoader):
with
warnings
.
catch_warnings
():
warnings
.
simplefilter
(
"ignore"
,
DeprecationWarning
)
frozen_util
=
util
[
'Frozen'
]
@
frozen_util
.
module_for_loader
def
load_module
(
self
,
module
):
module
.
ham
=
self
.
HAM
...
...
@@ -221,18 +221,17 @@ class ModuleSpecTests:
self
.
assertEqual
(
self
.
loc_spec
.
cached
,
'spam.pyc'
)
class
Frozen_ModuleSpecTests
(
ModuleSpecTests
,
unittest
.
TestCase
):
util
=
frozen_util
machinery
=
frozen_machinery
class
Source_ModuleSpecTests
(
ModuleSpecTests
,
unittest
.
TestCase
):
util
=
source_util
machinery
=
source_machinery
(
Frozen_ModuleSpecTests
,
Source_ModuleSpecTests
)
=
test_util
.
test_both
(
ModuleSpecTests
,
util
=
util
,
machinery
=
machinery
)
class
ModuleSpecMethodsTests
:
@
property
def
bootstrap
(
self
):
return
self
.
init
.
_bootstrap
def
setUp
(
self
):
self
.
name
=
'spam'
self
.
path
=
'spam.py'
...
...
@@ -528,20 +527,18 @@ class ModuleSpecMethodsTests:
self
.
assertIs
(
installed
,
loaded
)
class
Frozen_ModuleSpecMethodsTests
(
ModuleSpecMethodsTests
,
unittest
.
TestCase
):
bootstrap
=
frozen_bootstrap
machinery
=
frozen_machinery
util
=
frozen_util
class
Source_ModuleSpecMethodsTests
(
ModuleSpecMethodsTests
,
unittest
.
TestCase
):
bootstrap
=
source_bootstrap
machinery
=
source_machinery
util
=
source_util
(
Frozen_ModuleSpecMethodsTests
,
Source_ModuleSpecMethodsTests
)
=
test_util
.
test_both
(
ModuleSpecMethodsTests
,
init
=
init
,
util
=
util
,
machinery
=
machinery
)
class
ModuleReprTests
:
@
property
def
bootstrap
(
self
):
return
self
.
init
.
_bootstrap
def
setUp
(
self
):
self
.
module
=
type
(
os
)(
'spam'
)
self
.
spec
=
self
.
machinery
.
ModuleSpec
(
'spam'
,
TestLoader
())
...
...
@@ -625,16 +622,10 @@ class ModuleReprTests:
self
.
assertEqual
(
modrepr
,
'<module {!r}>'
.
format
(
'spam'
))
class
Frozen_ModuleReprTests
(
ModuleReprTests
,
unittest
.
TestCase
):
bootstrap
=
frozen_bootstrap
machinery
=
frozen_machinery
util
=
frozen_util
class
Source_ModuleReprTests
(
ModuleReprTests
,
unittest
.
TestCase
):
bootstrap
=
source_bootstrap
machinery
=
source_machinery
util
=
source_util
(
Frozen_ModuleReprTests
,
Source_ModuleReprTests
)
=
test_util
.
test_both
(
ModuleReprTests
,
init
=
init
,
util
=
util
,
machinery
=
machinery
)
class
FactoryTests
:
...
...
@@ -787,7 +778,7 @@ class FactoryTests:
# spec_from_file_location()
def
test_spec_from_file_location_default
(
self
):
if
self
.
machinery
is
source_machinery
:
if
self
.
machinery
is
machinery
[
'Source'
]
:
raise
unittest
.
SkipTest
(
'not sure why this is breaking...'
)
spec
=
self
.
util
.
spec_from_file_location
(
self
.
name
,
self
.
path
)
...
...
@@ -947,11 +938,6 @@ class FactoryTests:
self
.
assertTrue
(
spec
.
has_location
)
class
Frozen_FactoryTests
(
FactoryTests
,
unittest
.
TestCase
):
util
=
frozen_util
machinery
=
frozen_machinery
class
Source_FactoryTests
(
FactoryTests
,
unittest
.
TestCase
):
util
=
source_util
machinery
=
source_machinery
(
Frozen_FactoryTests
,
Source_FactoryTests
)
=
test_util
.
test_both
(
FactoryTests
,
util
=
util
,
machinery
=
machinery
)
Lib/test/test_importlib/test_util.py
View file @
3497c0bf
from
importlib
import
util
import
importlib.
util
from
.
import
util
as
test_util
frozen_init
,
source_
init
=
test_util
.
import_importlib
(
'importlib'
)
frozen_machinery
,
source_
machinery
=
test_util
.
import_importlib
(
'importlib.machinery'
)
frozen_util
,
source_
util
=
test_util
.
import_importlib
(
'importlib.util'
)
init
=
test_util
.
import_importlib
(
'importlib'
)
machinery
=
test_util
.
import_importlib
(
'importlib.machinery'
)
util
=
test_util
.
import_importlib
(
'importlib.util'
)
import
os
import
sys
...
...
@@ -32,8 +32,10 @@ class DecodeSourceBytesTests:
self
.
assertEqual
(
self
.
util
.
decode_source
(
source_bytes
),
'
\
n
'
.
join
([
self
.
source
,
self
.
source
]))
Frozen_DecodeSourceBytesTests
,
Source_DecodeSourceBytesTests
=
test_util
.
test_both
(
DecodeSourceBytesTests
,
util
=
[
frozen_util
,
source_util
])
(
Frozen_DecodeSourceBytesTests
,
Source_DecodeSourceBytesTests
)
=
test_util
.
test_both
(
DecodeSourceBytesTests
,
util
=
util
)
class
ModuleForLoaderTests
:
...
...
@@ -161,8 +163,10 @@ class ModuleForLoaderTests:
self
.
assertIs
(
module
.
__loader__
,
loader
)
self
.
assertEqual
(
module
.
__package__
,
name
)
Frozen_ModuleForLoaderTests
,
Source_ModuleForLoaderTests
=
test_util
.
test_both
(
ModuleForLoaderTests
,
util
=
[
frozen_util
,
source_util
])
(
Frozen_ModuleForLoaderTests
,
Source_ModuleForLoaderTests
)
=
test_util
.
test_both
(
ModuleForLoaderTests
,
util
=
util
)
class
SetPackageTests
:
...
...
@@ -222,18 +226,25 @@ class SetPackageTests:
self
.
assertEqual
(
wrapped
.
__name__
,
fxn
.
__name__
)
self
.
assertEqual
(
wrapped
.
__qualname__
,
fxn
.
__qualname__
)
Frozen_SetPackageTests
,
Source_SetPackageTests
=
test_util
.
test_both
(
SetPackageTests
,
util
=
[
frozen_util
,
source_util
])
(
Frozen_SetPackageTests
,
Source_SetPackageTests
)
=
test_util
.
test_both
(
SetPackageTests
,
util
=
util
)
class
SetLoaderTests
:
"""Tests importlib.util.set_loader()."""
class
DummyLoader
:
@
util
.
set_loader
def
load_module
(
self
,
module
):
return
self
.
module
@
property
def
DummyLoader
(
self
):
# Set DummyLoader on the class lazily.
class
DummyLoader
:
@
self
.
util
.
set_loader
def
load_module
(
self
,
module
):
return
self
.
module
self
.
__class__
.
DummyLoader
=
DummyLoader
return
DummyLoader
def
test_no_attribute
(
self
):
loader
=
self
.
DummyLoader
()
...
...
@@ -262,17 +273,10 @@ class SetLoaderTests:
warnings
.
simplefilter
(
'ignore'
,
DeprecationWarning
)
self
.
assertEqual
(
42
,
loader
.
load_module
(
'blah'
).
__loader__
)
class
Frozen_SetLoaderTests
(
SetLoaderTests
,
unittest
.
TestCase
):
class
DummyLoader
:
@
frozen_util
.
set_loader
def
load_module
(
self
,
module
):
return
self
.
module
class
Source_SetLoaderTests
(
SetLoaderTests
,
unittest
.
TestCase
):
class
DummyLoader
:
@
source_util
.
set_loader
def
load_module
(
self
,
module
):
return
self
.
module
(
Frozen_SetLoaderTests
,
Source_SetLoaderTests
)
=
test_util
.
test_both
(
SetLoaderTests
,
util
=
util
)
class
ResolveNameTests
:
...
...
@@ -307,9 +311,10 @@ class ResolveNameTests:
with
self
.
assertRaises
(
ValueError
):
self
.
util
.
resolve_name
(
'..bacon'
,
'spam'
)
Frozen_ResolveNameTests
,
Source_ResolveNameTests
=
test_util
.
test_both
(
ResolveNameTests
,
util
=
[
frozen_util
,
source_util
])
(
Frozen_ResolveNameTests
,
Source_ResolveNameTests
)
=
test_util
.
test_both
(
ResolveNameTests
,
util
=
util
)
class
FindSpecTests
:
...
...
@@ -446,15 +451,10 @@ class FindSpecTests:
self
.
assertNotIn
(
fullname
,
sorted
(
sys
.
modules
))
class
Frozen_FindSpecTests
(
FindSpecTests
,
unittest
.
TestCase
):
init
=
frozen_init
machinery
=
frozen_machinery
util
=
frozen_util
class
Source_FindSpecTests
(
FindSpecTests
,
unittest
.
TestCase
):
init
=
source_init
machinery
=
source_machinery
util
=
source_util
(
Frozen_FindSpecTests
,
Source_FindSpecTests
)
=
test_util
.
test_both
(
FindSpecTests
,
init
=
init
,
util
=
util
,
machinery
=
machinery
)
class
MagicNumberTests
:
...
...
@@ -467,8 +467,10 @@ class MagicNumberTests:
# The magic number uses \r\n to come out wrong when splitting on lines.
self
.
assertTrue
(
self
.
util
.
MAGIC_NUMBER
.
endswith
(
b'
\
r
\
n
'
))
Frozen_MagicNumberTests
,
Source_MagicNumberTests
=
test_util
.
test_both
(
MagicNumberTests
,
util
=
[
frozen_util
,
source_util
])
(
Frozen_MagicNumberTests
,
Source_MagicNumberTests
)
=
test_util
.
test_both
(
MagicNumberTests
,
util
=
util
)
class
PEP3147Tests
:
...
...
@@ -583,9 +585,10 @@ class PEP3147Tests:
ValueError
,
self
.
util
.
source_from_cache
,
'/foo/bar/foo.cpython-32.foo.pyc'
)
Frozen_PEP3147Tests
,
Source_PEP3147Tests
=
test_util
.
test_both
(
PEP3147Tests
,
util
=
[
frozen_util
,
source_util
])
(
Frozen_PEP3147Tests
,
Source_PEP3147Tests
)
=
test_util
.
test_both
(
PEP3147Tests
,
util
=
util
)
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/test_windows.py
View file @
3497c0bf
from
.
import
util
frozen_machinery
,
source_machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
from
.
import
util
as
test_util
machinery
=
test_
util
.
import_importlib
(
'importlib.machinery'
)
import
sys
import
unittest
...
...
@@ -19,11 +19,6 @@ class WindowsRegistryFinderTests:
self
.
assertIs
(
loader
,
None
)
class
Frozen_WindowsRegistryFinderTests
(
WindowsRegistryFinderTests
,
unittest
.
TestCase
):
machinery
=
frozen_machinery
class
Source_WindowsRegistryFinderTests
(
WindowsRegistryFinderTests
,
unittest
.
TestCase
):
machinery
=
source_machinery
(
Frozen_WindowsRegistryFinderTests
,
Source_WindowsRegistryFinderTests
)
=
test_util
.
test_both
(
WindowsRegistryFinderTests
,
machinery
=
machinery
)
Lib/test/test_importlib/util.py
View file @
3497c0bf
...
...
@@ -50,19 +50,36 @@ def import_importlib(module_name):
frozen
=
support
.
import_fresh_module
(
module_name
)
source
=
support
.
import_fresh_module
(
module_name
,
fresh
=
fresh
,
blocked
=
(
'_frozen_importlib'
,))
return
{
'Frozen'
:
frozen
,
'Source'
:
source
}
def
specialize_class
(
cls
,
kind
,
base
=
None
,
**
kwargs
):
# XXX Support passing in submodule names--load (and cache) them?
# That would clean up the test modules a bit more.
if
base
is
None
:
base
=
unittest
.
TestCase
elif
not
isinstance
(
base
,
type
):
base
=
base
[
kind
]
name
=
'{}_{}'
.
format
(
kind
,
cls
.
__name__
)
bases
=
(
cls
,
base
)
specialized
=
types
.
new_class
(
name
,
bases
)
specialized
.
__module__
=
cls
.
__module__
specialized
.
_NAME
=
cls
.
__name__
specialized
.
_KIND
=
kind
for
attr
,
values
in
kwargs
.
items
():
value
=
values
[
kind
]
setattr
(
specialized
,
attr
,
value
)
return
specialized
def
split_frozen
(
cls
,
base
=
None
,
**
kwargs
):
frozen
=
specialize_class
(
cls
,
'Frozen'
,
base
,
**
kwargs
)
source
=
specialize_class
(
cls
,
'Source'
,
base
,
**
kwargs
)
return
frozen
,
source
def
test_both
(
test_class
,
**
kwargs
):
frozen_tests
=
types
.
new_class
(
'Frozen_'
+
test_class
.
__name__
,
(
test_class
,
unittest
.
TestCase
))
source_tests
=
types
.
new_class
(
'Source_'
+
test_class
.
__name__
,
(
test_class
,
unittest
.
TestCase
))
frozen_tests
.
__module__
=
source_tests
.
__module__
=
test_class
.
__module__
for
attr
,
(
frozen_value
,
source_value
)
in
kwargs
.
items
():
setattr
(
frozen_tests
,
attr
,
frozen_value
)
setattr
(
source_tests
,
attr
,
source_value
)
return
frozen_tests
,
source_tests
def
test_both
(
test_class
,
base
=
None
,
**
kwargs
):
return
split_frozen
(
test_class
,
base
,
**
kwargs
)
CASE_INSENSITIVE_FS
=
True
...
...
@@ -75,8 +92,9 @@ if sys.platform not in ('win32', 'cygwin'):
if
not
os
.
path
.
exists
(
changed_name
):
CASE_INSENSITIVE_FS
=
False
_
,
source_importlib
=
import_importlib
(
'importlib'
)
__import__
=
staticmethod
(
builtins
.
__import__
),
staticmethod
(
source_importlib
.
__import__
)
source_importlib
=
import_importlib
(
'importlib'
)[
'Source'
]
__import__
=
{
'Frozen'
:
staticmethod
(
builtins
.
__import__
),
'Source'
:
staticmethod
(
source_importlib
.
__import__
)}
def
case_insensitive_tests
(
test
):
...
...
Misc/NEWS
View file @
3497c0bf
...
...
@@ -496,6 +496,8 @@ Tests
-
Issue
#
21097
:
Move
test_namespace_pkgs
into
test_importlib
.
-
Issue
#
21503
:
Use
test_both
()
consistently
in
test_importlib
.
-
Issue
#
20939
:
Avoid
various
network
test
failures
due
to
new
redirect
of
http
://
www
.
python
.
org
/
to
https
://
www
.
python
.
org
:
use
http
://
www
.
example
.
com
instead
.
...
...
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