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
30b047dc
Kaydet (Commit)
30b047dc
authored
Şub 01, 2009
tarafından
Brett Cannon
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Move source loader tests (including reload tests) over to
importlib.test.abc.LoaderTests.
üst
223a19d8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
77 deletions
+72
-77
NOTES
Lib/importlib/NOTES
+0
-4
test_loader.py
Lib/importlib/test/source/test_loader.py
+72
-2
test_reload.py
Lib/importlib/test/source/test_reload.py
+0
-71
No files found.
Lib/importlib/NOTES
Dosyayı görüntüle @
30b047dc
to do
to do
/////
/////
* Use test.abc.LoaderTests
+ source
* Reorganize support code.
* Reorganize support code.
+ Separate general support code and importer-specific (e.g. source) support
+ Separate general support code and importer-specific (e.g. source) support
...
...
Lib/importlib/test/source/test_loader.py
Dosyayı görüntüle @
30b047dc
import
importlib
import
importlib
from
..
import
abc
from
..
import
support
from
..
import
support
import
imp
import
imp
...
@@ -16,11 +17,80 @@ class SimpleTest(unittest.TestCase):
...
@@ -16,11 +17,80 @@ class SimpleTest(unittest.TestCase):
"""
"""
# [basic]
# [basic]
def
test_
basic
(
self
):
def
test_
module
(
self
):
with
support
.
create_modules
(
'_temp'
)
as
mapping
:
with
support
.
create_modules
(
'_temp'
)
as
mapping
:
loader
=
importlib
.
_PyFileLoader
(
'_temp'
,
mapping
[
'_temp'
],
False
)
loader
=
importlib
.
_PyFileLoader
(
'_temp'
,
mapping
[
'_temp'
],
False
)
loader
.
load_module
(
'_temp'
)
module
=
loader
.
load_module
(
'_temp'
)
self
.
assert_
(
'_temp'
in
sys
.
modules
)
self
.
assert_
(
'_temp'
in
sys
.
modules
)
check
=
{
'__name__'
:
'_temp'
,
'__file__'
:
mapping
[
'_temp'
],
'__package__'
:
None
}
for
attr
,
value
in
check
.
items
():
self
.
assertEqual
(
getattr
(
module
,
attr
),
value
)
def
test_package
(
self
):
with
support
.
create_modules
(
'_pkg.__init__'
)
as
mapping
:
loader
=
importlib
.
_PyFileLoader
(
'_pkg'
,
mapping
[
'_pkg.__init__'
],
True
)
module
=
loader
.
load_module
(
'_pkg'
)
self
.
assert_
(
'_pkg'
in
sys
.
modules
)
check
=
{
'__name__'
:
'_pkg'
,
'__file__'
:
mapping
[
'_pkg.__init__'
],
'__path__'
:
[
os
.
path
.
dirname
(
mapping
[
'_pkg.__init__'
])],
'__package__'
:
'_pkg'
}
for
attr
,
value
in
check
.
items
():
self
.
assertEqual
(
getattr
(
module
,
attr
),
value
)
def
test_lacking_parent
(
self
):
with
support
.
create_modules
(
'_pkg.__init__'
,
'_pkg.mod'
)
as
mapping
:
loader
=
importlib
.
_PyFileLoader
(
'_pkg.mod'
,
mapping
[
'_pkg.mod'
],
False
)
module
=
loader
.
load_module
(
'_pkg.mod'
)
self
.
assert_
(
'_pkg.mod'
in
sys
.
modules
)
check
=
{
'__name__'
:
'_pkg.mod'
,
'__file__'
:
mapping
[
'_pkg.mod'
],
'__package__'
:
'_pkg'
}
for
attr
,
value
in
check
.
items
():
self
.
assertEqual
(
getattr
(
module
,
attr
),
value
)
def
fake_mtime
(
self
,
fxn
):
"""Fake mtime to always be higher than expected."""
return
lambda
name
:
fxn
(
name
)
+
1
def
test_module_reuse
(
self
):
with
support
.
create_modules
(
'_temp'
)
as
mapping
:
loader
=
importlib
.
_PyFileLoader
(
'_temp'
,
mapping
[
'_temp'
],
False
)
module
=
loader
.
load_module
(
'_temp'
)
module_id
=
id
(
module
)
module_dict_id
=
id
(
module
.
__dict__
)
with
open
(
mapping
[
'_temp'
],
'w'
)
as
file
:
file
.
write
(
"testing_var = 42
\n
"
)
# For filesystems where the mtime is only to a second granularity,
# everything that has happened above can be too fast;
# force an mtime on the source that is guaranteed to be different
# than the original mtime.
loader
.
source_mtime
=
self
.
fake_mtime
(
loader
.
source_mtime
)
module
=
loader
.
load_module
(
'_temp'
)
self
.
assert_
(
'testing_var'
in
module
.
__dict__
,
"'testing_var' not in "
"{0}"
.
format
(
list
(
module
.
__dict__
.
keys
())))
self
.
assertEqual
(
module
,
sys
.
modules
[
'_temp'
])
self
.
assertEqual
(
id
(
module
),
module_id
)
self
.
assertEqual
(
id
(
module
.
__dict__
),
module_dict_id
)
def
test_state_after_failure
(
self
):
# A failed reload should leave the original module intact.
attributes
=
(
'__file__'
,
'__path__'
,
'__package__'
)
value
=
'<test>'
name
=
'_temp'
with
support
.
create_modules
(
name
)
as
mapping
:
orig_module
=
imp
.
new_module
(
name
)
for
attr
in
attributes
:
setattr
(
orig_module
,
attr
,
value
)
with
open
(
mapping
[
name
],
'w'
)
as
file
:
file
.
write
(
'+++ bad syntax +++'
)
loader
=
importlib
.
_PyFileLoader
(
'_temp'
,
mapping
[
'_temp'
],
False
)
self
.
assertRaises
(
SyntaxError
,
loader
.
load_module
,
name
)
for
attr
in
attributes
:
self
.
assertEqual
(
getattr
(
orig_module
,
attr
),
value
)
# [syntax error]
# [syntax error]
def
test_bad_syntax
(
self
):
def
test_bad_syntax
(
self
):
...
...
Lib/importlib/test/source/test_reload.py
deleted
100644 → 0
Dosyayı görüntüle @
223a19d8
"""Test reload support.
Reload support requires two things. One is that if module is loaded that
already exists in sys.modules then it is reused. And two, if a reload fails the
pre-existing module is left in a sane state.
"""
import
imp
import
sys
import
types
import
unittest
import
importlib
from
..
import
support
class
ReloadTests
(
unittest
.
TestCase
):
name
=
'_temp'
def
load_module
(
self
,
mapping
):
return
importlib
.
_PyFileLoader
(
self
.
name
,
mapping
[
self
.
name
],
False
)
def
fake_mtime
(
self
,
fxn
):
"""Fake mtime to always be higher than expected."""
return
lambda
name
:
fxn
(
name
)
+
1
def
test_module_reuse
(
self
):
with
support
.
create_modules
(
self
.
name
)
as
mapping
:
loader
=
self
.
load_module
(
mapping
)
module
=
loader
.
load_module
(
self
.
name
)
module_id
=
id
(
module
)
module_dict_id
=
id
(
module
.
__dict__
)
with
open
(
mapping
[
self
.
name
],
'w'
)
as
file
:
file
.
write
(
"testing_var = 42
\n
"
)
# For filesystems where the mtime is only to a second granularity,
# everything that has happened above can be too fast;
# force an mtime on the source that is guaranteed to be different
# than the original mtime.
loader
.
source_mtime
=
self
.
fake_mtime
(
loader
.
source_mtime
)
module
=
loader
.
load_module
(
self
.
name
)
self
.
assert_
(
'testing_var'
in
module
.
__dict__
,
"'testing_var' not in "
"{0}"
.
format
(
list
(
module
.
__dict__
.
keys
())))
self
.
assertEqual
(
module
,
sys
.
modules
[
self
.
name
])
self
.
assertEqual
(
id
(
module
),
module_id
)
self
.
assertEqual
(
id
(
module
.
__dict__
),
module_dict_id
)
def
test_bad_reload
(
self
):
# A failed reload should leave the original module intact.
attributes
=
(
'__file__'
,
'__path__'
,
'__package__'
)
value
=
'<test>'
with
support
.
create_modules
(
self
.
name
)
as
mapping
:
orig_module
=
imp
.
new_module
(
self
.
name
)
for
attr
in
attributes
:
setattr
(
orig_module
,
attr
,
value
)
with
open
(
mapping
[
self
.
name
],
'w'
)
as
file
:
file
.
write
(
'+++ bad syntax +++'
)
loader
=
self
.
load_module
(
mapping
)
self
.
assertRaises
(
SyntaxError
,
loader
.
load_module
,
self
.
name
)
for
attr
in
attributes
:
self
.
assertEqual
(
getattr
(
orig_module
,
attr
),
value
)
def
test_main
():
from
test.support
import
run_unittest
run_unittest
(
ReloadTests
)
if
__name__
==
'__main__'
:
test_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