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 23 matching lines...) Expand all Loading... |
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): | 41 def integration_test_empty(self): |
42 pass | 42 pass |
43 | 43 |
44 def serial_test_empty(self): | |
45 pass | |
46 | |
47 def serial_integration_test_empty(self): | |
48 pass | |
49 | |
50 | 44 |
51 class TesterTest(unittest.TestCase): | 45 class TesterTest(unittest.TestCase): |
52 | 46 |
53 def test_no_tests_found(self): | 47 def test_no_tests_found(self): |
54 tester = Tester() | 48 tester = Tester() |
55 errors = StringIO.StringIO() | 49 errors = StringIO.StringIO() |
56 | 50 |
57 # Here we need to remove any existing log handlers so that they | 51 # Here we need to remove any existing log handlers so that they |
58 # don't log the messages webkitpy.test while we're testing it. | 52 # don't log the messages webkitpy.test while we're testing it. |
59 root_logger = logging.getLogger() | 53 root_logger = logging.getLogger() |
(...skipping 16 matching lines...) Expand all Loading... |
76 self.assertIn('No tests to run', errors.getvalue()) | 70 self.assertIn('No tests to run', errors.getvalue()) |
77 self.assertIn('No tests to run', logs) | 71 self.assertIn('No tests to run', logs) |
78 | 72 |
79 def _find_test_names(self, args): | 73 def _find_test_names(self, args): |
80 tester = Tester() | 74 tester = Tester() |
81 tester._options, args = tester._parse_args(args) | 75 tester._options, args = tester._parse_args(args) |
82 return tester._test_names(_Loader(), args) | 76 return tester._test_names(_Loader(), args) |
83 | 77 |
84 def test_individual_names_are_not_run_twice(self): | 78 def test_individual_names_are_not_run_twice(self): |
85 args = [STUBS_CLASS + '.test_empty'] | 79 args = [STUBS_CLASS + '.test_empty'] |
86 parallel_tests, serial_tests = self._find_test_names(args) | 80 tests = self._find_test_names(args) |
87 self.assertEqual(parallel_tests, args) | 81 self.assertEqual(tests, args) |
88 self.assertEqual(serial_tests, []) | |
89 | 82 |
90 def test_integration_tests_are_not_found_by_default(self): | 83 def test_integration_tests_are_not_found_by_default(self): |
91 parallel_tests, serial_tests = self._find_test_names([STUBS_CLASS]) | 84 tests = self._find_test_names([STUBS_CLASS]) |
92 self.assertEqual(parallel_tests, [ | 85 self.assertEqual(tests, [STUBS_CLASS + '.test_empty']) |
93 STUBS_CLASS + '.test_empty', | |
94 ]) | |
95 self.assertEqual(serial_tests, [ | |
96 STUBS_CLASS + '.serial_test_empty', | |
97 ]) | |
98 | 86 |
99 def test_integration_tests_are_found(self): | 87 def test_integration_tests_are_found(self): |
100 parallel_tests, serial_tests = self._find_test_names(['--integration-tes
ts', STUBS_CLASS]) | 88 tests = self._find_test_names(['--integration-tests', STUBS_CLASS]) |
101 self.assertEqual(parallel_tests, [ | 89 self.assertEqual(tests, [ |
102 STUBS_CLASS + '.integration_test_empty', | 90 STUBS_CLASS + '.integration_test_empty', |
103 STUBS_CLASS + '.test_empty', | 91 STUBS_CLASS + '.test_empty', |
104 ]) | 92 ]) |
105 self.assertEqual(serial_tests, [ | |
106 STUBS_CLASS + '.serial_integration_test_empty', | |
107 STUBS_CLASS + '.serial_test_empty', | |
108 ]) | |
109 | 93 |
110 def test_coverage_works(self): | 94 def test_coverage_works(self): |
111 # This is awkward; by design, running test-webkitpy -c will | 95 # This is awkward; by design, running test-webkitpy -c will |
112 # create a .coverage file in Tools/Scripts, so we need to be | 96 # create a .coverage file in Tools/Scripts, so we need to be |
113 # careful not to clobber an existing one, and to clean up. | 97 # careful not to clobber an existing one, and to clean up. |
114 # FIXME: This design needs to change since it means we can't actually | 98 # FIXME: This design needs to change since it means we can't actually |
115 # run this method itself under coverage properly. | 99 # run this method itself under coverage properly. |
116 filesystem = FileSystem() | 100 filesystem = FileSystem() |
117 executive = Executive() | 101 executive = Executive() |
118 module_path = filesystem.path_to_module(self.__module__) | 102 module_path = filesystem.path_to_module(self.__module__) |
119 script_dir = module_path[0:module_path.find('webkitpy') - 1] | 103 script_dir = module_path[0:module_path.find('webkitpy') - 1] |
120 coverage_file = filesystem.join(script_dir, '.coverage') | 104 coverage_file = filesystem.join(script_dir, '.coverage') |
121 coverage_file_orig = None | 105 coverage_file_orig = None |
122 if filesystem.exists(coverage_file): | 106 if filesystem.exists(coverage_file): |
123 coverage_file_orig = coverage_file + '.orig' | 107 coverage_file_orig = coverage_file + '.orig' |
124 filesystem.move(coverage_file, coverage_file_orig) | 108 filesystem.move(coverage_file, coverage_file_orig) |
125 | 109 |
126 try: | 110 try: |
127 proc = executive.popen([sys.executable, filesystem.join(script_dir,
'test-webkitpy'), '-c', STUBS_CLASS + '.test_empty'], | 111 proc = executive.popen([sys.executable, filesystem.join(script_dir,
'test-webkitpy'), '-c', STUBS_CLASS + '.test_empty'], |
128 stdout=executive.PIPE, stderr=executive.PIPE) | 112 stdout=executive.PIPE, stderr=executive.PIPE) |
129 out, _ = proc.communicate() | 113 out, _ = proc.communicate() |
130 retcode = proc.returncode | 114 retcode = proc.returncode |
131 self.assertEqual(retcode, 0) | 115 self.assertEqual(retcode, 0) |
132 self.assertIn('Cover', out) | 116 self.assertIn('Cover', out) |
133 finally: | 117 finally: |
134 if coverage_file_orig: | 118 if coverage_file_orig: |
135 filesystem.move(coverage_file_orig, coverage_file) | 119 filesystem.move(coverage_file_orig, coverage_file) |
136 elif filesystem.exists(coverage_file): | 120 elif filesystem.exists(coverage_file): |
137 filesystem.remove(coverage_file) | 121 filesystem.remove(coverage_file) |
OLD | NEW |