Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: chrome/test/pyautolib/pyauto.py

Issue 3191014: Produce gtest style output with pyauto. (Closed)
Patch Set: fix on py2.4 Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2010 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """PyAuto: Python Interface to Chromium's Automation Proxy. 7 """PyAuto: Python Interface to Chromium's Automation Proxy.
8 8
9 PyAuto uses swig to expose Automation Proxy interfaces to Python. 9 PyAuto uses swig to expose Automation Proxy interfaces to Python.
10 For complete documentation on the functionality available, 10 For complete documentation on the functionality available,
(...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 1341
1342 def __del__(self): 1342 def __del__(self):
1343 # python unittest module is setup such that the suite gets deleted before 1343 # python unittest module is setup such that the suite gets deleted before
1344 # the test cases, which is odd because our test cases depend on 1344 # the test cases, which is odd because our test cases depend on
1345 # initializtions like exitmanager, autorelease pool provided by the 1345 # initializtions like exitmanager, autorelease pool provided by the
1346 # suite. Forcibly delete the test cases before the suite. 1346 # suite. Forcibly delete the test cases before the suite.
1347 del self._tests 1347 del self._tests
1348 pyautolib.PyUITestSuiteBase.__del__(self) 1348 pyautolib.PyUITestSuiteBase.__del__(self)
1349 1349
1350 1350
1351 class _GTestTextTestResult(unittest._TextTestResult):
1352 """A test result class that can print formatted text results to a stream.
1353
1354 Results printed in conformance with gtest output format, like:
1355 [ RUN ] autofill.AutoFillTest.testAutofillInvalid: "test desc."
1356 [ OK ] autofill.AutoFillTest.testAutofillInvalid
1357 [ RUN ] autofill.AutoFillTest.testFillProfile: "test desc."
1358 [ OK ] autofill.AutoFillTest.testFillProfile
1359 [ RUN ] autofill.AutoFillTest.testFillProfileCrazyCharacters: "Test."
1360 [ OK ] autofill.AutoFillTest.testFillProfileCrazyCharacters
1361 """
1362 def __init__(self, stream, descriptions, verbosity):
1363 unittest._TextTestResult.__init__(self, stream, descriptions, verbosity)
1364
1365 def _GetTestURI(self, test):
1366 if sys.version_info[:2] <= (2, 4):
1367 return '%s.%s' % (unittest._strclass(test.__class__),
1368 test._TestCase__testMethodName)
1369 return '%s.%s' % (unittest._strclass(test.__class__), test._testMethodName)
1370
1371 def getDescription(self, test):
1372 return '%s: "%s"' % (self._GetTestURI(test), test.shortDescription())
1373
1374 def startTest(self, test):
1375 unittest.TestResult.startTest(self, test)
1376 self.stream.writeln('[ RUN ] %s' % self.getDescription(test))
1377
1378 def addSuccess(self, test):
1379 unittest.TestResult.addSuccess(self, test)
1380 self.stream.writeln('[ OK ] %s' % self._GetTestURI(test))
1381
1382 def addError(self, test, err):
1383 unittest.TestResult.addError(self, test, err)
1384 self.stream.writeln('[ ERROR ] %s' % self._GetTestURI(test))
1385
1386 def addFailure(self, test, err):
1387 unittest.TestResult.addFailure(self, test, err)
1388 self.stream.writeln('[ FAILED ] %s' % self._GetTestURI(test))
1389
1390
1391 class PyAutoTextTestRuner(unittest.TextTestRunner):
1392 """Test Runner for PyAuto tests that displays results in textual format.
1393
1394 Results are displayed in conformance with gtest output.
1395 """
1396 def __init__(self, verbosity=1):
1397 unittest.TextTestRunner.__init__(self,
1398 stream=sys.stderr,
1399 verbosity=verbosity)
1400
1401 def _makeResult(self):
1402 return _GTestTextTestResult(self.stream, self.descriptions, self.verbosity)
1403
1404
1351 # Implementation inspired from unittest.main() 1405 # Implementation inspired from unittest.main()
1352 class Main(object): 1406 class Main(object):
1353 """Main program for running PyAuto tests.""" 1407 """Main program for running PyAuto tests."""
1354 1408
1355 _options, _args = None, None 1409 _options, _args = None, None
1356 _tests_filename = 'PYAUTO_TESTS' 1410 _tests_filename = 'PYAUTO_TESTS'
1357 _platform_map = { 1411 _platform_map = {
1358 'win32': 'win', 1412 'win32': 'win',
1359 'darwin': 'mac', 1413 'darwin': 'mac',
1360 'linux2': 'linux', 1414 'linux2': 'linux',
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 # read values back out. 1622 # read values back out.
1569 chrome_flags += ' --dom-automation' 1623 chrome_flags += ' --dom-automation'
1570 1624
1571 suite_args.append('--extra-chrome-flags=%s' % chrome_flags) 1625 suite_args.append('--extra-chrome-flags=%s' % chrome_flags)
1572 pyauto_suite = PyUITestSuite(suite_args) 1626 pyauto_suite = PyUITestSuite(suite_args)
1573 loaded_tests = self._LoadTests(self._args) 1627 loaded_tests = self._LoadTests(self._args)
1574 pyauto_suite.addTests(loaded_tests) 1628 pyauto_suite.addTests(loaded_tests)
1575 verbosity = 1 1629 verbosity = 1
1576 if self._options.verbose: 1630 if self._options.verbose:
1577 verbosity = 2 1631 verbosity = 2
1578 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite) 1632 result = PyAutoTextTestRuner(verbosity=verbosity).run(pyauto_suite)
1579 del loaded_tests # Need to destroy test cases before the suite 1633 del loaded_tests # Need to destroy test cases before the suite
1580 del pyauto_suite 1634 del pyauto_suite
1581 sys.exit(not result.wasSuccessful()) 1635 sys.exit(not result.wasSuccessful())
1582 1636
1583 1637
1584 if __name__ == '__main__': 1638 if __name__ == '__main__':
1585 Main() 1639 Main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698