diff options
author | Gregory P. Smith <greg@krypto.org> | 2015-04-14 19:56:53 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@krypto.org> | 2015-04-14 19:56:53 (GMT) |
commit | e334e3ff714502a25c3270bd4cb4d9a699076deb (patch) | |
tree | 6320908ce22dea096f84d2d11a02ff5f1a829405 /Lib/test/test_support.py | |
parent | a8b120641bd286bb0be663c5486077e2e61863ba (diff) | |
download | cpython-e334e3ff714502a25c3270bd4cb4d9a699076deb.zip cpython-e334e3ff714502a25c3270bd4cb4d9a699076deb.tar.gz cpython-e334e3ff714502a25c3270bd4cb4d9a699076deb.tar.bz2 |
issue9859: Adds a test.support.detect_api_mismatch function useful to
compare the public APIs of two modules or classes.
Diffstat (limited to 'Lib/test/test_support.py')
-rw-r--r-- | Lib/test/test_support.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index a02d2f4..4a27c44 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -280,6 +280,48 @@ class TestSupport(unittest.TestCase): self.assertEqual(D["item"], 5) self.assertEqual(D["item"], 1) + def test_detect_api_mismatch(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 + + missing_items = support.detect_api_mismatch(RefClass, OtherClass) + self.assertEqual({'attribute1'}, missing_items) + + missing_items = support.detect_api_mismatch(OtherClass, RefClass) + self.assertEqual({'attribute3', '__magic_2__'}, missing_items) + + 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'] + + missing_items = support.detect_api_mismatch(RefClass, OtherClass, + ignore=ignore) + self.assertEqual(set(), missing_items) + + missing_items = support.detect_api_mismatch(OtherClass, RefClass, + ignore=ignore) + self.assertEqual(set(), missing_items) + # XXX -follows a list of untested API # make_legacy_pyc # is_resource_enabled |