| OLD | NEW |
| 1 # Copyright (C) 2012 Google, Inc. | 1 # Copyright (C) 2012 Google, Inc. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions | 4 # modification, are permitted provided that the following conditions |
| 5 # are met: | 5 # are met: |
| 6 # 1. Redistributions of source code must retain the above copyright | 6 # 1. Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # 2. Redistributions in binary form must reproduce the above copyright | 8 # 2. Redistributions in binary form must reproduce the above copyright |
| 9 # notice, this list of conditions and the following disclaimer in the | 9 # notice, this list of conditions and the following disclaimer in the |
| 10 # documentation and/or other materials provided with the distribution. | 10 # documentation and/or other materials provided with the distribution. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 21 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 22 | 22 |
| 23 import logging | 23 import logging |
| 24 import sys | 24 import sys |
| 25 import webkitpy.thirdparty.unittest2 as unittest | 25 import webkitpy.thirdparty.unittest2 as unittest |
| 26 import StringIO | 26 import StringIO |
| 27 | 27 |
| 28 from webkitpy.common.system.filesystem import FileSystem | 28 from webkitpy.common.system.filesystem import FileSystem |
| 29 from webkitpy.common.system.executive import Executive | 29 from webkitpy.common.system.executive import Executive |
| 30 from webkitpy.common.system.outputcapture import OutputCapture | 30 from webkitpy.common.system.outputcapture import OutputCapture |
| 31 from webkitpy.test.main import Tester, _Loader | 31 from webkitpy.test.main import Tester |
| 32 | 32 |
| 33 | 33 |
| 34 STUBS_CLASS = __name__ + ".TestStubs" | 34 STUBS_CLASS = __name__ + ".TestStubs" |
| 35 | 35 |
| 36 | 36 |
| 37 class TestStubs(unittest.TestCase): | 37 class TestStubs(unittest.TestCase): |
| 38 def test_empty(self): | 38 def test_empty(self): |
| 39 pass | 39 pass |
| 40 | 40 |
| 41 def integration_test_empty(self): | |
| 42 pass | |
| 43 | |
| 44 | 41 |
| 45 class TesterTest(unittest.TestCase): | 42 class TesterTest(unittest.TestCase): |
| 46 | 43 |
| 47 def test_no_tests_found(self): | 44 def test_no_tests_found(self): |
| 48 tester = Tester() | 45 tester = Tester() |
| 49 errors = StringIO.StringIO() | 46 errors = StringIO.StringIO() |
| 50 | 47 |
| 51 # Here we need to remove any existing log handlers so that they | 48 # Here we need to remove any existing log handlers so that they |
| 52 # don't log the messages webkitpy.test while we're testing it. | 49 # don't log the messages webkitpy.test while we're testing it. |
| 53 root_logger = logging.getLogger() | 50 root_logger = logging.getLogger() |
| (...skipping 12 matching lines...) Expand all Loading... |
| 66 _, _, logs = oc.restore_output() | 63 _, _, logs = oc.restore_output() |
| 67 root_logger.handlers = root_handlers | 64 root_logger.handlers = root_handlers |
| 68 sys.argv = orig_argv | 65 sys.argv = orig_argv |
| 69 | 66 |
| 70 self.assertIn('No tests to run', errors.getvalue()) | 67 self.assertIn('No tests to run', errors.getvalue()) |
| 71 self.assertIn('No tests to run', logs) | 68 self.assertIn('No tests to run', logs) |
| 72 | 69 |
| 73 def _find_test_names(self, args): | 70 def _find_test_names(self, args): |
| 74 tester = Tester() | 71 tester = Tester() |
| 75 tester._options, args = tester._parse_args(args) | 72 tester._options, args = tester._parse_args(args) |
| 76 return tester._test_names(_Loader(), args) | 73 return tester._test_names(unittest.TestLoader(), args) |
| 77 | 74 |
| 78 def test_individual_names_are_not_run_twice(self): | 75 def test_individual_names_are_not_run_twice(self): |
| 79 args = [STUBS_CLASS + '.test_empty'] | 76 args = [STUBS_CLASS + '.test_empty'] |
| 80 tests = self._find_test_names(args) | 77 tests = self._find_test_names(args) |
| 81 self.assertEqual(tests, args) | 78 self.assertEqual(tests, args) |
| 82 | 79 |
| 83 def test_integration_tests_are_not_found_by_default(self): | |
| 84 tests = self._find_test_names([STUBS_CLASS]) | |
| 85 self.assertEqual(tests, [STUBS_CLASS + '.test_empty']) | |
| 86 | |
| 87 def test_integration_tests_are_found(self): | |
| 88 tests = self._find_test_names(['--integration-tests', STUBS_CLASS]) | |
| 89 self.assertEqual(tests, [ | |
| 90 STUBS_CLASS + '.integration_test_empty', | |
| 91 STUBS_CLASS + '.test_empty', | |
| 92 ]) | |
| 93 | |
| 94 def test_coverage_works(self): | 80 def test_coverage_works(self): |
| 95 # This is awkward; by design, running test-webkitpy -c will | 81 # This is awkward; by design, running test-webkitpy -c will |
| 96 # create a .coverage file in Tools/Scripts, so we need to be | 82 # create a .coverage file in Tools/Scripts, so we need to be |
| 97 # careful not to clobber an existing one, and to clean up. | 83 # careful not to clobber an existing one, and to clean up. |
| 98 # FIXME: This design needs to change since it means we can't actually | 84 # FIXME: This design needs to change since it means we can't actually |
| 99 # run this method itself under coverage properly. | 85 # run this method itself under coverage properly. |
| 100 filesystem = FileSystem() | 86 filesystem = FileSystem() |
| 101 executive = Executive() | 87 executive = Executive() |
| 102 module_path = filesystem.path_to_module(self.__module__) | 88 module_path = filesystem.path_to_module(self.__module__) |
| 103 script_dir = module_path[0:module_path.find('webkitpy') - 1] | 89 script_dir = module_path[0:module_path.find('webkitpy') - 1] |
| 104 coverage_file = filesystem.join(script_dir, '.coverage') | 90 coverage_file = filesystem.join(script_dir, '.coverage') |
| 105 coverage_file_orig = None | 91 coverage_file_orig = None |
| 106 if filesystem.exists(coverage_file): | 92 if filesystem.exists(coverage_file): |
| 107 coverage_file_orig = coverage_file + '.orig' | 93 coverage_file_orig = coverage_file + '.orig' |
| 108 filesystem.move(coverage_file, coverage_file_orig) | 94 filesystem.move(coverage_file, coverage_file_orig) |
| 109 | 95 |
| 110 try: | 96 try: |
| 111 proc = executive.popen([sys.executable, filesystem.join(script_dir,
'test-webkitpy'), '-c', STUBS_CLASS + '.test_empty'], | 97 proc = executive.popen([sys.executable, filesystem.join(script_dir,
'test-webkitpy'), '-c', STUBS_CLASS + '.test_empty'], |
| 112 stdout=executive.PIPE, stderr=executive.PIPE) | 98 stdout=executive.PIPE, stderr=executive.PIPE) |
| 113 out, _ = proc.communicate() | 99 out, _ = proc.communicate() |
| 114 retcode = proc.returncode | 100 retcode = proc.returncode |
| 115 self.assertEqual(retcode, 0) | 101 self.assertEqual(retcode, 0) |
| 116 self.assertIn('Cover', out) | 102 self.assertIn('Cover', out) |
| 117 finally: | 103 finally: |
| 118 if coverage_file_orig: | 104 if coverage_file_orig: |
| 119 filesystem.move(coverage_file_orig, coverage_file) | 105 filesystem.move(coverage_file_orig, coverage_file) |
| 120 elif filesystem.exists(coverage_file): | 106 elif filesystem.exists(coverage_file): |
| 121 filesystem.remove(coverage_file) | 107 filesystem.remove(coverage_file) |
| OLD | NEW |