summaryrefslogtreecommitdiff
path: root/src/zope/interface/tests/test_ro.py
diff options
context:
space:
mode:
authorJason Madden <jamadden@gmail.com>2020-03-17 08:28:12 -0500
committerJason Madden <jamadden@gmail.com>2020-03-17 15:14:37 -0500
commit7e532de0bc9475294d2dcfd7ebea50a80cb8c7f7 (patch)
tree8204bf08f3af554c58a5dd28baefc8909faa954c /src/zope/interface/tests/test_ro.py
parent11a1d01945fd486ba63209f3358fd3313ff1e25f (diff)
downloadzope-interface-issue8.tar.gz
Move the one-base optimization down a level, and enable using pre-calculated __sro__ for caching.issue8
In my local 'load the world' test, this went from ~7800 full C3 merges to about ~1100. Also take steps to avoid triggering false positive warnings about changed ROs when it's *just* Interface that moved.
Diffstat (limited to 'src/zope/interface/tests/test_ro.py')
-rw-r--r--src/zope/interface/tests/test_ro.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/zope/interface/tests/test_ro.py b/src/zope/interface/tests/test_ro.py
index 3a516b5..ce0a6f4 100644
--- a/src/zope/interface/tests/test_ro.py
+++ b/src/zope/interface/tests/test_ro.py
@@ -375,6 +375,27 @@ Object <InterfaceClass zope.interface.tests.test_ro.A> has different legacy and
self.assertEqual(iro, legacy_iro)
+class TestC3(unittest.TestCase):
+ def _makeOne(self, C, strict=False, base_mros=None):
+ from zope.interface.ro import C3
+ return C3.resolver(C, strict, base_mros)
+
+ def test_base_mros_given(self):
+ c3 = self._makeOne(type(self), base_mros={unittest.TestCase: unittest.TestCase.__mro__})
+ memo = c3.memo
+ self.assertIn(unittest.TestCase, memo)
+ # We used the StaticMRO class
+ self.assertIsNone(memo[unittest.TestCase].had_inconsistency)
+
+ def test_one_base_optimization(self):
+ c3 = self._makeOne(type(self))
+ # Even though we didn't call .mro() yet, the MRO has been
+ # computed.
+ self.assertIsNotNone(c3._C3__mro) # pylint:disable=no-member
+ c3._merge = None
+ self.assertEqual(c3.mro(), list(type(self).__mro__))
+
+
class Test_ROComparison(unittest.TestCase):
class MockC3(object):