Merge lp:~mike-amy/sahana-eden/test_framework into lp:sahana-eden

Proposed by Mike Amy
Status: Merged
Merged at revision: 2644
Proposed branch: lp:~mike-amy/sahana-eden/test_framework
Merge into: lp:sahana-eden
Diff against target: 162 lines (+83/-24)
4 files modified
modules/test_utils/__init__.py (+2/-0)
modules/test_utils/compare_lines.py (+15/-0)
modules/test_utils/run.py (+60/-23)
tests/nose.py (+6/-1)
To merge this branch: bzr merge lp:~mike-amy/sahana-eden/test_framework
Reviewer Review Type Date Requested Status
Fran Boon Pending
Review via email: mp+71261@code.launchpad.net

Description of the change

moved run.py out of tests folder
(=> less confusion as to what to run)

Workaround for an issue in nose where our adjusted arguments are ignored if not read from sys.argv.
(=> nose plugins work, e.g. coverage)

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'modules/test_utils'
2=== added file 'modules/test_utils/__init__.py'
3--- modules/test_utils/__init__.py 1970-01-01 00:00:00 +0000
4+++ modules/test_utils/__init__.py 2011-08-11 19:33:44 +0000
5@@ -0,0 +1,2 @@
6+
7+from compare_lines import compare_lines
8\ No newline at end of file
9
10=== added file 'modules/test_utils/compare_lines.py'
11--- modules/test_utils/compare_lines.py 1970-01-01 00:00:00 +0000
12+++ modules/test_utils/compare_lines.py 2011-08-11 19:33:44 +0000
13@@ -0,0 +1,15 @@
14+
15+
16+def compare_lines(test, expected, actual):
17+ line = 1
18+ expected_lines = expected.split('\n')
19+ actual_lines = actual.split('\n')
20+ for expected_line, actual_line in zip(expected_lines, actual_lines):
21+ test.assertEquals(
22+ actual_line,
23+ expected_line,
24+ "%s: '%s' != '%s'" % (line, actual_line, expected_line)
25+ )
26+ line += 1
27+ test.assertEquals(len(expected_lines), len(actual_lines))
28+
29
30=== renamed file 'tests/run.py' => 'modules/test_utils/run.py'
31--- tests/run.py 2011-08-11 16:22:44 +0000
32+++ modules/test_utils/run.py 2011-08-11 19:33:44 +0000
33@@ -126,9 +126,9 @@
34 log = sys.stderr.write
35
36 import unittest
37-
38-
39-test_folder = os.path.join("applications", application_name, "tests", "unit_tests")
40+from itertools import imap
41+
42+test_folders = set()
43
44 class Web2pyNosePlugin(nose.plugins.base.Plugin):
45 # see: http://somethingaboutorange.com/mrl/projects/nose/0.11.1/plugins/writing.html
46@@ -157,6 +157,7 @@
47
48 def options(self, parser, env):
49 """Register command line options"""
50+ return
51 parser.add_option(
52 "--web2py",
53 dest="web2py",
54@@ -169,14 +170,9 @@
55 return bool(re.search(self.directory_pattern, dirname))
56
57 def wantFile(self, file_name):
58- if file_name.endswith(
59- os.path.join(test_folder, "run.py")
60- ) or file_name.endswith(
61- os.path.join(test_folder, "nose.py")
62- ):
63- return False
64- else:
65- return test_folder in file_name and file_name.endswith(".py")
66+ return file_name.endswith(".py") and any(
67+ imap(file_name.__contains__, test_folders)
68+ )
69
70 def wantModule(self, module):
71 return False
72@@ -247,19 +243,60 @@
73
74 import re
75
76+argv = [
77+ #"--verbosity=2",
78+ #"--debug=nose"
79+]
80+
81+# folder in which tests are kept
82+# non-option arguments (test paths) are made relative to this
83+test_root = os.path.join("applications", application_name, "tests", "unit_tests")
84+
85+disallowed_options = {}
86+disallowed_options["-w"] = disallowed_options["--where"] = (
87+ "web2py does not allow changing directory"
88+)
89+for arg in sys.argv[1:]:
90+ if arg.startswith("-"):
91+ if not arg.startswith("--"):
92+ print (
93+ "\nSorry, please use verbose option names "
94+ "(currently need this to distinguish options from paths)"
95+ )
96+ sys.exit(1)
97+ else:
98+ try:
99+ reason = disallowed_options[arg]
100+ except KeyError:
101+ pass
102+ else:
103+ print "\nSorry, %s option is not accepted as %s" % (arg, reason)
104+ sys.exit(1)
105+ argv.append(arg)
106+ else:
107+ test_path = arg
108+ test_fuller_path = os.path.join(test_root, test_path)
109+ test_folders.add(test_fuller_path)
110+ if not os.path.exists(test_fuller_path):
111+ print "\n", test_fuller_path, "not found"
112+ #sys.exit(1)
113+
114+# test paths in command line aren't passed, just added to test_folders
115+# the plugin does the testing
116+# nose just searches everything from the test_root
117+# so we give it the test root
118+argv.append(test_root)
119+
120+# if no test folders are given, assume we test everything from the test_root
121+if len(test_folders) == 0:
122+ test_folders.add(test_root)
123+
124+sys.argv[1:] = argv
125+
126 nose.main(
127- argv = [
128- "--verbosity=2",
129- #"--debug=nose"
130- ] + map((
131- lambda test_path:
132- os.path.join(
133- "applications", application_name, "tests", "unit_tests", test_path
134- )
135- ),
136- sys.argv[1:]
137- ),
138- plugins = nose.plugins.PluginManager([
139+# seems at least this version of nose ignores passed in argv
140+# argv = argv,
141+ addplugins = nose.plugins.PluginManager([
142 Web2pyNosePlugin(
143 application_name,
144 globals(),
145
146=== modified file 'tests/nose.py'
147--- tests/nose.py 2011-07-23 18:41:53 +0000
148+++ tests/nose.py 2011-08-11 19:33:44 +0000
149@@ -21,7 +21,12 @@
150 join("..","..","..","web2py.py"),
151 "--shell=" + application_name,
152 "--import_models",
153- "--run "+join("applications",application_name,"tests","run.py"),
154+
155+ "--run "+join(
156+ # the code that makes all the test folders relative to
157+ # tests/unit_tests is in modules/test_utils/run.py
158+ "applications",application_name,"modules","test_utils","run.py"
159+ ),
160 "--args"
161 ] + sys.argv[1:] # nose arguments
162 )