Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
faae3adb
Kaydet (Commit)
faae3adb
authored
Haz 27, 2012
tarafından
Eric V. Smith
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Changed importlib tests to use assertIs, assertIsInstance, etc., instead of just assertTrue.
üst
8d37ffa5
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
58 additions
and
58 deletions
+58
-58
test_finder.py
Lib/importlib/test/builtin/test_finder.py
+2
-2
test_loader.py
Lib/importlib/test/builtin/test_loader.py
+5
-5
test_finder.py
Lib/importlib/test/extension/test_finder.py
+1
-1
test_loader.py
Lib/importlib/test/extension/test_loader.py
+4
-4
test_finder.py
Lib/importlib/test/frozen/test_finder.py
+1
-1
test_loader.py
Lib/importlib/test/frozen/test_loader.py
+3
-3
test_caching.py
Lib/importlib/test/import_/test_caching.py
+2
-1
test_meta_path.py
Lib/importlib/test/import_/test_meta_path.py
+2
-2
test_packages.py
Lib/importlib/test/import_/test_packages.py
+11
-11
test_path.py
Lib/importlib/test/import_/test_path.py
+6
-6
test_abc_loader.py
Lib/importlib/test/source/test_abc_loader.py
+10
-11
test_file_loader.py
Lib/importlib/test/source/test_file_loader.py
+6
-6
test_finder.py
Lib/importlib/test/source/test_finder.py
+1
-1
test_util.py
Lib/importlib/test/test_util.py
+4
-4
No files found.
Lib/importlib/test/builtin/test_finder.py
Dosyayı görüntüle @
faae3adb
...
@@ -35,14 +35,14 @@ class FinderTests(abc.FinderTests):
...
@@ -35,14 +35,14 @@ class FinderTests(abc.FinderTests):
def
test_failure
(
self
):
def
test_failure
(
self
):
assert
'importlib'
not
in
sys
.
builtin_module_names
assert
'importlib'
not
in
sys
.
builtin_module_names
loader
=
machinery
.
BuiltinImporter
.
find_module
(
'importlib'
)
loader
=
machinery
.
BuiltinImporter
.
find_module
(
'importlib'
)
self
.
assert
True
(
loader
is
None
)
self
.
assert
Is
(
loader
,
None
)
def
test_ignore_path
(
self
):
def
test_ignore_path
(
self
):
# The value for 'path' should always trigger a failed import.
# The value for 'path' should always trigger a failed import.
with
util
.
uncache
(
builtin_util
.
NAME
):
with
util
.
uncache
(
builtin_util
.
NAME
):
loader
=
machinery
.
BuiltinImporter
.
find_module
(
builtin_util
.
NAME
,
loader
=
machinery
.
BuiltinImporter
.
find_module
(
builtin_util
.
NAME
,
[
'pkg'
])
[
'pkg'
])
self
.
assert
True
(
loader
is
None
)
self
.
assert
Is
(
loader
,
None
)
...
...
Lib/importlib/test/builtin/test_loader.py
Dosyayı görüntüle @
faae3adb
...
@@ -18,10 +18,10 @@ class LoaderTests(abc.LoaderTests):
...
@@ -18,10 +18,10 @@ class LoaderTests(abc.LoaderTests):
def
verify
(
self
,
module
):
def
verify
(
self
,
module
):
"""Verify that the module matches against what it should have."""
"""Verify that the module matches against what it should have."""
self
.
assert
True
(
isinstance
(
module
,
types
.
ModuleType
)
)
self
.
assert
IsInstance
(
module
,
types
.
ModuleType
)
for
attr
,
value
in
self
.
verification
.
items
():
for
attr
,
value
in
self
.
verification
.
items
():
self
.
assertEqual
(
getattr
(
module
,
attr
),
value
)
self
.
assertEqual
(
getattr
(
module
,
attr
),
value
)
self
.
assert
True
(
module
.
__name__
in
sys
.
modules
)
self
.
assert
In
(
module
.
__name__
,
sys
.
modules
)
load_module
=
staticmethod
(
lambda
name
:
load_module
=
staticmethod
(
lambda
name
:
machinery
.
BuiltinImporter
.
load_module
(
name
))
machinery
.
BuiltinImporter
.
load_module
(
name
))
...
@@ -49,7 +49,7 @@ class LoaderTests(abc.LoaderTests):
...
@@ -49,7 +49,7 @@ class LoaderTests(abc.LoaderTests):
with
util
.
uncache
(
builtin_util
.
NAME
):
with
util
.
uncache
(
builtin_util
.
NAME
):
module1
=
self
.
load_module
(
builtin_util
.
NAME
)
module1
=
self
.
load_module
(
builtin_util
.
NAME
)
module2
=
self
.
load_module
(
builtin_util
.
NAME
)
module2
=
self
.
load_module
(
builtin_util
.
NAME
)
self
.
assert
True
(
module1
is
module2
)
self
.
assert
Is
(
module1
,
module2
)
def
test_unloadable
(
self
):
def
test_unloadable
(
self
):
name
=
'dssdsdfff'
name
=
'dssdsdfff'
...
@@ -74,12 +74,12 @@ class InspectLoaderTests(unittest.TestCase):
...
@@ -74,12 +74,12 @@ class InspectLoaderTests(unittest.TestCase):
def
test_get_code
(
self
):
def
test_get_code
(
self
):
# There is no code object.
# There is no code object.
result
=
machinery
.
BuiltinImporter
.
get_code
(
builtin_util
.
NAME
)
result
=
machinery
.
BuiltinImporter
.
get_code
(
builtin_util
.
NAME
)
self
.
assert
True
(
result
is
None
)
self
.
assert
Is
(
result
,
None
)
def
test_get_source
(
self
):
def
test_get_source
(
self
):
# There is no source.
# There is no source.
result
=
machinery
.
BuiltinImporter
.
get_source
(
builtin_util
.
NAME
)
result
=
machinery
.
BuiltinImporter
.
get_source
(
builtin_util
.
NAME
)
self
.
assert
True
(
result
is
None
)
self
.
assert
Is
(
result
,
None
)
def
test_is_package
(
self
):
def
test_is_package
(
self
):
# Cannot be a package.
# Cannot be a package.
...
...
Lib/importlib/test/extension/test_finder.py
Dosyayı görüntüle @
faae3adb
...
@@ -36,7 +36,7 @@ class FinderTests(abc.FinderTests):
...
@@ -36,7 +36,7 @@ class FinderTests(abc.FinderTests):
pass
pass
def
test_failure
(
self
):
def
test_failure
(
self
):
self
.
assert
True
(
self
.
find_module
(
'asdfjkl;'
)
is
None
)
self
.
assert
Is
(
self
.
find_module
(
'asdfjkl;'
),
None
)
# XXX Raise an exception if someone tries to use the 'path' argument?
# XXX Raise an exception if someone tries to use the 'path' argument?
...
...
Lib/importlib/test/extension/test_loader.py
Dosyayı görüntüle @
faae3adb
...
@@ -33,9 +33,9 @@ class LoaderTests(abc.LoaderTests):
...
@@ -33,9 +33,9 @@ class LoaderTests(abc.LoaderTests):
(
'__file__'
,
ext_util
.
FILEPATH
),
(
'__file__'
,
ext_util
.
FILEPATH
),
(
'__package__'
,
''
)]:
(
'__package__'
,
''
)]:
self
.
assertEqual
(
getattr
(
module
,
attr
),
value
)
self
.
assertEqual
(
getattr
(
module
,
attr
),
value
)
self
.
assert
True
(
ext_util
.
NAME
in
sys
.
modules
)
self
.
assert
In
(
ext_util
.
NAME
,
sys
.
modules
)
self
.
assert
True
(
isi
nstance
(
module
.
__loader__
,
self
.
assert
IsI
nstance
(
module
.
__loader__
,
machinery
.
ExtensionFileLoader
)
)
machinery
.
ExtensionFileLoader
)
def
test_package
(
self
):
def
test_package
(
self
):
# Extensions are not found in packages.
# Extensions are not found in packages.
...
@@ -49,7 +49,7 @@ class LoaderTests(abc.LoaderTests):
...
@@ -49,7 +49,7 @@ class LoaderTests(abc.LoaderTests):
with
util
.
uncache
(
ext_util
.
NAME
):
with
util
.
uncache
(
ext_util
.
NAME
):
module1
=
self
.
load_module
(
ext_util
.
NAME
)
module1
=
self
.
load_module
(
ext_util
.
NAME
)
module2
=
self
.
load_module
(
ext_util
.
NAME
)
module2
=
self
.
load_module
(
ext_util
.
NAME
)
self
.
assert
True
(
module1
is
module2
)
self
.
assert
Is
(
module1
,
module2
)
def
test_state_after_failure
(
self
):
def
test_state_after_failure
(
self
):
# No easy way to trigger a failure after a successful import.
# No easy way to trigger a failure after a successful import.
...
...
Lib/importlib/test/frozen/test_finder.py
Dosyayı görüntüle @
faae3adb
...
@@ -35,7 +35,7 @@ class FinderTests(abc.FinderTests):
...
@@ -35,7 +35,7 @@ class FinderTests(abc.FinderTests):
def
test_failure
(
self
):
def
test_failure
(
self
):
loader
=
self
.
find
(
'<not real>'
)
loader
=
self
.
find
(
'<not real>'
)
self
.
assert
True
(
loader
is
None
)
self
.
assert
Is
(
loader
,
None
)
def
test_main
():
def
test_main
():
...
...
Lib/importlib/test/frozen/test_loader.py
Dosyayı görüntüle @
faae3adb
...
@@ -55,7 +55,7 @@ class LoaderTests(abc.LoaderTests):
...
@@ -55,7 +55,7 @@ class LoaderTests(abc.LoaderTests):
with
util
.
uncache
(
'__hello__'
),
captured_stdout
()
as
stdout
:
with
util
.
uncache
(
'__hello__'
),
captured_stdout
()
as
stdout
:
module1
=
machinery
.
FrozenImporter
.
load_module
(
'__hello__'
)
module1
=
machinery
.
FrozenImporter
.
load_module
(
'__hello__'
)
module2
=
machinery
.
FrozenImporter
.
load_module
(
'__hello__'
)
module2
=
machinery
.
FrozenImporter
.
load_module
(
'__hello__'
)
self
.
assert
True
(
module1
is
module2
)
self
.
assert
Is
(
module1
,
module2
)
self
.
assertEqual
(
stdout
.
getvalue
(),
self
.
assertEqual
(
stdout
.
getvalue
(),
'Hello world!
\n
Hello world!
\n
'
)
'Hello world!
\n
Hello world!
\n
'
)
...
@@ -93,7 +93,7 @@ class InspectLoaderTests(unittest.TestCase):
...
@@ -93,7 +93,7 @@ class InspectLoaderTests(unittest.TestCase):
def
test_get_source
(
self
):
def
test_get_source
(
self
):
# Should always return None.
# Should always return None.
result
=
machinery
.
FrozenImporter
.
get_source
(
'__hello__'
)
result
=
machinery
.
FrozenImporter
.
get_source
(
'__hello__'
)
self
.
assert
True
(
result
is
None
)
self
.
assert
Is
(
result
,
None
)
def
test_is_package
(
self
):
def
test_is_package
(
self
):
# Should be able to tell what is a package.
# Should be able to tell what is a package.
...
@@ -101,7 +101,7 @@ class InspectLoaderTests(unittest.TestCase):
...
@@ -101,7 +101,7 @@ class InspectLoaderTests(unittest.TestCase):
(
'__phello__.spam'
,
False
))
(
'__phello__.spam'
,
False
))
for
name
,
is_package
in
test_for
:
for
name
,
is_package
in
test_for
:
result
=
machinery
.
FrozenImporter
.
is_package
(
name
)
result
=
machinery
.
FrozenImporter
.
is_package
(
name
)
self
.
assert
True
(
bool
(
result
)
==
is_package
)
self
.
assert
Equal
(
bool
(
result
),
is_package
)
def
test_failure
(
self
):
def
test_failure
(
self
):
# Raise ImportError for modules that are not frozen.
# Raise ImportError for modules that are not frozen.
...
...
Lib/importlib/test/import_/test_caching.py
Dosyayı görüntüle @
faae3adb
...
@@ -65,7 +65,8 @@ class UseCache(unittest.TestCase):
...
@@ -65,7 +65,8 @@ class UseCache(unittest.TestCase):
with
util
.
import_state
(
meta_path
=
[
importer
]):
with
util
.
import_state
(
meta_path
=
[
importer
]):
module
=
import_util
.
import_
(
'pkg.module'
)
module
=
import_util
.
import_
(
'pkg.module'
)
self
.
assertTrue
(
hasattr
(
module
,
'module'
))
self
.
assertTrue
(
hasattr
(
module
,
'module'
))
self
.
assertTrue
(
id
(
module
.
module
),
id
(
sys
.
modules
[
'pkg.module'
]))
self
.
assertEqual
(
id
(
module
.
module
),
id
(
sys
.
modules
[
'pkg.module'
]))
# See test_using_cache_after_loader() for reasoning.
# See test_using_cache_after_loader() for reasoning.
@import_util.importlib_only
@import_util.importlib_only
...
...
Lib/importlib/test/import_/test_meta_path.py
Dosyayı görüntüle @
faae3adb
...
@@ -82,7 +82,7 @@ class CallSignature(unittest.TestCase):
...
@@ -82,7 +82,7 @@ class CallSignature(unittest.TestCase):
self
.
assertEqual
(
len
(
args
),
2
)
self
.
assertEqual
(
len
(
args
),
2
)
self
.
assertEqual
(
len
(
kwargs
),
0
)
self
.
assertEqual
(
len
(
kwargs
),
0
)
self
.
assertEqual
(
args
[
0
],
mod_name
)
self
.
assertEqual
(
args
[
0
],
mod_name
)
self
.
assert
True
(
args
[
1
]
is
None
)
self
.
assert
Is
(
args
[
1
],
None
)
def
test_with_path
(
self
):
def
test_with_path
(
self
):
# [path set]
# [path set]
...
@@ -102,7 +102,7 @@ class CallSignature(unittest.TestCase):
...
@@ -102,7 +102,7 @@ class CallSignature(unittest.TestCase):
# Assuming all arguments are positional.
# Assuming all arguments are positional.
self
.
assertTrue
(
not
kwargs
)
self
.
assertTrue
(
not
kwargs
)
self
.
assertEqual
(
args
[
0
],
mod_name
)
self
.
assertEqual
(
args
[
0
],
mod_name
)
self
.
assert
True
(
args
[
1
]
is
path
)
self
.
assert
Is
(
args
[
1
],
path
)
...
...
Lib/importlib/test/import_/test_packages.py
Dosyayı görüntüle @
faae3adb
...
@@ -14,7 +14,7 @@ class ParentModuleTests(unittest.TestCase):
...
@@ -14,7 +14,7 @@ class ParentModuleTests(unittest.TestCase):
with
util
.
mock_modules
(
'pkg.__init__'
,
'pkg.module'
)
as
mock
:
with
util
.
mock_modules
(
'pkg.__init__'
,
'pkg.module'
)
as
mock
:
with
util
.
import_state
(
meta_path
=
[
mock
]):
with
util
.
import_state
(
meta_path
=
[
mock
]):
module
=
import_util
.
import_
(
'pkg.module'
)
module
=
import_util
.
import_
(
'pkg.module'
)
self
.
assert
True
(
'pkg'
in
sys
.
modules
)
self
.
assert
In
(
'pkg'
,
sys
.
modules
)
def
test_bad_parent
(
self
):
def
test_bad_parent
(
self
):
with
util
.
mock_modules
(
'pkg.module'
)
as
mock
:
with
util
.
mock_modules
(
'pkg.module'
)
as
mock
:
...
@@ -33,12 +33,12 @@ class ParentModuleTests(unittest.TestCase):
...
@@ -33,12 +33,12 @@ class ParentModuleTests(unittest.TestCase):
with
util
.
import_state
(
meta_path
=
[
mock
]):
with
util
.
import_state
(
meta_path
=
[
mock
]):
with
self
.
assertRaises
(
ZeroDivisionError
):
with
self
.
assertRaises
(
ZeroDivisionError
):
import_util
.
import_
(
'pkg'
)
import_util
.
import_
(
'pkg'
)
self
.
assert
False
(
'pkg'
in
sys
.
modules
)
self
.
assert
NotIn
(
'pkg'
,
sys
.
modules
)
self
.
assert
True
(
'pkg.module'
in
sys
.
modules
)
self
.
assert
In
(
'pkg.module'
,
sys
.
modules
)
with
self
.
assertRaises
(
ZeroDivisionError
):
with
self
.
assertRaises
(
ZeroDivisionError
):
import_util
.
import_
(
'pkg.module'
)
import_util
.
import_
(
'pkg.module'
)
self
.
assert
False
(
'pkg'
in
sys
.
modules
)
self
.
assert
NotIn
(
'pkg'
,
sys
.
modules
)
self
.
assert
True
(
'pkg.module'
in
sys
.
modules
)
self
.
assert
In
(
'pkg.module'
,
sys
.
modules
)
def
test_raising_parent_after_relative_importing_child
(
self
):
def
test_raising_parent_after_relative_importing_child
(
self
):
def
__init__
():
def
__init__
():
...
@@ -52,12 +52,12 @@ class ParentModuleTests(unittest.TestCase):
...
@@ -52,12 +52,12 @@ class ParentModuleTests(unittest.TestCase):
# This raises ImportError on the "from . import module"
# This raises ImportError on the "from . import module"
# line, not sure why.
# line, not sure why.
import_util
.
import_
(
'pkg'
)
import_util
.
import_
(
'pkg'
)
self
.
assert
False
(
'pkg'
in
sys
.
modules
)
self
.
assert
NotIn
(
'pkg'
,
sys
.
modules
)
with
self
.
assertRaises
((
ZeroDivisionError
,
ImportError
)):
with
self
.
assertRaises
((
ZeroDivisionError
,
ImportError
)):
import_util
.
import_
(
'pkg.module'
)
import_util
.
import_
(
'pkg.module'
)
self
.
assert
False
(
'pkg'
in
sys
.
modules
)
self
.
assert
NotIn
(
'pkg'
,
sys
.
modules
)
# XXX False
# XXX False
#self.assert
True('pkg.module' in
sys.modules)
#self.assert
In('pkg.module',
sys.modules)
def
test_raising_parent_after_double_relative_importing_child
(
self
):
def
test_raising_parent_after_double_relative_importing_child
(
self
):
def
__init__
():
def
__init__
():
...
@@ -72,12 +72,12 @@ class ParentModuleTests(unittest.TestCase):
...
@@ -72,12 +72,12 @@ class ParentModuleTests(unittest.TestCase):
# This raises ImportError on the "from ..subpkg import module"
# This raises ImportError on the "from ..subpkg import module"
# line, not sure why.
# line, not sure why.
import_util
.
import_
(
'pkg.subpkg'
)
import_util
.
import_
(
'pkg.subpkg'
)
self
.
assert
False
(
'pkg.subpkg'
in
sys
.
modules
)
self
.
assert
NotIn
(
'pkg.subpkg'
,
sys
.
modules
)
with
self
.
assertRaises
((
ZeroDivisionError
,
ImportError
)):
with
self
.
assertRaises
((
ZeroDivisionError
,
ImportError
)):
import_util
.
import_
(
'pkg.subpkg.module'
)
import_util
.
import_
(
'pkg.subpkg.module'
)
self
.
assert
False
(
'pkg.subpkg'
in
sys
.
modules
)
self
.
assert
NotIn
(
'pkg.subpkg'
,
sys
.
modules
)
# XXX False
# XXX False
#self.assert
True('pkg.subpkg.module' in
sys.modules)
#self.assert
In('pkg.subpkg.module',
sys.modules)
def
test_module_not_package
(
self
):
def
test_module_not_package
(
self
):
# Try to import a submodule from a non-package should raise ImportError.
# Try to import a submodule from a non-package should raise ImportError.
...
...
Lib/importlib/test/import_/test_path.py
Dosyayı görüntüle @
faae3adb
...
@@ -20,7 +20,7 @@ class FinderTests(unittest.TestCase):
...
@@ -20,7 +20,7 @@ class FinderTests(unittest.TestCase):
# Test None returned upon not finding a suitable finder.
# Test None returned upon not finding a suitable finder.
module
=
'<test module>'
module
=
'<test module>'
with
util
.
import_state
():
with
util
.
import_state
():
self
.
assert
True
(
machinery
.
PathFinder
.
find_module
(
module
)
is
None
)
self
.
assert
Is
(
machinery
.
PathFinder
.
find_module
(
module
),
None
)
def
test_sys_path
(
self
):
def
test_sys_path
(
self
):
# Test that sys.path is used when 'path' is None.
# Test that sys.path is used when 'path' is None.
...
@@ -31,7 +31,7 @@ class FinderTests(unittest.TestCase):
...
@@ -31,7 +31,7 @@ class FinderTests(unittest.TestCase):
with
util
.
import_state
(
path_importer_cache
=
{
path
:
importer
},
with
util
.
import_state
(
path_importer_cache
=
{
path
:
importer
},
path
=
[
path
]):
path
=
[
path
]):
loader
=
machinery
.
PathFinder
.
find_module
(
module
)
loader
=
machinery
.
PathFinder
.
find_module
(
module
)
self
.
assert
True
(
loader
is
importer
)
self
.
assert
Is
(
loader
,
importer
)
def
test_path
(
self
):
def
test_path
(
self
):
# Test that 'path' is used when set.
# Test that 'path' is used when set.
...
@@ -41,7 +41,7 @@ class FinderTests(unittest.TestCase):
...
@@ -41,7 +41,7 @@ class FinderTests(unittest.TestCase):
importer
=
util
.
mock_modules
(
module
)
importer
=
util
.
mock_modules
(
module
)
with
util
.
import_state
(
path_importer_cache
=
{
path
:
importer
}):
with
util
.
import_state
(
path_importer_cache
=
{
path
:
importer
}):
loader
=
machinery
.
PathFinder
.
find_module
(
module
,
[
path
])
loader
=
machinery
.
PathFinder
.
find_module
(
module
,
[
path
])
self
.
assert
True
(
loader
is
importer
)
self
.
assert
Is
(
loader
,
importer
)
def
test_empty_list
(
self
):
def
test_empty_list
(
self
):
# An empty list should not count as asking for sys.path.
# An empty list should not count as asking for sys.path.
...
@@ -61,9 +61,9 @@ class FinderTests(unittest.TestCase):
...
@@ -61,9 +61,9 @@ class FinderTests(unittest.TestCase):
hook
=
import_util
.
mock_path_hook
(
path
,
importer
=
importer
)
hook
=
import_util
.
mock_path_hook
(
path
,
importer
=
importer
)
with
util
.
import_state
(
path_hooks
=
[
hook
]):
with
util
.
import_state
(
path_hooks
=
[
hook
]):
loader
=
machinery
.
PathFinder
.
find_module
(
module
,
[
path
])
loader
=
machinery
.
PathFinder
.
find_module
(
module
,
[
path
])
self
.
assert
True
(
loader
is
importer
)
self
.
assert
Is
(
loader
,
importer
)
self
.
assert
True
(
path
in
sys
.
path_importer_cache
)
self
.
assert
In
(
path
,
sys
.
path_importer_cache
)
self
.
assert
True
(
sys
.
path_importer_cache
[
path
]
is
importer
)
self
.
assert
Is
(
sys
.
path_importer_cache
[
path
],
importer
)
def
test_empty_path_hooks
(
self
):
def
test_empty_path_hooks
(
self
):
# Test that if sys.path_hooks is empty a warning is raised,
# Test that if sys.path_hooks is empty a warning is raised,
...
...
Lib/importlib/test/source/test_abc_loader.py
Dosyayı görüntüle @
faae3adb
...
@@ -221,7 +221,7 @@ class PyLoaderTests(testing_abc.LoaderTests):
...
@@ -221,7 +221,7 @@ class PyLoaderTests(testing_abc.LoaderTests):
mock
=
self
.
mocker
({
name
:
path
})
mock
=
self
.
mocker
({
name
:
path
})
with
util
.
uncache
(
name
):
with
util
.
uncache
(
name
):
module
=
mock
.
load_module
(
name
)
module
=
mock
.
load_module
(
name
)
self
.
assert
True
(
name
in
sys
.
modules
)
self
.
assert
In
(
name
,
sys
.
modules
)
self
.
eq_attrs
(
module
,
__name__
=
name
,
__file__
=
path
,
__package__
=
''
,
self
.
eq_attrs
(
module
,
__name__
=
name
,
__file__
=
path
,
__package__
=
''
,
__loader__
=
mock
)
__loader__
=
mock
)
self
.
assertTrue
(
not
hasattr
(
module
,
'__path__'
))
self
.
assertTrue
(
not
hasattr
(
module
,
'__path__'
))
...
@@ -233,7 +233,7 @@ class PyLoaderTests(testing_abc.LoaderTests):
...
@@ -233,7 +233,7 @@ class PyLoaderTests(testing_abc.LoaderTests):
mock
=
self
.
mocker
({
name
:
path
})
mock
=
self
.
mocker
({
name
:
path
})
with
util
.
uncache
(
name
):
with
util
.
uncache
(
name
):
module
=
mock
.
load_module
(
name
)
module
=
mock
.
load_module
(
name
)
self
.
assert
True
(
name
in
sys
.
modules
)
self
.
assert
In
(
name
,
sys
.
modules
)
self
.
eq_attrs
(
module
,
__name__
=
name
,
__file__
=
path
,
self
.
eq_attrs
(
module
,
__name__
=
name
,
__file__
=
path
,
__path__
=
[
os
.
path
.
dirname
(
path
)],
__package__
=
name
,
__path__
=
[
os
.
path
.
dirname
(
path
)],
__package__
=
name
,
__loader__
=
mock
)
__loader__
=
mock
)
...
@@ -259,8 +259,8 @@ class PyLoaderTests(testing_abc.LoaderTests):
...
@@ -259,8 +259,8 @@ class PyLoaderTests(testing_abc.LoaderTests):
with
util
.
uncache
(
name
):
with
util
.
uncache
(
name
):
sys
.
modules
[
name
]
=
module
sys
.
modules
[
name
]
=
module
loaded_module
=
mock
.
load_module
(
name
)
loaded_module
=
mock
.
load_module
(
name
)
self
.
assert
True
(
loaded_module
is
module
)
self
.
assert
Is
(
loaded_module
,
module
)
self
.
assert
True
(
sys
.
modules
[
name
]
is
module
)
self
.
assert
Is
(
sys
.
modules
[
name
],
module
)
return
mock
,
name
return
mock
,
name
def
test_state_after_failure
(
self
):
def
test_state_after_failure
(
self
):
...
@@ -273,7 +273,7 @@ class PyLoaderTests(testing_abc.LoaderTests):
...
@@ -273,7 +273,7 @@ class PyLoaderTests(testing_abc.LoaderTests):
sys
.
modules
[
name
]
=
module
sys
.
modules
[
name
]
=
module
with
self
.
assertRaises
(
ZeroDivisionError
):
with
self
.
assertRaises
(
ZeroDivisionError
):
mock
.
load_module
(
name
)
mock
.
load_module
(
name
)
self
.
assert
True
(
sys
.
modules
[
name
]
is
module
)
self
.
assert
Is
(
sys
.
modules
[
name
],
module
)
self
.
assertTrue
(
hasattr
(
module
,
'blah'
))
self
.
assertTrue
(
hasattr
(
module
,
'blah'
))
return
mock
return
mock
...
@@ -284,7 +284,7 @@ class PyLoaderTests(testing_abc.LoaderTests):
...
@@ -284,7 +284,7 @@ class PyLoaderTests(testing_abc.LoaderTests):
with
util
.
uncache
(
name
):
with
util
.
uncache
(
name
):
with
self
.
assertRaises
(
ZeroDivisionError
):
with
self
.
assertRaises
(
ZeroDivisionError
):
mock
.
load_module
(
name
)
mock
.
load_module
(
name
)
self
.
assert
True
(
name
not
in
sys
.
modules
)
self
.
assert
NotIn
(
name
,
sys
.
modules
)
return
mock
return
mock
...
@@ -414,8 +414,7 @@ class SkipWritingBytecodeTests(unittest.TestCase):
...
@@ -414,8 +414,7 @@ class SkipWritingBytecodeTests(unittest.TestCase):
sys
.
dont_write_bytecode
=
dont_write_bytecode
sys
.
dont_write_bytecode
=
dont_write_bytecode
with
util
.
uncache
(
name
):
with
util
.
uncache
(
name
):
mock
.
load_module
(
name
)
mock
.
load_module
(
name
)
self
.
assertTrue
((
name
in
mock
.
module_bytecode
)
is
not
self
.
assertIsNot
(
name
in
mock
.
module_bytecode
,
dont_write_bytecode
)
dont_write_bytecode
)
def
test_no_bytecode_written
(
self
):
def
test_no_bytecode_written
(
self
):
self
.
run_test
(
True
)
self
.
run_test
(
True
)
...
@@ -440,7 +439,7 @@ class RegeneratedBytecodeTests(unittest.TestCase):
...
@@ -440,7 +439,7 @@ class RegeneratedBytecodeTests(unittest.TestCase):
'magic'
:
bad_magic
}})
'magic'
:
bad_magic
}})
with
util
.
uncache
(
name
):
with
util
.
uncache
(
name
):
mock
.
load_module
(
name
)
mock
.
load_module
(
name
)
self
.
assert
True
(
name
in
mock
.
module_bytecode
)
self
.
assert
In
(
name
,
mock
.
module_bytecode
)
magic
=
mock
.
module_bytecode
[
name
][:
4
]
magic
=
mock
.
module_bytecode
[
name
][:
4
]
self
.
assertEqual
(
magic
,
imp
.
get_magic
())
self
.
assertEqual
(
magic
,
imp
.
get_magic
())
...
@@ -453,7 +452,7 @@ class RegeneratedBytecodeTests(unittest.TestCase):
...
@@ -453,7 +452,7 @@ class RegeneratedBytecodeTests(unittest.TestCase):
{
name
:
{
'path'
:
'path/to/mod.bytecode'
,
'mtime'
:
old_mtime
}})
{
name
:
{
'path'
:
'path/to/mod.bytecode'
,
'mtime'
:
old_mtime
}})
with
util
.
uncache
(
name
):
with
util
.
uncache
(
name
):
mock
.
load_module
(
name
)
mock
.
load_module
(
name
)
self
.
assert
True
(
name
in
mock
.
module_bytecode
)
self
.
assert
In
(
name
,
mock
.
module_bytecode
)
mtime
=
importlib
.
_r_long
(
mock
.
module_bytecode
[
name
][
4
:
8
])
mtime
=
importlib
.
_r_long
(
mock
.
module_bytecode
[
name
][
4
:
8
])
self
.
assertEqual
(
mtime
,
PyPycLoaderMock
.
default_mtime
)
self
.
assertEqual
(
mtime
,
PyPycLoaderMock
.
default_mtime
)
...
@@ -621,7 +620,7 @@ class SourceOnlyLoaderTests(SourceLoaderTestHarness):
...
@@ -621,7 +620,7 @@ class SourceOnlyLoaderTests(SourceLoaderTestHarness):
module
=
self
.
loader
.
load_module
(
self
.
name
)
module
=
self
.
loader
.
load_module
(
self
.
name
)
self
.
verify_module
(
module
)
self
.
verify_module
(
module
)
self
.
assertEqual
(
module
.
__path__
,
[
os
.
path
.
dirname
(
self
.
path
)])
self
.
assertEqual
(
module
.
__path__
,
[
os
.
path
.
dirname
(
self
.
path
)])
self
.
assert
True
(
self
.
name
in
sys
.
modules
)
self
.
assert
In
(
self
.
name
,
sys
.
modules
)
def
test_package_settings
(
self
):
def
test_package_settings
(
self
):
# __package__ needs to be set, while __path__ is set on if the module
# __package__ needs to be set, while __path__ is set on if the module
...
...
Lib/importlib/test/source/test_file_loader.py
Dosyayı görüntüle @
faae3adb
...
@@ -64,7 +64,7 @@ class SimpleTest(unittest.TestCase):
...
@@ -64,7 +64,7 @@ class SimpleTest(unittest.TestCase):
with
source_util
.
create_modules
(
'_temp'
)
as
mapping
:
with
source_util
.
create_modules
(
'_temp'
)
as
mapping
:
loader
=
_bootstrap
.
SourceFileLoader
(
'_temp'
,
mapping
[
'_temp'
])
loader
=
_bootstrap
.
SourceFileLoader
(
'_temp'
,
mapping
[
'_temp'
])
module
=
loader
.
load_module
(
'_temp'
)
module
=
loader
.
load_module
(
'_temp'
)
self
.
assert
True
(
'_temp'
in
sys
.
modules
)
self
.
assert
In
(
'_temp'
,
sys
.
modules
)
check
=
{
'__name__'
:
'_temp'
,
'__file__'
:
mapping
[
'_temp'
],
check
=
{
'__name__'
:
'_temp'
,
'__file__'
:
mapping
[
'_temp'
],
'__package__'
:
''
}
'__package__'
:
''
}
for
attr
,
value
in
check
.
items
():
for
attr
,
value
in
check
.
items
():
...
@@ -75,7 +75,7 @@ class SimpleTest(unittest.TestCase):
...
@@ -75,7 +75,7 @@ class SimpleTest(unittest.TestCase):
loader
=
_bootstrap
.
SourceFileLoader
(
'_pkg'
,
loader
=
_bootstrap
.
SourceFileLoader
(
'_pkg'
,
mapping
[
'_pkg.__init__'
])
mapping
[
'_pkg.__init__'
])
module
=
loader
.
load_module
(
'_pkg'
)
module
=
loader
.
load_module
(
'_pkg'
)
self
.
assert
True
(
'_pkg'
in
sys
.
modules
)
self
.
assert
In
(
'_pkg'
,
sys
.
modules
)
check
=
{
'__name__'
:
'_pkg'
,
'__file__'
:
mapping
[
'_pkg.__init__'
],
check
=
{
'__name__'
:
'_pkg'
,
'__file__'
:
mapping
[
'_pkg.__init__'
],
'__path__'
:
[
os
.
path
.
dirname
(
mapping
[
'_pkg.__init__'
])],
'__path__'
:
[
os
.
path
.
dirname
(
mapping
[
'_pkg.__init__'
])],
'__package__'
:
'_pkg'
}
'__package__'
:
'_pkg'
}
...
@@ -88,7 +88,7 @@ class SimpleTest(unittest.TestCase):
...
@@ -88,7 +88,7 @@ class SimpleTest(unittest.TestCase):
loader
=
_bootstrap
.
SourceFileLoader
(
'_pkg.mod'
,
loader
=
_bootstrap
.
SourceFileLoader
(
'_pkg.mod'
,
mapping
[
'_pkg.mod'
])
mapping
[
'_pkg.mod'
])
module
=
loader
.
load_module
(
'_pkg.mod'
)
module
=
loader
.
load_module
(
'_pkg.mod'
)
self
.
assert
True
(
'_pkg.mod'
in
sys
.
modules
)
self
.
assert
In
(
'_pkg.mod'
,
sys
.
modules
)
check
=
{
'__name__'
:
'_pkg.mod'
,
'__file__'
:
mapping
[
'_pkg.mod'
],
check
=
{
'__name__'
:
'_pkg.mod'
,
'__file__'
:
mapping
[
'_pkg.mod'
],
'__package__'
:
'_pkg'
}
'__package__'
:
'_pkg'
}
for
attr
,
value
in
check
.
items
():
for
attr
,
value
in
check
.
items
():
...
@@ -107,7 +107,7 @@ class SimpleTest(unittest.TestCase):
...
@@ -107,7 +107,7 @@ class SimpleTest(unittest.TestCase):
with
open
(
mapping
[
'_temp'
],
'w'
)
as
file
:
with
open
(
mapping
[
'_temp'
],
'w'
)
as
file
:
file
.
write
(
"testing_var = 42
\n
"
)
file
.
write
(
"testing_var = 42
\n
"
)
module
=
loader
.
load_module
(
'_temp'
)
module
=
loader
.
load_module
(
'_temp'
)
self
.
assert
True
(
'testing_var'
in
module
.
__dict__
,
self
.
assert
In
(
'testing_var'
,
module
.
__dict__
,
"'testing_var' not in "
"'testing_var' not in "
"{0}"
.
format
(
list
(
module
.
__dict__
.
keys
())))
"{0}"
.
format
(
list
(
module
.
__dict__
.
keys
())))
self
.
assertEqual
(
module
,
sys
.
modules
[
'_temp'
])
self
.
assertEqual
(
module
,
sys
.
modules
[
'_temp'
])
...
@@ -139,7 +139,7 @@ class SimpleTest(unittest.TestCase):
...
@@ -139,7 +139,7 @@ class SimpleTest(unittest.TestCase):
loader
=
_bootstrap
.
SourceFileLoader
(
'_temp'
,
mapping
[
'_temp'
])
loader
=
_bootstrap
.
SourceFileLoader
(
'_temp'
,
mapping
[
'_temp'
])
with
self
.
assertRaises
(
SyntaxError
):
with
self
.
assertRaises
(
SyntaxError
):
loader
.
load_module
(
'_temp'
)
loader
.
load_module
(
'_temp'
)
self
.
assert
True
(
'_temp'
not
in
sys
.
modules
)
self
.
assert
NotIn
(
'_temp'
,
sys
.
modules
)
def
test_file_from_empty_string_dir
(
self
):
def
test_file_from_empty_string_dir
(
self
):
# Loading a module found from an empty string entry on sys.path should
# Loading a module found from an empty string entry on sys.path should
...
@@ -189,7 +189,7 @@ class BadBytecodeTest(unittest.TestCase):
...
@@ -189,7 +189,7 @@ class BadBytecodeTest(unittest.TestCase):
def
import_
(
self
,
file
,
module_name
):
def
import_
(
self
,
file
,
module_name
):
loader
=
self
.
loader
(
module_name
,
file
)
loader
=
self
.
loader
(
module_name
,
file
)
module
=
loader
.
load_module
(
module_name
)
module
=
loader
.
load_module
(
module_name
)
self
.
assert
True
(
module_name
in
sys
.
modules
)
self
.
assert
In
(
module_name
,
sys
.
modules
)
def
manipulate_bytecode
(
self
,
name
,
mapping
,
manipulator
,
*
,
def
manipulate_bytecode
(
self
,
name
,
mapping
,
manipulator
,
*
,
del_source
=
False
):
del_source
=
False
):
...
...
Lib/importlib/test/source/test_finder.py
Dosyayı görüntüle @
faae3adb
...
@@ -115,7 +115,7 @@ class FinderTests(abc.FinderTests):
...
@@ -115,7 +115,7 @@ class FinderTests(abc.FinderTests):
def
test_failure
(
self
):
def
test_failure
(
self
):
with
source_util
.
create_modules
(
'blah'
)
as
mapping
:
with
source_util
.
create_modules
(
'blah'
)
as
mapping
:
nothing
=
self
.
import_
(
mapping
[
'.root'
],
'sdfsadsadf'
)
nothing
=
self
.
import_
(
mapping
[
'.root'
],
'sdfsadsadf'
)
self
.
assert
True
(
nothing
is
None
)
self
.
assert
Is
(
nothing
,
None
)
def
test_empty_string_for_dir
(
self
):
def
test_empty_string_for_dir
(
self
):
# The empty string from sys.path means to search in the cwd.
# The empty string from sys.path means to search in the cwd.
...
...
Lib/importlib/test/test_util.py
Dosyayı görüntüle @
faae3adb
...
@@ -29,8 +29,8 @@ class ModuleForLoaderTests(unittest.TestCase):
...
@@ -29,8 +29,8 @@ class ModuleForLoaderTests(unittest.TestCase):
module_name
=
'a.b.c'
module_name
=
'a.b.c'
with
test_util
.
uncache
(
module_name
):
with
test_util
.
uncache
(
module_name
):
module
=
self
.
return_module
(
module_name
)
module
=
self
.
return_module
(
module_name
)
self
.
assert
True
(
module_name
in
sys
.
modules
)
self
.
assert
In
(
module_name
,
sys
.
modules
)
self
.
assert
True
(
isinstance
(
module
,
types
.
ModuleType
)
)
self
.
assert
IsInstance
(
module
,
types
.
ModuleType
)
self
.
assertEqual
(
module
.
__name__
,
module_name
)
self
.
assertEqual
(
module
.
__name__
,
module_name
)
def
test_reload
(
self
):
def
test_reload
(
self
):
...
@@ -48,7 +48,7 @@ class ModuleForLoaderTests(unittest.TestCase):
...
@@ -48,7 +48,7 @@ class ModuleForLoaderTests(unittest.TestCase):
name
=
'a.b.c'
name
=
'a.b.c'
with
test_util
.
uncache
(
name
):
with
test_util
.
uncache
(
name
):
self
.
raise_exception
(
name
)
self
.
raise_exception
(
name
)
self
.
assert
True
(
name
not
in
sys
.
modules
)
self
.
assert
NotIn
(
name
,
sys
.
modules
)
def
test_reload_failure
(
self
):
def
test_reload_failure
(
self
):
# Test that a failure on reload leaves the module in-place.
# Test that a failure on reload leaves the module in-place.
...
@@ -77,7 +77,7 @@ class ModuleForLoaderTests(unittest.TestCase):
...
@@ -77,7 +77,7 @@ class ModuleForLoaderTests(unittest.TestCase):
self
.
assertFalse
(
module
)
self
.
assertFalse
(
module
)
sys
.
modules
[
name
]
=
module
sys
.
modules
[
name
]
=
module
given
=
self
.
return_module
(
name
)
given
=
self
.
return_module
(
name
)
self
.
assert
True
(
given
is
module
)
self
.
assert
Is
(
given
,
module
)
def
test_attributes_set
(
self
):
def
test_attributes_set
(
self
):
# __name__, __loader__, and __package__ should be set (when
# __name__, __loader__, and __package__ should be set (when
...
...
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