Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(109)

Side by Side Diff: test.py

Issue 88081: Add testing support for cvs2svn (Closed) SVN Base: http://unladen-swallow.googlecode.com/svn/tests/
Patch Set: Created 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 """Wrapper script for running all of Unladen Swallow's third-party tests. 3 """Wrapper script for running all of Unladen Swallow's third-party tests.
4 4
5 This is equivalent to manually invoking the tests for each third-party app/lib. 5 This is equivalent to manually invoking the tests for each third-party app/lib.
6 Note that this script is intended to be invoked after setup.py install (certain) 6 Note that this script is intended to be invoked after setup.py install (certain)
7 tests depend on it. 7 tests depend on it.
8 """ 8 """
9 9
10 __author__ = "collinwinter@google.com (Collin Winter)" 10 __author__ = "collinwinter@google.com (Collin Winter)"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 95
96 def CallAndCaptureOutput(command, env=None): 96 def CallAndCaptureOutput(command, env=None):
97 """Run the given command, capturing stdout and stderr. 97 """Run the given command, capturing stdout and stderr.
98 98
99 Args: 99 Args:
100 command: the command to run as a list, one argument per element. 100 command: the command to run as a list, one argument per element.
101 env: optional; dict of environment variables to set. 101 env: optional; dict of environment variables to set.
102 102
103 Returns: 103 Returns:
104 The captured stdout + stderr as a string. 104 (output, retcode) where output is captured stdout + stderr as a string;
105 retcode is the process's return code.
105 106
106 Raises: 107 Raises:
107 RuntimeError: if the command failed. The value of the exception will 108 RuntimeError: if the command failed. The value of the exception will
108 be the error message from the command. 109 be the error message from the command.
109 """ 110 """
110 subproc = subprocess.Popen(command, 111 subproc = subprocess.Popen(command,
111 stdout=subprocess.PIPE, 112 stdout=subprocess.PIPE,
112 stderr=subprocess.PIPE, 113 stderr=subprocess.PIPE,
113 env=BuildEnv(env)) 114 env=BuildEnv(env))
114 with BuildBotMollifier(): 115 with BuildBotMollifier():
115 result, err = subproc.communicate() 116 result, err = subproc.communicate()
116 print result + err, 117 print result + err,
117 return result + err 118 return (result + err, subproc.returncode)
118 119
119 120
120 def DefaultPassCheck(command, env=None): 121 def DefaultPassCheck(command, env=None):
121 """Run a test command and check whether it passed. 122 """Run a test command and check whether it passed.
122 123
123 This works for most test suites we run, but not all. Pass/fail is 124 This works for most test suites we run, but not all. Pass/fail is
124 determined by whether the final line of output starts with OK. 125 determined by whether the final line of output starts with OK.
125 126
126 Args: 127 Args:
127 command: the command to run as a list, one argument per element. 128 command: the command to run as a list, one argument per element.
128 env: optional; dict of environment variables to set. 129 env: optional; dict of environment variables to set.
129 130
130 Returns: 131 Returns:
131 True if the test passed, False otherwise. 132 True if the test passed, False otherwise.
132 """ 133 """
133 output = CallAndCaptureOutput(command, env) 134 output, _ = CallAndCaptureOutput(command, env)
134 lines = output.splitlines() 135 lines = output.splitlines()
135 if not lines: 136 if not lines:
136 return False 137 return False
137 return lines[-1].startswith("OK") 138 return lines[-1].startswith("OK")
138 139
139 140
141 def CheckReturnCode(command):
142 output, ret_code = CallAndCaptureOutput(command)
143 return ret_code == 0
144
145
140 ### Wrappers for the third-party modules we don't want to break go here. ### 146 ### Wrappers for the third-party modules we don't want to break go here. ###
141 147
142 def Test2to3(): 148 def Test2to3():
143 return DefaultPassCheck([sys.executable, "-E", "test.py"]) 149 return DefaultPassCheck([sys.executable, "-E", "test.py"])
144 150
145 def TestCheetah(): 151 def TestCheetah():
146 path = os.pathsep.join([os.environ["PATH"], 152 path = os.pathsep.join([os.environ["PATH"],
147 os.path.dirname(sys.executable)]) 153 os.path.dirname(sys.executable)])
148 with ChangeDir(os.path.join("src", "Tests")): 154 with ChangeDir(os.path.join("src", "Tests")):
149 return DefaultPassCheck([sys.executable, "-E", "Test.py"], 155 return DefaultPassCheck([sys.executable, "-E", "Test.py"],
150 env={"PATH": path}) 156 env={"PATH": path})
157
158 def TestCvs2svn():
159 return CheckReturnCode([sys.executable, "-E", "run-tests.py", "-v"])
Jeffrey Yasskin 2009/07/03 05:25:35 We probably want to print the output on failure.
Collin Winter 2009/07/04 03:59:02 On 2009/07/03 05:25:35, Jeffrey Yasskin wrote: > W
151 160
152 def TestDjango(): 161 def TestDjango():
153 py_path = os.path.join("..", "..", "correctness") 162 py_path = os.path.join("..", "..", "correctness")
154 test_runner = os.path.join("tests", "runtests.py") 163 test_runner = os.path.join("tests", "runtests.py")
155 return DefaultPassCheck([sys.executable, test_runner, "-v1", 164 return DefaultPassCheck([sys.executable, test_runner, "-v1",
156 "--settings=django_data.settings"], 165 "--settings=django_data.settings"],
157 env={"PYTHONPATH": py_path}) 166 env={"PYTHONPATH": py_path})
158 167
159 # Mercurial's test are disabled. They fail on Ubuntu Hardy, are flaky on 168 # Mercurial's test are disabled. They fail on Ubuntu Hardy, are flaky on
160 # Dapper and OS X and take forever to run. 169 # Dapper and OS X and take forever to run.
161 # def TestMercurial(): 170 # def TestMercurial():
162 # with ChangeDir("tests"): 171 # with ChangeDir("tests"):
163 # output = CallAndCaptureOutput([sys.executable, "-E", "run-tests.py"]) 172 # output = CallAndCaptureOutput([sys.executable, "-E", "run-tests.py"])
164 # lines = output.splitlines() 173 # lines = output.splitlines()
165 # return lines[-1].endswith(" 0 failed.") 174 # return lines[-1].endswith(" 0 failed.")
166 175
167 def TestNose(): 176 def TestNose():
168 return DefaultPassCheck([sys.executable, "-E", "selftest.py"]) 177 return DefaultPassCheck([sys.executable, "-E", "selftest.py"])
169 178
170 def TestNumpy(): 179 def TestNumpy():
171 # Numpy refuses to be imported from the source directory. 180 # Numpy refuses to be imported from the source directory.
172 with ChangeDir(".."): 181 with ChangeDir(".."):
173 return DefaultPassCheck([sys.executable, "-E", "-c", 182 return DefaultPassCheck([sys.executable, "-E", "-c",
174 "import numpy; numpy.test()"]) 183 "import numpy; numpy.test()"])
175 184
176 def TestPyxml(): 185 def TestPyxml():
177 with ChangeDir("test"): 186 with ChangeDir("test"):
178 output = CallAndCaptureOutput([sys.executable, "-E", "regrtest.py"]) 187 output, _ = CallAndCaptureOutput([sys.executable, "-E", "regrtest.py"])
179 lines = output.splitlines() 188 lines = output.splitlines()
180 return lines[-1].endswith("OK.") 189 return lines[-1].endswith("OK.")
181 190
182 def TestSetuptools(): 191 def TestSetuptools():
183 return DefaultPassCheck([sys.executable, "-E", "setup.py", "test"]) 192 return DefaultPassCheck([sys.executable, "-E", "setup.py", "test"])
184 193
185 def TestSwig(): 194 def TestSwig():
186 ret_code = subprocess.call(["make", "check"]) 195 return CheckReturnCode(["make", "check"])
187 return ret_code == 0
188 196
189 def TestSympy(): 197 def TestSympy():
190 output = CallAndCaptureOutput([sys.executable, "-E", "setup.py", "test"]) 198 output, _ = CallAndCaptureOutput([sys.executable, "-E", "setup.py", "test"])
191 return not output.endswith("DO *NOT* COMMIT!\n") 199 return not output.endswith("DO *NOT* COMMIT!\n")
192 200
193 def TestZope_interface(): 201 def TestZope_interface():
194 # zope.interface is included because Twisted and a number of Zope packages 202 # zope.interface is included because Twisted and a number of Zope packages
195 # depend on it. 203 # depend on it.
196 return DefaultPassCheck([sys.executable, "-E", "setup.py", "test", 204 return DefaultPassCheck([sys.executable, "-E", "setup.py", "test",
197 "-s", "zope.interface.tests"]) 205 "-s", "zope.interface.tests"])
198 206
199 207
200 ### Utility code ### 208 ### Utility code ###
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 tests_passed[test_name] = test_func() 240 tests_passed[test_name] = test_func()
233 finally: 241 finally:
234 os.chdir(current_dir) 242 os.chdir(current_dir)
235 243
236 if all(tests_passed.values()): 244 if all(tests_passed.values()):
237 print "All OK" 245 print "All OK"
238 else: 246 else:
239 failed = [test for (test, passed) in tests_passed.items() if not passed] 247 failed = [test for (test, passed) in tests_passed.items() if not passed]
240 print "FAILED:", failed 248 print "FAILED:", failed
241 sys.exit(1) 249 sys.exit(1)
OLDNEW
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497