cpython: cbdd56d07123 (original) (raw)
Mercurial > cpython
changeset 95657:cbdd56d07123
issue9859: Document test.support.detect_api_mismatch() and simplify its test. [#9859]
Gregory P. Smith greg@krypto.org | |
---|---|
date | Tue, 14 Apr 2015 13:26:06 -0700 |
parents | 9903368b9d7b |
children | 4286afa7b63e |
files | Doc/library/test.rst Lib/test/support/__init__.py Lib/test/test_support.py |
diffstat | 3 files changed, 29 insertions(+), 30 deletions(-)[+] [-] Doc/library/test.rst 9 Lib/test/support/__init__.py 2 Lib/test/test_support.py 48 |
line wrap: on
line diff
--- a/Doc/library/test.rst
+++ b/Doc/library/test.rst
@@ -568,6 +568,15 @@ The :mod:test.support
module defines t
def load_tests(*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:
--- a/Lib/test/support/init.py +++ b/Lib/test/support/init.py @@ -2184,7 +2184,7 @@ def fs_is_case_insensitive(directory): 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 defined list of items to be ignored in this check.
--- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -280,46 +280,36 @@ class TestSupport(unittest.TestCase): self.assertEqual(D["item"], 5) self.assertEqual(D["item"], 1)
- def test_detect_api_mismatch(self):
class RefClass:[](#l3.8)
attribute1 = None[](#l3.9)
attribute2 = None[](#l3.10)
_hidden_attribute1 = None[](#l3.11)
__magic_1__ = None[](#l3.12)
- class RefClass:
attribute1 = None[](#l3.14)
attribute2 = None[](#l3.15)
_hidden_attribute1 = None[](#l3.16)
__magic_1__ = None[](#l3.17)
class OtherClass:[](#l3.19)
attribute2 = None[](#l3.20)
attribute3 = None[](#l3.21)
__magic_1__ = None[](#l3.22)
__magic_2__ = None[](#l3.23)
- class OtherClass:
attribute2 = None[](#l3.25)
attribute3 = None[](#l3.26)
__magic_1__ = None[](#l3.27)
__magic_2__ = None[](#l3.28)
missing_items = support.detect_api_mismatch(RefClass, OtherClass)[](#l3.30)
- def test_detect_api_mismatch(self):
missing_items = support.detect_api_mismatch(self.RefClass,[](#l3.32)
self.OtherClass)[](#l3.33) self.assertEqual({'attribute1'}, missing_items)[](#l3.34)
missing_items = support.detect_api_mismatch(OtherClass, RefClass)[](#l3.36)
missing_items = support.detect_api_mismatch(self.OtherClass,[](#l3.37)
self.RefClass)[](#l3.38) self.assertEqual({'attribute3', '__magic_2__'}, missing_items)[](#l3.39)
def test_detect_api_mismatch__ignore(self):
class RefClass:[](#l3.42)
attribute1 = None[](#l3.43)
attribute2 = None[](#l3.44)
_hidden_attribute1 = None[](#l3.45)
__magic_1__ = None[](#l3.46)
class OtherClass:[](#l3.48)
attribute2 = None[](#l3.49)
attribute3 = None[](#l3.50)
__magic_1__ = None[](#l3.51)
__magic_2__ = None[](#l3.52)
- ignore = ['attribute1', 'attribute3', 'magic_2', 'not_in_either']
missing_items = support.detect_api_mismatch(RefClass, OtherClass,[](#l3.56)
ignore=ignore)[](#l3.57)
missing_items = support.detect_api_mismatch([](#l3.58)
self.RefClass, self.OtherClass, ignore=ignore)[](#l3.59) self.assertEqual(set(), missing_items)[](#l3.60)
missing_items = support.detect_api_mismatch(OtherClass, RefClass,[](#l3.62)
ignore=ignore)[](#l3.63)
missing_items = support.detect_api_mismatch([](#l3.64)
self.OtherClass, self.RefClass, ignore=ignore)[](#l3.65) self.assertEqual(set(), missing_items)[](#l3.66)