~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to mainpage/tests.py

  • Committer: Holger Rapp
  • Date: 2009-02-19 15:31:42 UTC
  • Revision ID: sirver@h566336-20090219153142-dc8xuabldnw5t395
Initial commit of new widelands homepage

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python -tt
2
 
 
3
 
# Load and runs the test from the utest subdirectory
4
 
# your unittests should append ".." to their path to
5
 
# find the files relative to this directory
6
 
 
7
 
import unittest
8
 
from glob import glob
9
 
import os
10
 
import sys
11
 
 
12
 
prefix = ''
13
 
append_path = False
14
 
if __name__ != '__main__':
15
 
    prefix = __name__[:-5]
16
 
    append_path = True
17
 
 
18
 
 
19
 
def suite():
20
 
    # If we are not called directly, we have
21
 
    # to append this path to sys.path so our
22
 
    # subtests will find their files
23
 
    this_dir = os.path.dirname(__file__)
24
 
    if append_path:
25
 
        sys.path.append(this_dir)
26
 
 
27
 
    suite = unittest.TestSuite()
28
 
    l = unittest.TestLoader()
29
 
 
30
 
    dname = os.path.dirname(__file__)
31
 
 
32
 
    for f in glob('%s/utest/*.py' % dname):
33
 
        if os.path.basename(f) == '__init__.py':
34
 
            continue
35
 
 
36
 
        modname = '%sutest.%s' % (prefix, os.path.basename(f)[:-3])
37
 
 
38
 
        # Load tests
39
 
        tests = l.loadTestsFromName(modname)
40
 
        suite.addTests(tests)
41
 
 
42
 
    if append_path:
43
 
        sys.path.remove(this_dir)
44
 
 
45
 
    return suite
46
 
 
47
 
 
48
 
def main():
49
 
    tsuite = suite()
50
 
    runner = unittest.TextTestRunner()
51
 
    runner.run(tsuite)
52
 
    return unittest.TestResult()
53
 
 
54
 
 
55
 
if __name__ == '__main__':
56
 
    main()
 
1
"""
 
2
This file demonstrates two different styles of tests (one doctest and one
 
3
unittest). These will both pass when you run "manage.py test".
 
4
 
 
5
Replace these with more appropriate tests for your application.
 
6
"""
 
7
 
 
8
from django.test import TestCase
 
9
 
 
10
class SimpleTest(TestCase):
 
11
    def test_basic_addition(self):
 
12
        """
 
13
        Tests that 1 + 1 always equals 2.
 
14
        """
 
15
        self.failUnlessEqual(1 + 1, 2)
 
16
 
 
17
__test__ = {"doctest": """
 
18
Another way to test that 1 + 1 is equal to 2.
 
19
 
 
20
>>> 1 + 1 == 2
 
21
True
 
22
"""}
 
23