| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 """ | 3 """ |
| 4 Copyright 2014 Google Inc. | 4 Copyright 2014 Google Inc. |
| 5 | 5 |
| 6 Use of this source code is governed by a BSD-style license that can be | 6 Use of this source code is governed by a BSD-style license that can be |
| 7 found in the LICENSE file. | 7 found in the LICENSE file. |
| 8 | 8 |
| 9 Test imagepairset.py | 9 Test imagepairset.py |
| 10 """ | 10 """ |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_1_AS_DICT), | 82 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_1_AS_DICT), |
| 83 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_2_AS_DICT), | 83 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_2_AS_DICT), |
| 84 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_3_AS_DICT), | 84 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_3_AS_DICT), |
| 85 ] | 85 ] |
| 86 expected_imageset_dict = { | 86 expected_imageset_dict = { |
| 87 'extraColumnHeaders': { | 87 'extraColumnHeaders': { |
| 88 'builder': { | 88 'builder': { |
| 89 'headerText': 'builder', | 89 'headerText': 'builder', |
| 90 'isFilterable': True, | 90 'isFilterable': True, |
| 91 'isSortable': True, | 91 'isSortable': True, |
| 92 'useFreeformFilter': False, |
| 92 'valuesAndCounts': [('MyBuilder', 3)], | 93 'valuesAndCounts': [('MyBuilder', 3)], |
| 93 }, | 94 }, |
| 94 'test': { | 95 'test': { |
| 95 'headerText': 'which GM test', | 96 'headerText': 'which GM test', |
| 96 'headerUrl': 'http://learn/about/gm/tests', | 97 'headerUrl': 'http://learn/about/gm/tests', |
| 97 'isFilterable': True, | 98 'isFilterable': True, |
| 98 'isSortable': False, | 99 'isSortable': False, |
| 100 'useFreeformFilter': False, |
| 101 'valuesAndCounts': [('test1', 1), |
| 102 ('test2', 1), |
| 103 ('test3', 1)], |
| 99 }, | 104 }, |
| 100 }, | 105 }, |
| 106 'extraColumnOrder': ['builder', 'test'], |
| 101 'imagePairs': [ | 107 'imagePairs': [ |
| 102 IMAGEPAIR_1_AS_DICT, | 108 IMAGEPAIR_1_AS_DICT, |
| 103 IMAGEPAIR_2_AS_DICT, | 109 IMAGEPAIR_2_AS_DICT, |
| 104 IMAGEPAIR_3_AS_DICT, | 110 IMAGEPAIR_3_AS_DICT, |
| 105 ], | 111 ], |
| 106 'imageSets': { | 112 'imageSets': { |
| 107 'imageA': { | 113 'imageA': { |
| 108 'baseUrl': BASE_URL_1, | 114 'baseUrl': BASE_URL_1, |
| 109 'description': SET_A_DESCRIPTION, | 115 'description': SET_A_DESCRIPTION, |
| 110 }, | 116 }, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 129 for image_pair in image_pairs: | 135 for image_pair in image_pairs: |
| 130 image_pair_set.add_image_pair(image_pair) | 136 image_pair_set.add_image_pair(image_pair) |
| 131 # The 'builder' column header uses the default settings, | 137 # The 'builder' column header uses the default settings, |
| 132 # but the 'test' column header has manual adjustments. | 138 # but the 'test' column header has manual adjustments. |
| 133 image_pair_set.set_column_header_factory( | 139 image_pair_set.set_column_header_factory( |
| 134 'test', | 140 'test', |
| 135 column.ColumnHeaderFactory( | 141 column.ColumnHeaderFactory( |
| 136 header_text='which GM test', | 142 header_text='which GM test', |
| 137 header_url='http://learn/about/gm/tests', | 143 header_url='http://learn/about/gm/tests', |
| 138 is_filterable=True, | 144 is_filterable=True, |
| 139 is_sortable=False, | 145 is_sortable=False)) |
| 140 include_values_and_counts=False)) | |
| 141 self.assertEqual(image_pair_set.as_dict(), expected_imageset_dict) | 146 self.assertEqual(image_pair_set.as_dict(), expected_imageset_dict) |
| 142 | 147 |
| 143 def test_mismatched_base_url(self): | 148 def test_mismatched_base_url(self): |
| 144 """Confirms that mismatched base_urls will cause an exception.""" | 149 """Confirms that mismatched base_urls will cause an exception.""" |
| 145 image_pair_set = imagepairset.ImagePairSet( | 150 image_pair_set = imagepairset.ImagePairSet( |
| 146 diff_base_url=DIFF_BASE_URL) | 151 diff_base_url=DIFF_BASE_URL) |
| 147 image_pair_set.add_image_pair( | 152 image_pair_set.add_image_pair( |
| 148 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_1_AS_DICT)) | 153 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_1_AS_DICT)) |
| 149 image_pair_set.add_image_pair( | 154 image_pair_set.add_image_pair( |
| 150 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_2_AS_DICT)) | 155 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_2_AS_DICT)) |
| 151 with self.assertRaises(Exception): | 156 with self.assertRaises(Exception): |
| 152 image_pair_set.add_image_pair( | 157 image_pair_set.add_image_pair( |
| 153 MockImagePair(base_url=BASE_URL_2, | 158 MockImagePair(base_url=BASE_URL_2, |
| 154 dict_to_return=IMAGEPAIR_3_AS_DICT)) | 159 dict_to_return=IMAGEPAIR_3_AS_DICT)) |
| 155 | 160 |
| 161 def test_missing_column_ids(self): |
| 162 """Confirms that passing truncated column_ids_in_order to as_dict() |
| 163 will cause an exception.""" |
| 164 image_pair_set = imagepairset.ImagePairSet( |
| 165 diff_base_url=DIFF_BASE_URL) |
| 166 image_pair_set.add_image_pair( |
| 167 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_1_AS_DICT)) |
| 168 image_pair_set.add_image_pair( |
| 169 MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_2_AS_DICT)) |
| 170 # Call as_dict() with default or reasonable column_ids_in_order. |
| 171 image_pair_set.as_dict() |
| 172 image_pair_set.as_dict(column_ids_in_order=['test', 'builder']) |
| 173 image_pair_set.as_dict(column_ids_in_order=['test', 'builder', 'extra']) |
| 174 # Call as_dict() with not enough column_ids. |
| 175 with self.assertRaises(Exception): |
| 176 image_pair_set.as_dict(column_ids_in_order=['builder']) |
| 177 |
| 156 | 178 |
| 157 class MockImagePair(object): | 179 class MockImagePair(object): |
| 158 """Mock ImagePair object, which will return canned results.""" | 180 """Mock ImagePair object, which will return canned results.""" |
| 159 def __init__(self, base_url, dict_to_return): | 181 def __init__(self, base_url, dict_to_return): |
| 160 """ | 182 """ |
| 161 Args: | 183 Args: |
| 162 base_url: base_url attribute for this object | 184 base_url: base_url attribute for this object |
| 163 dict_to_return: dictionary to return from as_dict() | 185 dict_to_return: dictionary to return from as_dict() |
| 164 """ | 186 """ |
| 165 self.base_url = base_url | 187 self.base_url = base_url |
| 166 self.extra_columns_dict = dict_to_return.get( | 188 self.extra_columns_dict = dict_to_return.get( |
| 167 imagepair.KEY__IMAGEPAIRS__EXTRACOLUMNS, None) | 189 imagepair.KEY__IMAGEPAIRS__EXTRACOLUMNS, None) |
| 168 self._dict_to_return = dict_to_return | 190 self._dict_to_return = dict_to_return |
| 169 | 191 |
| 170 def as_dict(self): | 192 def as_dict(self): |
| 171 return self._dict_to_return | 193 return self._dict_to_return |
| 172 | 194 |
| 173 | 195 |
| 174 def main(): | 196 def main(): |
| 175 suite = unittest.TestLoader().loadTestsFromTestCase(ImagePairSetTest) | 197 suite = unittest.TestLoader().loadTestsFromTestCase(ImagePairSetTest) |
| 176 unittest.TextTestRunner(verbosity=2).run(suite) | 198 unittest.TextTestRunner(verbosity=2).run(suite) |
| 177 | 199 |
| 178 | 200 |
| 179 if __name__ == '__main__': | 201 if __name__ == '__main__': |
| 180 main() | 202 main() |
| OLD | NEW |