OLD | NEW |
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 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 self._ParseArgs() | 657 self._ParseArgs() |
658 self._Run() | 658 self._Run() |
659 | 659 |
660 def _ParseArgs(self): | 660 def _ParseArgs(self): |
661 """Parse command line args.""" | 661 """Parse command line args.""" |
662 parser = optparse.OptionParser() | 662 parser = optparse.OptionParser() |
663 parser.add_option( | 663 parser.add_option( |
664 '-v', '--verbose', action='store_true', default=False, | 664 '-v', '--verbose', action='store_true', default=False, |
665 help='Make PyAuto verbose.') | 665 help='Make PyAuto verbose.') |
666 parser.add_option( | 666 parser.add_option( |
| 667 '', '--log-file', type='string', default=None, |
| 668 help='Provide a path to a file to which the logger will log') |
| 669 parser.add_option( |
667 '-D', '--wait-for-debugger', action='store_true', default=False, | 670 '-D', '--wait-for-debugger', action='store_true', default=False, |
668 help='Block PyAuto on startup for attaching debugger.') | 671 help='Block PyAuto on startup for attaching debugger.') |
669 parser.add_option( | 672 parser.add_option( |
670 '', '--chrome-flags', type='string', default='', | 673 '', '--chrome-flags', type='string', default='', |
671 help='Flags passed to Chrome. This is in addition to the usual flags ' | 674 help='Flags passed to Chrome. This is in addition to the usual flags ' |
672 'like suppressing first-run dialogs, enabling automation. ' | 675 'like suppressing first-run dialogs, enabling automation. ' |
673 'See chrome/common/chrome_switches.cc for the list of flags ' | 676 'See chrome/common/chrome_switches.cc for the list of flags ' |
674 'chrome understands.') | 677 'chrome understands.') |
675 parser.add_option( | 678 parser.add_option( |
676 '', '--list-missing-tests', action='store_true', default=False, | 679 '', '--list-missing-tests', action='store_true', default=False, |
677 help='Print a list of tests not included in PYAUTO_TESTS, and exit') | 680 help='Print a list of tests not included in PYAUTO_TESTS, and exit') |
678 parser.add_option( | 681 parser.add_option( |
679 '', '--repeat', type='int', default=1, | 682 '', '--repeat', type='int', default=1, |
680 help='Number of times to repeat the tests. Useful to determine ' | 683 help='Number of times to repeat the tests. Useful to determine ' |
681 'flakiness. Defaults to 1.') | 684 'flakiness. Defaults to 1.') |
682 | 685 |
683 self._options, self._args = parser.parse_args() | 686 self._options, self._args = parser.parse_args() |
684 | 687 |
685 # Setup logging | 688 # Setup logging - start with defaults |
| 689 level = logging.WARNING |
| 690 format = None |
| 691 |
686 if self._options.verbose: | 692 if self._options.verbose: |
687 logging.basicConfig(level=logging.DEBUG, | 693 level=logging.DEBUG |
688 format='%(asctime)s %(levelname)-8s %(message)s') | 694 format='%(asctime)s %(levelname)-8s %(message)s' |
| 695 |
| 696 logging.basicConfig(level=level, format=format, |
| 697 filename=self._options.log_file) |
| 698 |
689 if self._options.list_missing_tests: | 699 if self._options.list_missing_tests: |
690 self._ListMissingTests() | 700 self._ListMissingTests() |
691 sys.exit(0) | 701 sys.exit(0) |
692 | 702 |
693 def TestsDir(self): | 703 def TestsDir(self): |
694 """Returns the path to dir containing tests. | 704 """Returns the path to dir containing tests. |
695 | 705 |
696 This is typically the dir containing the tests description file. | 706 This is typically the dir containing the tests description file. |
697 This method should be overridden by derived class to point to other dirs | 707 This method should be overridden by derived class to point to other dirs |
698 if needed. | 708 if needed. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 if self._options.verbose: | 853 if self._options.verbose: |
844 verbosity = 2 | 854 verbosity = 2 |
845 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite) | 855 result = unittest.TextTestRunner(verbosity=verbosity).run(pyauto_suite) |
846 del loaded_tests # Need to destroy test cases before the suite | 856 del loaded_tests # Need to destroy test cases before the suite |
847 del pyauto_suite | 857 del pyauto_suite |
848 sys.exit(not result.wasSuccessful()) | 858 sys.exit(not result.wasSuccessful()) |
849 | 859 |
850 | 860 |
851 if __name__ == '__main__': | 861 if __name__ == '__main__': |
852 Main() | 862 Main() |
OLD | NEW |