annotate test/test_jinja2.py @ 5036:380d8d8b30a3

Replace existing run_tests.py script with a pytest script The existing run_test.py script is quite old, a bit restrictive, and doesn't always behave as documented. The pytest testing tool is mature, well documented, and maintained. The run_tests.py script is generating by installing py.test and running: py.tests --genscript=run_tests.py Note: to generate a script that is compatible with python2.6 the command needs to be run using python2.6
author John Kristensen <john@jerrykan.com>
date Thu, 20 Aug 2015 18:15:23 +1000
parents 63c79c0992ae
children 364c54991861
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4964
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
1 #-*- encoding: utf8 -*-
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
2 """ Testing the jinja2 templating engine of roundup-tracker.
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
3
5009
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
4 Copyright: 2016 Intevation GmbH.
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
5 Author: Bernhard E. Reiter <bernhard@intevation.de>
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
6
4964
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
7 This module is Free Software under the Roundup licensing of 1.5,
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
8 see the COPYING.txt file coming with Roundup.
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
9
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
10 Just a test file template for now.
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
11 """
5009
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
12 import shutil # only, needed for tearDown. TODO: Remove when refactored.
4964
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
13 import unittest
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
14
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
15 import db_test_base
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
16
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
17 TESTSUITE_IDENTIFIER='jinja2'
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
18
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
19 class TestCase_Zero(unittest.TestCase):
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
20 def test_zero(self):
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
21 self.assertEqual(True, True)
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
22
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 5009
diff changeset
23
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 5009
diff changeset
24 class Jinja2Test(object):
5009
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
25 """Sets up and tears down an instance with database contents.
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
26
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
27 Setup and teardown modelled after the use of db_test_base
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
28 by several modules like test_xmlrpc and test_userauditor.
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
29
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
30 TODO: Should probably be moved to a base case in db_test_base.py.
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
31 """
4964
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
32
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
33 backend = None # can be used to create tests per backend, see test_xmlrpc
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
34
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
35 def setUp(self):
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
36 self.dirname = '_test_' + TESTSUITE_IDENTIFIER
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
37 self.instance = db_test_base.setupTracker(self.dirname, self.backend)
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
38 self.db = self.instance.open('admin')
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
39
5009
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
40 def tearDown(self):
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
41 self.db.close()
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
42 try:
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
43 shutil.rmtree(self.dirname)
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
44 except OSError, error:
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
45 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
46
4964
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
47 def test_zero(self):
5009
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
48 """Do nothing just make sure that setup and teardown works."""
4964
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
49 pass
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
50
5009
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
51
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 5009
diff changeset
52 class anydbmJinja2Test(Jinja2Test, unittest.TestCase):
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 5009
diff changeset
53 backend = 'anydbm'
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 5009
diff changeset
54
5009
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
55
4964
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
56 def test_suite():
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
57 suite = unittest.TestSuite()
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
58
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
59 suite.addTest(unittest.makeSuite(TestCase_Zero))
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
60
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
61 # only using one database backend for now, not sure if doing all
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
62 # backends will keep the test focussed enough to be useful for the used
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
63 # computing time. Would be okay to change in the future.
5009
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
64 # for l in list_backends():
5033
63c79c0992ae Update tests to work with py.test
John Kristensen <john@jerrykan.com>
parents: 5009
diff changeset
65 suite.addTest(unittest.makeSuite(anydbmJinja2Test))
4964
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
66
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
67 return suite
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
68
5009
3766e0ca8e7a test_jinja2: stub improved, now with proper teardown.
Bernhard Reiter <bernhard@intevation.de>
parents: 4964
diff changeset
69 # Other roundup test source files have an if __name__ == '__main__': here
4964
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
70 # but I'm not sure if this is still helpful. So left out for now.
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
71
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
72 # vim: ts=4 et sts=4 sw=4 ai :
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
73
2c3cc4ccd024 Automatic tests: added some notes to the readme and a test_jinja2 stub.
Bernhard Reiter <bernhard@intevation.de>
parents:
diff changeset
74

Roundup Issue Tracker: http://roundup-tracker.org/