Mercurial > p > roundup > code
comparison test/test_jinja2.py @ 5009:3766e0ca8e7a
test_jinja2: stub improved, now with proper teardown.
| author | Bernhard Reiter <bernhard@intevation.de> |
|---|---|
| date | Tue, 05 Jan 2016 22:16:54 +0100 |
| parents | 2c3cc4ccd024 |
| children | 63c79c0992ae |
comparison
equal
deleted
inserted
replaced
| 5008:3b9252085ba9 | 5009:3766e0ca8e7a |
|---|---|
| 1 #-*- encoding: utf8 -*- | 1 #-*- encoding: utf8 -*- |
| 2 """ Testing the jinja2 templating engine of roundup-tracker. | 2 """ Testing the jinja2 templating engine of roundup-tracker. |
| 3 | 3 |
| 4 Copyright 2015 Bernhard E. Reiter <bernhard@intevation.de> | 4 Copyright: 2016 Intevation GmbH. |
| 5 Author: Bernhard E. Reiter <bernhard@intevation.de> | |
| 6 | |
| 5 This module is Free Software under the Roundup licensing of 1.5, | 7 This module is Free Software under the Roundup licensing of 1.5, |
| 6 see the COPYING.txt file coming with Roundup. | 8 see the COPYING.txt file coming with Roundup. |
| 7 | 9 |
| 8 Just a test file template for now. | 10 Just a test file template for now. |
| 9 """ | 11 """ |
| 12 import shutil # only, needed for tearDown. TODO: Remove when refactored. | |
| 10 import unittest | 13 import unittest |
| 11 | 14 |
| 12 import db_test_base | 15 import db_test_base |
| 13 | 16 |
| 14 TESTSUITE_IDENTIFIER='jinja2' | 17 TESTSUITE_IDENTIFIER='jinja2' |
| 16 class TestCase_Zero(unittest.TestCase): | 19 class TestCase_Zero(unittest.TestCase): |
| 17 def test_zero(self): | 20 def test_zero(self): |
| 18 self.assertEqual(True, True) | 21 self.assertEqual(True, True) |
| 19 | 22 |
| 20 class TestCase(unittest.TestCase): | 23 class TestCase(unittest.TestCase): |
| 24 """Sets up and tears down an instance with database contents. | |
| 25 | |
| 26 Setup and teardown modelled after the use of db_test_base | |
| 27 by several modules like test_xmlrpc and test_userauditor. | |
| 28 | |
| 29 TODO: Should probably be moved to a base case in db_test_base.py. | |
| 30 """ | |
| 21 | 31 |
| 22 backend = None # can be used to create tests per backend, see test_xmlrpc | 32 backend = None # can be used to create tests per backend, see test_xmlrpc |
| 23 | 33 |
| 24 def setUp(self): | 34 def setUp(self): |
| 25 self.dirname = '_test_' + TESTSUITE_IDENTIFIER | 35 self.dirname = '_test_' + TESTSUITE_IDENTIFIER |
| 26 self.instance = db_test_base.setupTracker(self.dirname, self.backend) | 36 self.instance = db_test_base.setupTracker(self.dirname, self.backend) |
| 27 self.db = self.instance.open('admin') | 37 self.db = self.instance.open('admin') |
| 28 | 38 |
| 39 def tearDown(self): | |
| 40 self.db.close() | |
| 41 try: | |
| 42 shutil.rmtree(self.dirname) | |
| 43 except OSError, error: | |
| 44 if error.errno not in (errno.ENOENT, errno.ESRCH): raise | |
| 45 | |
| 29 def test_zero(self): | 46 def test_zero(self): |
| 47 """Do nothing just make sure that setup and teardown works.""" | |
| 30 pass | 48 pass |
| 49 | |
| 50 | |
| 31 | 51 |
| 32 def test_suite(): | 52 def test_suite(): |
| 33 suite = unittest.TestSuite() | 53 suite = unittest.TestSuite() |
| 34 | 54 |
| 35 suite.addTest(unittest.makeSuite(TestCase_Zero)) | 55 suite.addTest(unittest.makeSuite(TestCase_Zero)) |
| 36 | 56 |
| 37 # only using one database backend for now, not sure if doing all | 57 # only using one database backend for now, not sure if doing all |
| 38 # backends will keep the test focussed enough to be useful for the used | 58 # backends will keep the test focussed enough to be useful for the used |
| 39 # computing time. Would be okay to change in the future. | 59 # computing time. Would be okay to change in the future. |
| 40 l = 'anydbm' | 60 # for l in list_backends(): |
| 41 dct = dict(backend = l) | 61 for l in ['anydbm']: |
| 42 subcls = type(TestCase)('TestCase_%s'%l, (TestCase,), dct) | 62 dct = dict(backend = l) |
| 43 suite.addTest(unittest.makeSuite(subcls)) | 63 subcls = type(TestCase)('TestCase_%s'%l, (TestCase,), dct) |
| 64 suite.addTest(unittest.makeSuite(subcls)) | |
| 44 | 65 |
| 45 return suite | 66 return suite |
| 46 | 67 |
| 47 # Other roundup testcases do have a def main thing in there, | 68 # Other roundup test source files have an if __name__ == '__main__': here |
| 48 # but I'm not sure if this is still helpful. So left out for now. | 69 # but I'm not sure if this is still helpful. So left out for now. |
| 49 | 70 |
| 50 # vim: ts=4 et sts=4 sw=4 ai : | 71 # vim: ts=4 et sts=4 sw=4 ai : |
| 51 | 72 |
| 52 | 73 |
