Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e72cce

Browse files
committed
issue9859: Document test.support.detect_api_mismatch() and simplify its test.
1 parent 1bef907 commit 4e72cce

3 files changed

Lines changed: 30 additions & 31 deletions

File tree

Doc/library/test.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,15 @@ The :mod:`test.support` module defines the following functions:
568568
def load_tests(*args):
569569
return load_package_tests(os.path.dirname(__file__), *args)
570570

571+
.. function:: detect_api_mismatch(ref_api, other_api, *, ignore=()):
572+
573+
Returns the set of attributes, functions or methods of `ref_api` not
574+
found on `other_api`, except for a defined list of items to be
575+
ignored in this check specified in `ignore`.
576+
577+
By default this skips private attributes beginning with '_' but
578+
includes all magic methods, i.e. those starting and ending in '__'.
579+
571580

572581
The :mod:`test.support` module defines the following classes:
573582

Lib/test/support/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,7 @@ def fs_is_case_insensitive(directory):
21842184
return False
21852185

21862186

2187-
def detect_api_mismatch(ref_api, other_api, *, ignore=None):
2187+
def detect_api_mismatch(ref_api, other_api, *, ignore=()):
21882188
"""Returns the set of items in ref_api not in other_api, except for a
21892189
defined list of items to be ignored in this check.
21902190

Lib/test/test_support.py

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -280,46 +280,36 @@ def test_swap_item(self):
280280
self.assertEqual(D["item"], 5)
281281
self.assertEqual(D["item"], 1)
282282

283+
class RefClass:
284+
attribute1 = None
285+
attribute2 = None
286+
_hidden_attribute1 = None
287+
__magic_1__ = None
288+
289+
class OtherClass:
290+
attribute2 = None
291+
attribute3 = None
292+
__magic_1__ = None
293+
__magic_2__ = None
294+
283295
def test_detect_api_mismatch(self):
284-
class RefClass:
285-
attribute1 = None
286-
attribute2 = None
287-
_hidden_attribute1 = None
288-
__magic_1__ = None
289-
290-
class OtherClass:
291-
attribute2 = None
292-
attribute3 = None
293-
__magic_1__ = None
294-
__magic_2__ = None
295-
296-
missing_items = support.detect_api_mismatch(RefClass, OtherClass)
296+
missing_items = support.detect_api_mismatch(self.RefClass,
297+
self.OtherClass)
297298
self.assertEqual({'attribute1'}, missing_items)
298299

299-
missing_items = support.detect_api_mismatch(OtherClass, RefClass)
300+
missing_items = support.detect_api_mismatch(self.OtherClass,
301+
self.RefClass)
300302
self.assertEqual({'attribute3', '__magic_2__'}, missing_items)
301303

302304
def test_detect_api_mismatch__ignore(self):
303-
class RefClass:
304-
attribute1 = None
305-
attribute2 = None
306-
_hidden_attribute1 = None
307-
__magic_1__ = None
308-
309-
class OtherClass:
310-
attribute2 = None
311-
attribute3 = None
312-
__magic_1__ = None
313-
__magic_2__ = None
314-
315305
ignore = ['attribute1', 'attribute3', '__magic_2__', 'not_in_either']
316306

317-
missing_items = support.detect_api_mismatch(RefClass, OtherClass,
318-
ignore=ignore)
307+
missing_items = support.detect_api_mismatch(
308+
self.RefClass, self.OtherClass, ignore=ignore)
319309
self.assertEqual(set(), missing_items)
320310

321-
missing_items = support.detect_api_mismatch(OtherClass, RefClass,
322-
ignore=ignore)
311+
missing_items = support.detect_api_mismatch(
312+
self.OtherClass, self.RefClass, ignore=ignore)
323313
self.assertEqual(set(), missing_items)
324314

325315
# XXX -follows a list of untested API

0 commit comments

Comments
 (0)