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
d226d308
Kaydet (Commit)
d226d308
authored
Kas 14, 2015
tarafından
Martin Panter
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #23883: Add test.support.check__all__() and test gettext.__all__
Patches by Jacek Kołodziej.
üst
63c1ebb6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
0 deletions
+132
-0
test.rst
Doc/library/test.rst
+42
-0
__init__.py
Lib/test/support/__init__.py
+61
-0
test_gettext.py
Lib/test/test_gettext.py
+6
-0
test_support.py
Lib/test/test_support.py
+22
-0
ACKS
Misc/ACKS
+1
-0
No files found.
Doc/library/test.rst
Dosyayı görüntüle @
d226d308
...
@@ -580,6 +580,48 @@ The :mod:`test.support` module defines the following functions:
...
@@ -580,6 +580,48 @@ The :mod:`test.support` module defines the following functions:
.. versionadded:: 3.5
.. versionadded:: 3.5
.. function:: check__all__(test_case, module, name_of_module=None, extra=(), blacklist=())
Assert that the ``__all__`` variable of *module* contains all public names.
The module's public names (its API) are detected automatically
based on whether they match the public name convention and were defined in
*module*.
The *name_of_module* argument can specify (as a string or tuple thereof) what
module(s) an API could be defined in in order to be detected as a public
API. One case for this is when *module* imports part of its public API from
other modules, possibly a C backend (like ``csv`` and its ``_csv``).
The *extra* argument can be a set of names that wouldn't otherwise be automatically
detected as "public", like objects without a proper ``__module__``
attribute. If provided, it will be added to the automatically detected ones.
The *blacklist* argument can be a set of names that must not be treated as part of
the public API even though their names indicate otherwise.
Example use::
import bar
import foo
import unittest
from test import support
class MiscTestCase(unittest.TestCase):
def test__all__(self):
support.check__all__(self, foo)
class OtherTestCase(unittest.TestCase):
def test__all__(self):
extra = {'BAR_CONST', 'FOO_CONST'}
blacklist = {'baz'} # Undocumented name.
# bar imports part of its API from _bar.
support.check__all__(self, bar, ('bar', '_bar'),
extra=extra, blacklist=blacklist)
.. versionadded:: 3.6
The :mod:`test.support` module defines the following classes:
The :mod:`test.support` module defines the following classes:
.. class:: TransientResource(exc, **kwargs)
.. class:: TransientResource(exc, **kwargs)
...
...
Lib/test/support/__init__.py
Dosyayı görüntüle @
d226d308
...
@@ -26,6 +26,7 @@ import sys
...
@@ -26,6 +26,7 @@ import sys
import
sysconfig
import
sysconfig
import
tempfile
import
tempfile
import
time
import
time
import
types
import
unittest
import
unittest
import
urllib.error
import
urllib.error
import
warnings
import
warnings
...
@@ -89,6 +90,7 @@ __all__ = [
...
@@ -89,6 +90,7 @@ __all__ = [
"bigmemtest"
,
"bigaddrspacetest"
,
"cpython_only"
,
"get_attribute"
,
"bigmemtest"
,
"bigaddrspacetest"
,
"cpython_only"
,
"get_attribute"
,
"requires_IEEE_754"
,
"skip_unless_xattr"
,
"requires_zlib"
,
"requires_IEEE_754"
,
"skip_unless_xattr"
,
"requires_zlib"
,
"anticipate_failure"
,
"load_package_tests"
,
"detect_api_mismatch"
,
"anticipate_failure"
,
"load_package_tests"
,
"detect_api_mismatch"
,
"check__all__"
,
# sys
# sys
"is_jython"
,
"check_impl_detail"
,
"is_jython"
,
"check_impl_detail"
,
# network
# network
...
@@ -2199,6 +2201,65 @@ def detect_api_mismatch(ref_api, other_api, *, ignore=()):
...
@@ -2199,6 +2201,65 @@ def detect_api_mismatch(ref_api, other_api, *, ignore=()):
return
missing_items
return
missing_items
def
check__all__
(
test_case
,
module
,
name_of_module
=
None
,
extra
=
(),
blacklist
=
()):
"""Assert that the __all__ variable of 'module' contains all public names.
The module's public names (its API) are detected automatically based on
whether they match the public name convention and were defined in
'module'.
The 'name_of_module' argument can specify (as a string or tuple thereof)
what module(s) an API could be defined in in order to be detected as a
public API. One case for this is when 'module' imports part of its public
API from other modules, possibly a C backend (like 'csv' and its '_csv').
The 'extra' argument can be a set of names that wouldn't otherwise be
automatically detected as "public", like objects without a proper
'__module__' attriubute. If provided, it will be added to the
automatically detected ones.
The 'blacklist' argument can be a set of names that must not be treated
as part of the public API even though their names indicate otherwise.
Usage:
import bar
import foo
import unittest
from test import support
class MiscTestCase(unittest.TestCase):
def test__all__(self):
support.check__all__(self, foo)
class OtherTestCase(unittest.TestCase):
def test__all__(self):
extra = {'BAR_CONST', 'FOO_CONST'}
blacklist = {'baz'} # Undocumented name.
# bar imports part of its API from _bar.
support.check__all__(self, bar, ('bar', '_bar'),
extra=extra, blacklist=blacklist)
"""
if
name_of_module
is
None
:
name_of_module
=
(
module
.
__name__
,
)
elif
isinstance
(
name_of_module
,
str
):
name_of_module
=
(
name_of_module
,
)
expected
=
set
(
extra
)
for
name
in
dir
(
module
):
if
name
.
startswith
(
'_'
)
or
name
in
blacklist
:
continue
obj
=
getattr
(
module
,
name
)
if
(
getattr
(
obj
,
'__module__'
,
None
)
in
name_of_module
or
(
not
hasattr
(
obj
,
'__module__'
)
and
not
isinstance
(
obj
,
types
.
ModuleType
))):
expected
.
add
(
name
)
test_case
.
assertCountEqual
(
module
.
__all__
,
expected
)
class
SuppressCrashReport
:
class
SuppressCrashReport
:
"""Try to prevent a crash report from popping up.
"""Try to prevent a crash report from popping up.
...
...
Lib/test/test_gettext.py
Dosyayı görüntüle @
d226d308
...
@@ -440,6 +440,12 @@ class GettextCacheTestCase(GettextBaseTest):
...
@@ -440,6 +440,12 @@ class GettextCacheTestCase(GettextBaseTest):
self
.
assertEqual
(
t
.
__class__
,
DummyGNUTranslations
)
self
.
assertEqual
(
t
.
__class__
,
DummyGNUTranslations
)
class
MiscTestCase
(
unittest
.
TestCase
):
def
test__all__
(
self
):
blacklist
=
{
'c2py'
,
'ENOENT'
}
support
.
check__all__
(
self
,
gettext
,
blacklist
=
blacklist
)
def
test_main
():
def
test_main
():
support
.
run_unittest
(
__name__
)
support
.
run_unittest
(
__name__
)
...
...
Lib/test/test_support.py
Dosyayı görüntüle @
d226d308
...
@@ -312,6 +312,28 @@ class TestSupport(unittest.TestCase):
...
@@ -312,6 +312,28 @@ class TestSupport(unittest.TestCase):
self
.
OtherClass
,
self
.
RefClass
,
ignore
=
ignore
)
self
.
OtherClass
,
self
.
RefClass
,
ignore
=
ignore
)
self
.
assertEqual
(
set
(),
missing_items
)
self
.
assertEqual
(
set
(),
missing_items
)
def
test_check__all__
(
self
):
extra
=
{
'tempdir'
}
blacklist
=
{
'template'
}
support
.
check__all__
(
self
,
tempfile
,
extra
=
extra
,
blacklist
=
blacklist
)
extra
=
{
'TextTestResult'
,
'installHandler'
}
blacklist
=
{
'load_tests'
,
"TestProgram"
,
"BaseTestSuite"
}
support
.
check__all__
(
self
,
unittest
,
(
"unittest.result"
,
"unittest.case"
,
"unittest.suite"
,
"unittest.loader"
,
"unittest.main"
,
"unittest.runner"
,
"unittest.signals"
),
extra
=
extra
,
blacklist
=
blacklist
)
self
.
assertRaises
(
AssertionError
,
support
.
check__all__
,
self
,
unittest
)
# XXX -follows a list of untested API
# XXX -follows a list of untested API
# make_legacy_pyc
# make_legacy_pyc
# is_resource_enabled
# is_resource_enabled
...
...
Misc/ACKS
Dosyayı görüntüle @
d226d308
...
@@ -765,6 +765,7 @@ Damon Kohler
...
@@ -765,6 +765,7 @@ Damon Kohler
Marko Kohtala
Marko Kohtala
Vajrasky Kok
Vajrasky Kok
Guido Kollerie
Guido Kollerie
Jacek Kołodziej
Jacek Konieczny
Jacek Konieczny
Марк Коренберг
Марк Коренберг
Arkady Koplyarov
Arkady Koplyarov
...
...
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