webfaction and repo.or.cz deployment done
[worddb.git] / libs / dmigrations / tests / common.py
blob790724d0f97508fb6abceb555a4fac7e0683f57b
1 import os.path
2 import unittest
3 from dmigrations.exceptions import *
5 class WarningsMocker(object):
6 def __init__(self):
7 self.warnings = []
8 def __call__(self, warning):
9 self.warnings.append(warning)
11 class TestCase(unittest.TestCase):
12 """
13 Common code, and Pythonic (underscored) names support, instead of ugly javaCamelCase.
14 """
15 def assert_attrs(self, obj, **kwargs):
16 for key in sorted(kwargs.keys()):
17 expected = kwargs[key]
18 actual = getattr(obj, key)
19 self.assert_equal(expected, actual, u"Object's %s expected to be `%s', is `%s' instead" % (key, expected, actual))
21 def assert_raises(self, expected_exception_class, code):
22 try:
23 code()
24 self.assert_(False, u"Exception %s expected, but no exception raised" % expected_exception_class)
25 except Exception, e:
26 if isinstance(e, expected_exception_class):
27 self.assert_(True)
28 else:
29 raise # Assert false or raise an error is better ?
30 self.assert_(False, u"Exception %s expected, `%s' exception raised instead" % (expected_exception_class, e))
32 def assert_equal(self, *args, **kwargs):
33 self.assertEqual(*args, **kwargs)
35 def setUp(self):
36 self.mock_migrations_dir = os.path.join(os.path.dirname(__file__), "mock_migrations_dir")
37 self.set_up()
39 def set_up(self):
40 pass
42 def tearDown(self):
43 self.tear_down()
45 def tear_down(self):
46 pass