deluge/deluge/tests/basetest.py
bendikro 178c417fb0 [Core] [Tests] Changes to component.shutdown and unit tests
* component registry shutdown() now cleans up the component list
  this ensures that no old components are left when running unit
  tests.

* Added class BaseTestCase that all tests that create components
  should inherit from. It verifies the compoent list before and
  after the tests are run.
2014-12-01 10:52:08 +00:00

38 lines
1.3 KiB
Python

import warnings
from twisted.internet.defer import maybeDeferred
from twisted.trial import unittest
import deluge.component as component
class BaseTestCase(unittest.TestCase):
"""This is the base class that should be used for all test classes
that create classes that inherit from deluge.component.Component. It
ensures that the component registry has been cleaned up when tests
have finished.
"""
def setUp(self): # NOQA
if len(component._ComponentRegistry.components) != 0:
warnings.warn("The component._ComponentRegistry.components is not empty on test setup."
"This is probably caused by another test that didn't clean up after finishing!: %s" %
component._ComponentRegistry.components)
return self.set_up()
def tearDown(self): # NOQA
d = maybeDeferred(self.tear_down)
def on_teared_down(result):
if len(component._ComponentRegistry.components) != 0:
warnings.warn("The component._ComponentRegistry.components is not empty after the test finished!: %s" %
component._ComponentRegistry.components)
return d.addCallback(on_teared_down)
def set_up(self):
pass
def tear_down(self):
pass