mirror of
https://github.com/python/cpython.git
synced 2025-09-09 02:11:51 +00:00
issue9859: Document test.support.detect_api_mismatch() and simplify its test.
This commit is contained in:
parent
1bef9075b8
commit
4e72cceb62
3 changed files with 30 additions and 31 deletions
|
@ -568,6 +568,15 @@ The :mod:`test.support` module defines the following functions:
|
||||||
def load_tests(*args):
|
def load_tests(*args):
|
||||||
return load_package_tests(os.path.dirname(__file__), *args)
|
return load_package_tests(os.path.dirname(__file__), *args)
|
||||||
|
|
||||||
|
.. function:: detect_api_mismatch(ref_api, other_api, *, ignore=()):
|
||||||
|
|
||||||
|
Returns the set of attributes, functions or methods of `ref_api` not
|
||||||
|
found on `other_api`, except for a defined list of items to be
|
||||||
|
ignored in this check specified in `ignore`.
|
||||||
|
|
||||||
|
By default this skips private attributes beginning with '_' but
|
||||||
|
includes all magic methods, i.e. those starting and ending in '__'.
|
||||||
|
|
||||||
|
|
||||||
The :mod:`test.support` module defines the following classes:
|
The :mod:`test.support` module defines the following classes:
|
||||||
|
|
||||||
|
|
|
@ -2184,7 +2184,7 @@ def fs_is_case_insensitive(directory):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def detect_api_mismatch(ref_api, other_api, *, ignore=None):
|
def detect_api_mismatch(ref_api, other_api, *, ignore=()):
|
||||||
"""Returns the set of items in ref_api not in other_api, except for a
|
"""Returns the set of items in ref_api not in other_api, except for a
|
||||||
defined list of items to be ignored in this check.
|
defined list of items to be ignored in this check.
|
||||||
|
|
||||||
|
|
|
@ -280,46 +280,36 @@ class TestSupport(unittest.TestCase):
|
||||||
self.assertEqual(D["item"], 5)
|
self.assertEqual(D["item"], 5)
|
||||||
self.assertEqual(D["item"], 1)
|
self.assertEqual(D["item"], 1)
|
||||||
|
|
||||||
|
class RefClass:
|
||||||
|
attribute1 = None
|
||||||
|
attribute2 = None
|
||||||
|
_hidden_attribute1 = None
|
||||||
|
__magic_1__ = None
|
||||||
|
|
||||||
|
class OtherClass:
|
||||||
|
attribute2 = None
|
||||||
|
attribute3 = None
|
||||||
|
__magic_1__ = None
|
||||||
|
__magic_2__ = None
|
||||||
|
|
||||||
def test_detect_api_mismatch(self):
|
def test_detect_api_mismatch(self):
|
||||||
class RefClass:
|
missing_items = support.detect_api_mismatch(self.RefClass,
|
||||||
attribute1 = None
|
self.OtherClass)
|
||||||
attribute2 = None
|
|
||||||
_hidden_attribute1 = None
|
|
||||||
__magic_1__ = None
|
|
||||||
|
|
||||||
class OtherClass:
|
|
||||||
attribute2 = None
|
|
||||||
attribute3 = None
|
|
||||||
__magic_1__ = None
|
|
||||||
__magic_2__ = None
|
|
||||||
|
|
||||||
missing_items = support.detect_api_mismatch(RefClass, OtherClass)
|
|
||||||
self.assertEqual({'attribute1'}, missing_items)
|
self.assertEqual({'attribute1'}, missing_items)
|
||||||
|
|
||||||
missing_items = support.detect_api_mismatch(OtherClass, RefClass)
|
missing_items = support.detect_api_mismatch(self.OtherClass,
|
||||||
|
self.RefClass)
|
||||||
self.assertEqual({'attribute3', '__magic_2__'}, missing_items)
|
self.assertEqual({'attribute3', '__magic_2__'}, missing_items)
|
||||||
|
|
||||||
def test_detect_api_mismatch__ignore(self):
|
def test_detect_api_mismatch__ignore(self):
|
||||||
class RefClass:
|
|
||||||
attribute1 = None
|
|
||||||
attribute2 = None
|
|
||||||
_hidden_attribute1 = None
|
|
||||||
__magic_1__ = None
|
|
||||||
|
|
||||||
class OtherClass:
|
|
||||||
attribute2 = None
|
|
||||||
attribute3 = None
|
|
||||||
__magic_1__ = None
|
|
||||||
__magic_2__ = None
|
|
||||||
|
|
||||||
ignore = ['attribute1', 'attribute3', '__magic_2__', 'not_in_either']
|
ignore = ['attribute1', 'attribute3', '__magic_2__', 'not_in_either']
|
||||||
|
|
||||||
missing_items = support.detect_api_mismatch(RefClass, OtherClass,
|
missing_items = support.detect_api_mismatch(
|
||||||
ignore=ignore)
|
self.RefClass, self.OtherClass, ignore=ignore)
|
||||||
self.assertEqual(set(), missing_items)
|
self.assertEqual(set(), missing_items)
|
||||||
|
|
||||||
missing_items = support.detect_api_mismatch(OtherClass, RefClass,
|
missing_items = support.detect_api_mismatch(
|
||||||
ignore=ignore)
|
self.OtherClass, self.RefClass, ignore=ignore)
|
||||||
self.assertEqual(set(), missing_items)
|
self.assertEqual(set(), missing_items)
|
||||||
|
|
||||||
# XXX -follows a list of untested API
|
# XXX -follows a list of untested API
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue