source: nappy/trunk/nappy/unit_tests/make_unit_tests.py @ 3339

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/nappy/unit_tests/make_unit_tests.py@3339
Revision 3339, 1.4 KB checked in by astephen, 12 years ago (diff)
Line 
1#!/usr/bin/env python
2
3"""
4make_unit_tests.py
5==================
6
7Simple script for making basic unit test stubs for a given directory full of python files.
8
9"""
10
11# Import standard library modules
12import sys
13import glob
14import os
15
16template = """\"\"\"
17test_%s
18==================
19
20Tests for the %s module.
21
22\"\"\"
23
24# Import standard library modules
25import unittest
26
27# Import local modules
28import
29
30class TestCase(unittest.TestCase):
31
32    def setUp(self):
33        self. = ()
34
35    def test_(self):
36        "Tests ."
37        data = self.()
38        self.assertEqual()
39        self.assert()                           
40
41
42if __name__ ==  "__main__":
43
44    unittest.main()
45
46"""
47
48def makeUnitTestModule(dr, include_init=False):
49    """
50    Makes a unit test module for each module in a directory. It excludes
51    __init__.py unless you set include_init to True.
52    """
53    cwd = os.getcwd()
54    glob_pattn = os.path.join(dr, "*.py")
55    mods = glob.glob(glob_pattn)
56   
57    for mod in mods:
58        mod_name = os.path.split(mod)[-1]
59        content = template % (mod_name, mod_name)
60        ut_name = "test_%s" % mod_name
61        ut_file = open(ut_name, "w").write(content)
62        print "Wrote:", ut_name
63
64
65if __name__ == "__main__":
66
67    dirs = sys.argv[1:]
68    dirs = ["C:\\Documents and Settings\\as56\\Desktop\\nappy_svn\\nappy\\na_file"]
69    for dr in dirs:
70        makeUnitTestModule(dr)
Note: See TracBrowser for help on using the repository browser.