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
ffd33c29
Kaydet (Commit)
ffd33c29
authored
Eki 25, 2013
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #16803: Have test.test_importlib.builtin test both frozen and
source importlib.
üst
b3d6afff
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
26 deletions
+33
-26
test_finder.py
Lib/test/test_importlib/builtin/test_finder.py
+9
-5
test_loader.py
Lib/test/test_importlib/builtin/test_loader.py
+24
-21
No files found.
Lib/test/test_importlib/builtin/test_finder.py
Dosyayı görüntüle @
ffd33c29
from
importlib
import
machinery
from
..
import
abc
from
..
import
util
from
.
import
util
as
builtin_util
frozen_machinery
,
source_machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
import
sys
import
unittest
class
FinderTests
(
unittest
.
TestCase
,
abc
.
FinderTests
):
class
FinderTests
(
abc
.
FinderTests
):
"""Test find_module() for built-in modules."""
def
test_module
(
self
):
# Common case.
with
util
.
uncache
(
builtin_util
.
NAME
):
found
=
machinery
.
BuiltinImporter
.
find_module
(
builtin_util
.
NAME
)
found
=
self
.
machinery
.
BuiltinImporter
.
find_module
(
builtin_util
.
NAME
)
self
.
assertTrue
(
found
)
def
test_package
(
self
):
...
...
@@ -34,16 +36,18 @@ class FinderTests(unittest.TestCase, abc.FinderTests):
def
test_failure
(
self
):
assert
'importlib'
not
in
sys
.
builtin_module_names
loader
=
machinery
.
BuiltinImporter
.
find_module
(
'importlib'
)
loader
=
self
.
machinery
.
BuiltinImporter
.
find_module
(
'importlib'
)
self
.
assertIsNone
(
loader
)
def
test_ignore_path
(
self
):
# The value for 'path' should always trigger a failed import.
with
util
.
uncache
(
builtin_util
.
NAME
):
loader
=
machinery
.
BuiltinImporter
.
find_module
(
builtin_util
.
NAME
,
loader
=
self
.
machinery
.
BuiltinImporter
.
find_module
(
builtin_util
.
NAME
,
[
'pkg'
])
self
.
assertIsNone
(
loader
)
Frozen_FinderTests
,
Source_FinderTests
=
util
.
test_both
(
FinderTests
,
machinery
=
[
frozen_machinery
,
source_machinery
])
if
__name__
==
'__main__'
:
...
...
Lib/test/test_importlib/builtin/test_loader.py
Dosyayı görüntüle @
ffd33c29
import
importlib
from
importlib
import
machinery
from
..
import
abc
from
..
import
util
from
.
import
util
as
builtin_util
frozen_machinery
,
source_machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
import
sys
import
types
import
unittest
class
LoaderTests
(
unittest
.
TestCase
,
abc
.
LoaderTests
):
class
LoaderTests
(
abc
.
LoaderTests
):
"""Test load_module() for built-in modules."""
verification
=
{
'__name__'
:
'errno'
,
'__package__'
:
''
,
'__loader__'
:
machinery
.
BuiltinImporter
}
def
setUp
(
self
):
self
.
verification
=
{
'__name__'
:
'errno'
,
'__package__'
:
''
,
'__loader__'
:
self
.
machinery
.
BuiltinImporter
}
def
verify
(
self
,
module
):
"""Verify that the module matches against what it should have."""
...
...
@@ -23,8 +24,8 @@ class LoaderTests(unittest.TestCase, abc.LoaderTests):
self
.
assertEqual
(
getattr
(
module
,
attr
),
value
)
self
.
assertIn
(
module
.
__name__
,
sys
.
modules
)
load_module
=
staticmethod
(
lambda
name
:
machinery
.
BuiltinImporter
.
load_module
(
name
)
)
def
load_module
(
self
,
name
)
:
return
self
.
machinery
.
BuiltinImporter
.
load_module
(
name
)
def
test_module
(
self
):
# Common case.
...
...
@@ -61,45 +62,47 @@ class LoaderTests(unittest.TestCase, abc.LoaderTests):
def
test_already_imported
(
self
):
# Using the name of a module already imported but not a built-in should
# still fail.
assert
hasattr
(
importlib
,
'__file__'
)
# Not a built-in.
assert
hasattr
(
unittest
,
'__file__'
)
# Not a built-in.
with
self
.
assertRaises
(
ImportError
)
as
cm
:
self
.
load_module
(
'importlib'
)
self
.
assertEqual
(
cm
.
exception
.
name
,
'importlib'
)
self
.
load_module
(
'unittest'
)
self
.
assertEqual
(
cm
.
exception
.
name
,
'unittest'
)
Frozen_LoaderTests
,
Source_LoaderTests
=
util
.
test_both
(
LoaderTests
,
machinery
=
[
frozen_machinery
,
source_machinery
])
class
InspectLoaderTests
(
unittest
.
TestCase
)
:
class
InspectLoaderTests
:
"""Tests for InspectLoader methods for BuiltinImporter."""
def
test_get_code
(
self
):
# There is no code object.
result
=
machinery
.
BuiltinImporter
.
get_code
(
builtin_util
.
NAME
)
result
=
self
.
machinery
.
BuiltinImporter
.
get_code
(
builtin_util
.
NAME
)
self
.
assertIsNone
(
result
)
def
test_get_source
(
self
):
# There is no source.
result
=
machinery
.
BuiltinImporter
.
get_source
(
builtin_util
.
NAME
)
result
=
self
.
machinery
.
BuiltinImporter
.
get_source
(
builtin_util
.
NAME
)
self
.
assertIsNone
(
result
)
def
test_is_package
(
self
):
# Cannot be a package.
result
=
machinery
.
BuiltinImporter
.
is_package
(
builtin_util
.
NAME
)
result
=
self
.
machinery
.
BuiltinImporter
.
is_package
(
builtin_util
.
NAME
)
self
.
assertTrue
(
not
result
)
def
test_not_builtin
(
self
):
# Modules not built-in should raise ImportError.
for
meth_name
in
(
'get_code'
,
'get_source'
,
'is_package'
):
method
=
getattr
(
machinery
.
BuiltinImporter
,
meth_name
)
method
=
getattr
(
self
.
machinery
.
BuiltinImporter
,
meth_name
)
with
self
.
assertRaises
(
ImportError
)
as
cm
:
method
(
builtin_util
.
BAD_NAME
)
self
.
assertRaises
(
builtin_util
.
BAD_NAME
)
def
test_main
():
from
test.support
import
run_unittest
run_unittest
(
LoaderTests
,
InspectLoaderTests
)
Frozen_InspectLoaderTests
,
Source_InspectLoaderTests
=
util
.
test_both
(
InspectLoaderTests
,
machinery
=
[
frozen_machinery
,
source_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