OLD | NEW |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """A unit test module for TestExpectationManager.""" | |
7 | |
8 from datetime import date | |
9 from datetime import datetime | |
10 from datetime import timedelta | |
11 import os | |
12 import shutil | |
13 import time | |
14 import unittest | 6 import unittest |
15 | 7 |
16 from test_expectations import TestExpectationsManager | 8 from test_expectations import TestExpectations |
17 | 9 |
18 | 10 |
19 class TestTestExpectationsManager(unittest.TestCase): | 11 class TestTestExpectations(unittest.TestCase): |
20 """A unit test class for TestExpectationManager.""" | |
21 test_dir = u'test_dir' | |
22 cleaned = False | |
23 | 12 |
24 def setUp(self): | 13 def testParseLine(self): |
25 if not TestTestExpectationsManager.cleaned: | 14 line = "BUGCR86714 MAC GPU : media/video-zoom.html = CRASH IMAGE" |
26 if os.path.exists(self.test_dir): | 15 comments = "Comments" |
dennis_jeffrey
2011/08/22 16:39:39
Prefer single quotes over double quotes. Repeat i
imasaki1
2011/08/22 18:27:52
Done.
| |
27 shutil.rmtree(self.test_dir) | 16 expected_map = {'CRASH': True, 'IMAGE': True, 'Bugs': ['BUGCR86714'], |
28 os.mkdir(self.test_dir) | 17 'Comments': 'Comments', 'MAC': True, 'GPU': True} |
29 TestTestExpectationsManager.cleaned = True | 18 self.assertEquals(TestExpectations.ParseLine(line, comments), |
19 expected_map) | |
dennis_jeffrey
2011/08/22 16:39:39
msg='Some informative error message.'
imasaki1
2011/08/22 18:27:52
Discussed with Dennis offline. This can be kept as
| |
30 | 20 |
31 def verify_test_expectaion_format(self, file_name, media): | 21 def testParseLineWithLineCommentsFoo(self): |
dennis_jeffrey
2011/08/22 16:39:39
I think we can remove "Foo" from the function name
imasaki1
2011/08/22 18:27:52
Done.
| |
32 """Verify the test expectation format in the file. | 22 line = "BUGCR86714 MAC GPU : media/video-zoom.html = CRASH IMAGE // foo" |
23 comments = "Comments" | |
24 expected_map = {'CRASH': True, 'IMAGE': True, 'Bugs': ['BUGCR86714'], | |
25 'Comments': 'Comments foo', 'MAC': True, 'GPU': True} | |
26 self.assertEquals(TestExpectations.ParseLine(line, comments), | |
27 expected_map) | |
dennis_jeffrey
2011/08/22 16:39:39
msg='Some informative error message.'
imasaki1
2011/08/22 18:27:52
Done.
| |
33 | 28 |
34 Args: | 29 def testParseLineWithLineGPUComments(self): |
35 file_name: a file name to be verified. | 30 line = "BUGCR86714 MAC : media/video-zoom.html = CRASH IMAGE // GPU" |
36 media: a boolean to indicate whether the test is for media | 31 comments = "Comments" |
37 or not. | 32 expected_map = {'CRASH': True, 'IMAGE': True, 'Bugs': ['BUGCR86714'], |
33 'Comments': 'Comments GPU', 'MAC': True} | |
34 self.assertEquals(TestExpectations.ParseLine(line, comments), | |
35 expected_map) | |
dennis_jeffrey
2011/08/22 16:39:39
msg='Some informative error message.'
imasaki1
2011/08/22 18:27:52
Done.
| |
38 | 36 |
39 Returns: | 37 def testExtractTestName(self): |
40 a boolean indicating whether the file is in test expectation | 38 line = ('BUGWK58013 MAC GPU : compositing/scaling/' |
41 format. | 39 'tiled-layer-recursion.html = CRASH') |
42 """ | 40 self.assertEquals(TestExpectations.ExtractTestName(line), |
43 file_object = open(file_name, 'r') | 41 'compositing/scaling/tiled-layer-recursion.html', |
44 firstline = file_object.readline() | 42 'Test case name is different') |
dennis_jeffrey
2011/08/22 16:39:39
msg='Test case name is different.'
imasaki1
2011/08/22 18:27:52
Done.
| |
45 if ('These are the layout test expectations for the ' | |
46 'Chromium port(s) of WebKit.') not in firstline: | |
47 return False | |
48 # Check media related test case file is there. | |
49 verify_media = not media | |
50 if media: | |
51 for line in file_object: | |
52 if 'media' in line: | |
53 verify_media = True | |
54 file_object.close() | |
55 return verify_media | |
56 | 43 |
57 def verify_test_expectaion_format_in_csv(self, file_name): | 44 def testExtractTestNameWithDirName(self): |
58 """Verify the CSV file has information parsed. | 45 line = 'BUGWK43668 SKIP : media/track/ = TIMEOUT' |
46 self.assertEquals(TestExpectations.ExtractTestName(line), | |
47 'media/track/', | |
48 'Test case name is different') | |
dennis_jeffrey
2011/08/22 16:39:39
msg='Test case name is different.'
imasaki1
2011/08/22 18:27:52
Done.
| |
59 | 49 |
60 Args: | 50 def testExtractTestNameWithException(self): |
61 file_name: file name to be examined. | 51 line = 'Foo' |
62 | 52 try: |
63 Returns: | 53 TestExpectations.ExtractTestName(line), |
64 a boolean that indicates that the CSV file contains information | 54 except ValueError: |
65 parsed from test expectation file. | 55 return |
66 """ | 56 fail |
dennis_jeffrey
2011/08/22 16:39:39
Maybe we could use assertRaises() here:
http://do
imasaki1
2011/08/22 18:27:52
Done.
| |
67 file_object = open(file_name, 'r') | |
68 firstline = file_object.readline() | |
69 file_object.close() | |
70 return 'TestCase' in firstline | |
71 | |
72 def test_get_and_save_content(self): | |
73 """Test get_and_save_content method. | |
74 | |
75 Also, test several other methods. | |
76 """ | |
77 # Get all test cases. | |
78 result_file = os.path.join(self.test_dir, | |
79 'test_get_and_save_content.txt') | |
80 | |
81 test_expectations_manager = TestExpectationsManager() | |
82 test_expectations_manager.get_and_save_content( | |
83 test_expectations_manager.DEFAULT_TEST_EXPECTATION_LOCATION, | |
84 result_file) | |
85 | |
86 self.assertTrue( | |
87 self.verify_test_expectaion_format(result_file, False)) | |
88 | |
89 # Get media test cases from local all test cases. | |
90 result_file_media = os.path.join(self.test_dir, | |
91 'test_get_and_save_content_m.txt') | |
92 | |
93 test_expectations_manager = TestExpectationsManager() | |
94 test_expectations_manager.get_and_save_content_media_only( | |
95 result_file, result_file_media) | |
96 | |
97 self.assertTrue( | |
98 self.verify_test_expectaion_format(result_file_media, True)) | |
99 | |
100 # Get media test cases from local all test cases. | |
101 result_file_media_csv = os.path.join( | |
102 self.test_dir, 'test_get_and_save_content_m.csv') | |
103 | |
104 test_expectations_manager.get_and_parse_content( | |
105 result_file, result_file_media_csv, True) | |
106 | |
107 elements = test_expectations_manager.get_test_case_element( | |
108 'media/restore-from-page-cache.html', | |
109 ['TEXT', 'UNIMPLEMENTED', 'RELEASE']) | |
110 self.assertEqual( | |
111 elements, ['N', 'N', 'N'], | |
112 'returned element of GetTestCaseElement is wrong') | |
113 | |
114 field_names = ['SKIP', 'UNIMPLEMENTED', 'KNOWNISSUE'] | |
115 field_name_indexes = test_expectations_manager.get_column_indexes( | |
116 field_names) | |
117 expected_filed_name_indexes = [6, 22, 23] | |
118 self.assertEqual(field_name_indexes, expected_filed_name_indexes, | |
119 'incorrect field indexes') | |
120 | |
121 def test_parse_content_from_svn(self): | |
122 """Test get_and_parse_content method using SVN.""" | |
123 self.parse_content_from_svn_test_helper(False) | |
124 | |
125 def test_parse_content_from_svn_media(self): | |
126 """Test get_and_parse_content method using SVN (only media).""" | |
127 self.parse_content_from_svn_test_helper(True) | |
128 | |
129 def parse_content_from_svn_test_helper(self, media): | |
130 """Test get_and_parse_content method using SVN. | |
131 | |
132 Args: | |
133 media: True if this is for media tests. | |
134 """ | |
135 media_string = 'all' | |
136 if media: | |
137 media_string = 'media' | |
138 result_file = os.path.join( | |
139 self.test_dir, | |
140 'test_parse_content_from_svn_%s.csv' % media_string) | |
141 test_expectations_manager = TestExpectationsManager() | |
142 test_expectations_manager.get_and_parse_content( | |
143 test_expectations_manager.DEFAULT_TEST_EXPECTATION_LOCATION, | |
144 result_file, media) | |
145 | |
146 self.assertTrue(test_expectations_manager.testcases > 0) | |
147 | |
148 self.verify_test_expectaion_format_in_csv(result_file) | |
149 | |
150 def test_generate_link_for_cbug(self): | |
151 """Test generate_link_for_bug for a chromium bug.""" | |
152 self.generate_link_for_bug_helper( | |
153 'BUGCR1234', | |
154 'http://code.google.com/p/chromium/issues/detail?id=1234') | |
155 | |
156 def test_generate_link_for_wbug(self): | |
157 """Test generate_link_for_bug for a webkit bug.""" | |
158 self.generate_link_for_bug_helper( | |
159 'BUGWK1234', | |
160 'https://bugs.webkit.org/show_bug.cgi?id=1234') | |
161 | |
162 def test_generate_link_for_pbug(self): | |
163 """Test generate_link_for_bug for person.""" | |
164 self.generate_link_for_bug_helper('BUGIMASAKI', | |
165 'mailto:imasaki@chromium.org') | |
166 | |
167 def generate_link_for_bug_helper(self, bug_text, expected_link): | |
168 """A helper for generating link test.""" | |
169 test_expectations_manager = TestExpectationsManager() | |
170 link = test_expectations_manager.generate_link_for_bug(bug_text) | |
171 self.assertEqual(link, expected_link, 'link generated are not correct') | |
172 | |
173 def test_te_diff_between_times(self): | |
174 test_expectations_manager = TestExpectationsManager() | |
175 now = time.time() | |
176 past = datetime.now() - timedelta(days=4) | |
177 past = time.mktime(past.timetuple()) | |
178 result_list = test_expectations_manager.get_te_diff_between_times( | |
179 test_expectations_manager.DEFAULT_TEST_EXPECTATION_DIR, | |
180 now, past, ['media/audio-repaint.html'], -1, True) | |
181 self.assertTrue(result_list is not None) | |
182 | |
183 def test_te_diff_between_times_no_changecheck(self): | |
184 test_expectations_manager = TestExpectationsManager() | |
185 now = time.time() | |
186 past = datetime.now() - timedelta(weeks=2) | |
187 past = time.mktime(past.timetuple()) | |
188 result_list = test_expectations_manager.get_te_diff_between_times( | |
189 test_expectations_manager.DEFAULT_TEST_EXPECTATION_DIR, | |
190 now, past, ['media/audio-repaint.html'], -1, False) | |
191 self.assertTrue(result_list is not None) | |
192 | |
193 def test_te_diff_between_times_no_changecheck_with_pattern(self): | |
194 test_expectations_manager = TestExpectationsManager() | |
195 now = time.time() | |
196 past = datetime.now() - timedelta(weeks=2) | |
197 past = time.mktime(past.timetuple()) | |
198 result_list = test_expectations_manager.get_te_diff_between_times( | |
199 test_expectations_manager.DEFAULT_TEST_EXPECTATION_DIR, | |
200 now, past, ['media/audio-repaint.html'], -1, False) | |
201 self.assertTrue(result_list is not None) | |
202 | |
203 def test_get_all_column_names_no_other_field(self): | |
204 test_expectations_manager = TestExpectationsManager() | |
205 column_names = test_expectations_manager.get_all_column_names(False, | |
206 True) | |
207 other_field_column_names = test_expectations_manager.OTHER_FIELD_NAMES | |
208 for other_field_column_name in other_field_column_names: | |
209 self.assertFalse(other_field_column_name in column_names) | |
210 | |
211 def test_get_all_column_names_no_comment_field(self): | |
212 test_expectations_manager = TestExpectationsManager() | |
213 column_names = test_expectations_manager.get_all_column_names(True, | |
214 False) | |
215 other_field_column_names = ( | |
216 test_expectations_manager.COMMENT_COLUMN_NAMES) | |
217 for other_field_column_name in other_field_column_names: | |
218 self.assertFalse(other_field_column_name in column_names) | |
219 | 57 |
220 | 58 |
221 def main(): | 59 if __name__ == '__main__': |
222 test_suite = unittest.TestLoader().loadTestsFromTestCase( | 60 unittest.main() |
223 TestTestExpectationsManager) | |
224 | |
225 unittest.TextTestRunner(verbosity=2).run(test_suite) | |
OLD | NEW |