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