Commit 4e8eb1c6 authored by Tres Seaver's avatar Tres Seaver

Coverage for App.ApplicationManager.DebugManager.

parent c8d43b40
......@@ -129,6 +129,119 @@ class DatabaseChooserTests(unittest.TestCase):
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 @@ class DummyDBTab:
return self._databases[name]
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(FakeConnectionTests),
unittest.makeSuite(DatabaseChooserTests),
unittest.makeSuite(DebugManagerTests),
))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment