[Zope-Checkins] SVN: Zope/trunk/src/App/tests/test_ApplicationManager.py Coverage for App.ApplicationManager.DebugManager.
Tres Seaver
tseaver at palladion.com
Wed Apr 7 21:21:29 EDT 2010
Log message for revision 110619:
Coverage for App.ApplicationManager.DebugManager.
Changed:
U Zope/trunk/src/App/tests/test_ApplicationManager.py
-=-
Modified: Zope/trunk/src/App/tests/test_ApplicationManager.py
===================================================================
--- Zope/trunk/src/App/tests/test_ApplicationManager.py 2010-04-08 01:21:26 UTC (rev 110618)
+++ Zope/trunk/src/App/tests/test_ApplicationManager.py 2010-04-08 01:21:28 UTC (rev 110619)
@@ -129,6 +129,119 @@
self.assertEqual(values[2]._p_jar, None)
+class DebugManagerTests(unittest.TestCase):
+
+ def setUp(self):
+ import sys
+ self._sys = sys
+ self._old_sys_modules = sys.modules.copy()
+
+ def tearDown(self):
+ self._sys.modules.clear()
+ self._sys.modules.update(self._old_sys_modules)
+
+ def _getTargetClass(self):
+ from App.ApplicationManager import DebugManager
+ return DebugManager
+
+ def _makeOne(self, id):
+ return self._getTargetClass()(id)
+
+ def _makeModuleClasses(self):
+ import sys
+ import types
+ from ExtensionClass import Base
+ class Foo(Base):
+ pass
+ class Bar(Base):
+ pass
+ class Baz(Base):
+ pass
+ foo = sys.modules['foo'] = types.ModuleType('foo')
+ foo.Foo = Foo
+ Foo.__module__ = 'foo'
+ foo.Bar = Bar
+ Bar.__module__ = 'foo'
+ qux = sys.modules['qux'] = types.ModuleType('qux')
+ qux.Baz = Baz
+ Baz.__module__ = 'qux'
+ return Foo, Bar, Baz
+
+ def test_refcount_no_limit(self):
+ import sys
+ dm = self._makeOne('test')
+ Foo, Bar, Baz = self._makeModuleClasses()
+ pairs = dm.refcount()
+ # XXX : Ugly empiricism here: I don't know why the count is up 1.
+ foo_count = sys.getrefcount(Foo)
+ self.failUnless((foo_count+1, 'foo.Foo') in pairs)
+ bar_count = sys.getrefcount(Bar)
+ self.failUnless((bar_count+1, 'foo.Bar') in pairs)
+ baz_count = sys.getrefcount(Baz)
+ self.failUnless((baz_count+1, 'qux.Baz') in pairs)
+
+ def test_refdict(self):
+ import sys
+ dm = self._makeOne('test')
+ Foo, Bar, Baz = self._makeModuleClasses()
+ mapping = dm.refdict()
+ # XXX : Ugly empiricism here: I don't know why the count is up 1.
+ foo_count = sys.getrefcount(Foo)
+ self.assertEqual(mapping['foo.Foo'], foo_count+1)
+ bar_count = sys.getrefcount(Bar)
+ self.assertEqual(mapping['foo.Bar'], bar_count+1)
+ baz_count = sys.getrefcount(Baz)
+ self.assertEqual(mapping['qux.Baz'], baz_count+1)
+
+ def test_rcsnapshot(self):
+ import sys
+ import App.ApplicationManager
+ from DateTime.DateTime import DateTime
+ dm = self._makeOne('test')
+ Foo, Bar, Baz = self._makeModuleClasses()
+ before = DateTime()
+ dm.rcsnapshot()
+ after = DateTime()
+ # XXX : Ugly empiricism here: I don't know why the count is up 1.
+ self.failUnless(before <= App.ApplicationManager._v_rst <= after)
+ mapping = App.ApplicationManager._v_rcs
+ foo_count = sys.getrefcount(Foo)
+ self.assertEqual(mapping['foo.Foo'], foo_count+1)
+ bar_count = sys.getrefcount(Bar)
+ self.assertEqual(mapping['foo.Bar'], bar_count+1)
+ baz_count = sys.getrefcount(Baz)
+ self.assertEqual(mapping['qux.Baz'], baz_count+1)
+
+ def test_rcdate(self):
+ import App.ApplicationManager
+ dummy = object()
+ App.ApplicationManager._v_rst = dummy
+ dm = self._makeOne('test')
+ found = dm.rcdate()
+ App.ApplicationManager._v_rst = None
+ self.failUnless(found is dummy)
+
+ def test_rcdeltas(self):
+ dm = self._makeOne('test')
+ dm.rcsnapshot()
+ Foo, Bar, Baz = self._makeModuleClasses()
+ mappings = dm.rcdeltas()
+ self.assertEqual(len(mappings), 1)
+ mapping = mappings[0]
+ self.assertEqual(mapping['name'], 'ExtensionClass.Base')
+ self.failUnless('rc' in mapping)
+ self.failUnless('pc' in mapping)
+ self.assertEqual(mapping['delta'], mapping['rc'] - mapping['pc'])
+
+ #def test_dbconnections(self): XXX -- TOO UGLY TO TEST
+ #def test_manage_profile_stats(self): XXX -- TOO UGLY TO TEST
+
+ def test_manage_getSysPath(self):
+ import sys
+ dm = self._makeOne('test')
+ self.assertEqual(dm.manage_getSysPath(), list(sys.path))
+
+
class DummyDBTab:
def __init__(self, databases=None):
self._databases = databases or {}
@@ -143,9 +256,9 @@
return self._databases[name]
-
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(FakeConnectionTests),
unittest.makeSuite(DatabaseChooserTests),
+ unittest.makeSuite(DebugManagerTests),
))
More information about the Zope-Checkins
mailing list