Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
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
django
Commits
f6bd0013
Kaydet (Commit)
f6bd0013
authored
Haz 08, 2017
tarafından
Thomas Khyn
Kaydeden (comit)
Tim Graham
Haz 08, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #28241 -- Allowed module_has_submodule()'s module_name arg to be a dotted path.
üst
af69f14e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
1 deletion
+21
-1
module_loading.py
django/utils/module_loading.py
+8
-1
__init__.py
tests/utils_tests/test_module/child_module/__init__.py
+0
-0
grandchild_module.py
...utils_tests/test_module/child_module/grandchild_module.py
+1
-0
test_module_loading.py
tests/utils_tests/test_module_loading.py
+12
-0
No files found.
django/utils/module_loading.py
Dosyayı görüntüle @
f6bd0013
...
...
@@ -70,7 +70,14 @@ def module_has_submodule(package, module_name):
return
False
full_module_name
=
package_name
+
'.'
+
module_name
return
importlib_find
(
full_module_name
,
package_path
)
is
not
None
try
:
return
importlib_find
(
full_module_name
,
package_path
)
is
not
None
except
(
ImportError
,
AttributeError
):
# When module_name is an invalid dotted path, Python raises ImportError
# (or ModuleNotFoundError in Python 3.6+). AttributeError may be raised
# if the penultimate part of the path is not a package.
# (http://bugs.python.org/issue30436)
return
False
def
module_dir
(
module
):
...
...
tests/utils_tests/test_module/child_module/__init__.py
0 → 100644
Dosyayı görüntüle @
f6bd0013
tests/utils_tests/test_module/child_module/grandchild_module.py
0 → 100644
Dosyayı görüntüle @
f6bd0013
content
=
'Grandchild Module'
tests/utils_tests/test_module_loading.py
Dosyayı görüntüle @
f6bd0013
...
...
@@ -48,6 +48,18 @@ class DefaultLoader(unittest.TestCase):
with
self
.
assertRaises
(
ImportError
):
import_module
(
'utils_tests.test_no_submodule.anything'
)
def
test_has_sumbodule_with_dotted_path
(
self
):
"""Nested module existence can be tested."""
test_module
=
import_module
(
'utils_tests.test_module'
)
# A grandchild that exists.
self
.
assertIs
(
module_has_submodule
(
test_module
,
'child_module.grandchild_module'
),
True
)
# A grandchild that doesn't exist.
self
.
assertIs
(
module_has_submodule
(
test_module
,
'child_module.no_such_module'
),
False
)
# A grandchild whose parent doesn't exist.
self
.
assertIs
(
module_has_submodule
(
test_module
,
'no_such_module.grandchild_module'
),
False
)
# A grandchild whose parent is not a package.
self
.
assertIs
(
module_has_submodule
(
test_module
,
'good_module.no_such_module'
),
False
)
class
EggLoader
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
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