2014-02-13 17:17:05 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
"""
|
|
|
|
Copyright 2014 Google Inc.
|
|
|
|
|
|
|
|
Use of this source code is governed by a BSD-style license that can be
|
|
|
|
found in the LICENSE file.
|
|
|
|
|
|
|
|
Test imagepairset.py
|
|
|
|
"""
|
|
|
|
|
|
|
|
# System-level imports
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
# Local imports
|
|
|
|
import column
|
|
|
|
import imagepair
|
|
|
|
import imagepairset
|
|
|
|
|
|
|
|
|
|
|
|
BASE_URL_1 = 'http://base/url/1'
|
|
|
|
BASE_URL_2 = 'http://base/url/2'
|
2014-03-20 17:27:46 +00:00
|
|
|
DIFF_BASE_URL = 'http://diff/base/url'
|
2014-02-13 17:17:05 +00:00
|
|
|
IMAGEPAIR_1_AS_DICT = {
|
2014-05-12 20:40:29 +00:00
|
|
|
imagepair.KEY__IMAGEPAIRS__EXTRACOLUMNS: {
|
2014-02-13 17:17:05 +00:00
|
|
|
'builder': 'MyBuilder',
|
|
|
|
'test': 'test1',
|
|
|
|
},
|
2014-05-12 20:40:29 +00:00
|
|
|
imagepair.KEY__IMAGEPAIRS__IMAGE_A_URL: 'test1/1111.png',
|
|
|
|
imagepair.KEY__IMAGEPAIRS__IMAGE_B_URL: 'test1/1111.png',
|
|
|
|
imagepair.KEY__IMAGEPAIRS__IS_DIFFERENT: False,
|
2014-02-13 17:17:05 +00:00
|
|
|
}
|
|
|
|
IMAGEPAIR_2_AS_DICT = {
|
2014-05-12 20:40:29 +00:00
|
|
|
imagepair.KEY__IMAGEPAIRS__DIFFERENCES: {
|
2014-02-13 17:17:05 +00:00
|
|
|
'maxDiffPerChannel': [1, 2, 3],
|
|
|
|
'numDifferingPixels': 111,
|
|
|
|
'percentDifferingPixels': 22.222,
|
|
|
|
},
|
2014-05-12 20:40:29 +00:00
|
|
|
imagepair.KEY__IMAGEPAIRS__EXTRACOLUMNS: {
|
2014-02-13 17:17:05 +00:00
|
|
|
'builder': 'MyBuilder',
|
|
|
|
'test': 'test2',
|
|
|
|
},
|
2014-05-12 20:40:29 +00:00
|
|
|
imagepair.KEY__IMAGEPAIRS__IMAGE_A_URL: 'test2/2222.png',
|
|
|
|
imagepair.KEY__IMAGEPAIRS__IMAGE_B_URL: 'test2/22223.png',
|
|
|
|
imagepair.KEY__IMAGEPAIRS__IS_DIFFERENT: True,
|
2014-02-13 17:17:05 +00:00
|
|
|
}
|
|
|
|
IMAGEPAIR_3_AS_DICT = {
|
2014-05-12 20:40:29 +00:00
|
|
|
imagepair.KEY__IMAGEPAIRS__DIFFERENCES: {
|
2014-02-13 17:17:05 +00:00
|
|
|
'maxDiffPerChannel': [4, 5, 6],
|
|
|
|
'numDifferingPixels': 111,
|
|
|
|
'percentDifferingPixels': 44.444,
|
|
|
|
},
|
2014-05-12 20:40:29 +00:00
|
|
|
imagepair.KEY__IMAGEPAIRS__EXPECTATIONS: {
|
2014-02-13 17:17:05 +00:00
|
|
|
'bugs': [1001, 1002],
|
|
|
|
'ignoreFailure': True,
|
|
|
|
},
|
2014-05-12 20:40:29 +00:00
|
|
|
imagepair.KEY__IMAGEPAIRS__EXTRACOLUMNS: {
|
2014-02-13 17:17:05 +00:00
|
|
|
'builder': 'MyBuilder',
|
|
|
|
'test': 'test3',
|
|
|
|
},
|
2014-05-12 20:40:29 +00:00
|
|
|
imagepair.KEY__IMAGEPAIRS__IMAGE_A_URL: 'test3/3333.png',
|
|
|
|
imagepair.KEY__IMAGEPAIRS__IMAGE_B_URL: 'test3/33334.png',
|
|
|
|
imagepair.KEY__IMAGEPAIRS__IS_DIFFERENT: True,
|
2014-02-13 17:17:05 +00:00
|
|
|
}
|
|
|
|
SET_A_DESCRIPTION = 'expectations'
|
|
|
|
SET_B_DESCRIPTION = 'actuals'
|
|
|
|
|
|
|
|
|
|
|
|
class ImagePairSetTest(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.maxDiff = None # do not truncate diffs when tests fail
|
|
|
|
|
|
|
|
def shortDescription(self):
|
|
|
|
"""Tells unittest framework to not print docstrings for test cases."""
|
|
|
|
return None
|
|
|
|
|
|
|
|
def test_success(self):
|
|
|
|
"""Assembles some ImagePairs into an ImagePairSet, and validates results.
|
|
|
|
"""
|
|
|
|
image_pairs = [
|
|
|
|
MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_1_AS_DICT),
|
|
|
|
MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_2_AS_DICT),
|
|
|
|
MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_3_AS_DICT),
|
|
|
|
]
|
|
|
|
expected_imageset_dict = {
|
2014-02-26 19:05:20 +00:00
|
|
|
'extraColumnHeaders': {
|
2014-02-13 17:17:05 +00:00
|
|
|
'builder': {
|
|
|
|
'headerText': 'builder',
|
|
|
|
'isFilterable': True,
|
|
|
|
'isSortable': True,
|
2014-07-09 13:19:20 +00:00
|
|
|
'useFreeformFilter': False,
|
2014-05-08 21:15:20 +00:00
|
|
|
'valuesAndCounts': [('MyBuilder', 3)],
|
2014-02-13 17:17:05 +00:00
|
|
|
},
|
|
|
|
'test': {
|
|
|
|
'headerText': 'which GM test',
|
|
|
|
'headerUrl': 'http://learn/about/gm/tests',
|
|
|
|
'isFilterable': True,
|
|
|
|
'isSortable': False,
|
2014-07-09 13:19:20 +00:00
|
|
|
'useFreeformFilter': False,
|
|
|
|
'valuesAndCounts': [('test1', 1),
|
|
|
|
('test2', 1),
|
|
|
|
('test3', 1)],
|
2014-02-13 17:17:05 +00:00
|
|
|
},
|
|
|
|
},
|
2014-07-09 13:19:20 +00:00
|
|
|
'extraColumnOrder': ['builder', 'test'],
|
2014-02-13 17:17:05 +00:00
|
|
|
'imagePairs': [
|
|
|
|
IMAGEPAIR_1_AS_DICT,
|
|
|
|
IMAGEPAIR_2_AS_DICT,
|
|
|
|
IMAGEPAIR_3_AS_DICT,
|
|
|
|
],
|
2014-03-17 14:22:02 +00:00
|
|
|
'imageSets': {
|
|
|
|
'imageA': {
|
2014-02-13 17:17:05 +00:00
|
|
|
'baseUrl': BASE_URL_1,
|
|
|
|
'description': SET_A_DESCRIPTION,
|
|
|
|
},
|
2014-03-17 14:22:02 +00:00
|
|
|
'imageB': {
|
2014-02-13 17:17:05 +00:00
|
|
|
'baseUrl': BASE_URL_1,
|
|
|
|
'description': SET_B_DESCRIPTION,
|
|
|
|
},
|
2014-03-17 14:22:02 +00:00
|
|
|
'diffs': {
|
2014-03-20 17:27:46 +00:00
|
|
|
'baseUrl': DIFF_BASE_URL + '/diffs',
|
2014-03-17 14:22:02 +00:00
|
|
|
'description': 'color difference per channel',
|
|
|
|
},
|
|
|
|
'whiteDiffs': {
|
2014-03-20 17:27:46 +00:00
|
|
|
'baseUrl': DIFF_BASE_URL + '/whitediffs',
|
2014-03-17 14:22:02 +00:00
|
|
|
'description': 'differing pixels in white',
|
|
|
|
},
|
|
|
|
},
|
2014-02-13 17:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
image_pair_set = imagepairset.ImagePairSet(
|
2014-03-20 17:27:46 +00:00
|
|
|
descriptions=(SET_A_DESCRIPTION, SET_B_DESCRIPTION),
|
|
|
|
diff_base_url=DIFF_BASE_URL)
|
2014-02-13 17:17:05 +00:00
|
|
|
for image_pair in image_pairs:
|
|
|
|
image_pair_set.add_image_pair(image_pair)
|
|
|
|
# The 'builder' column header uses the default settings,
|
|
|
|
# but the 'test' column header has manual adjustments.
|
|
|
|
image_pair_set.set_column_header_factory(
|
|
|
|
'test',
|
|
|
|
column.ColumnHeaderFactory(
|
|
|
|
header_text='which GM test',
|
|
|
|
header_url='http://learn/about/gm/tests',
|
|
|
|
is_filterable=True,
|
2014-07-09 13:19:20 +00:00
|
|
|
is_sortable=False))
|
2014-02-13 17:17:05 +00:00
|
|
|
self.assertEqual(image_pair_set.as_dict(), expected_imageset_dict)
|
|
|
|
|
|
|
|
def test_mismatched_base_url(self):
|
|
|
|
"""Confirms that mismatched base_urls will cause an exception."""
|
2014-03-20 17:27:46 +00:00
|
|
|
image_pair_set = imagepairset.ImagePairSet(
|
|
|
|
diff_base_url=DIFF_BASE_URL)
|
2014-02-13 17:17:05 +00:00
|
|
|
image_pair_set.add_image_pair(
|
|
|
|
MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_1_AS_DICT))
|
|
|
|
image_pair_set.add_image_pair(
|
|
|
|
MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_2_AS_DICT))
|
|
|
|
with self.assertRaises(Exception):
|
|
|
|
image_pair_set.add_image_pair(
|
|
|
|
MockImagePair(base_url=BASE_URL_2,
|
|
|
|
dict_to_return=IMAGEPAIR_3_AS_DICT))
|
|
|
|
|
2014-07-09 13:19:20 +00:00
|
|
|
def test_missing_column_ids(self):
|
|
|
|
"""Confirms that passing truncated column_ids_in_order to as_dict()
|
|
|
|
will cause an exception."""
|
|
|
|
image_pair_set = imagepairset.ImagePairSet(
|
|
|
|
diff_base_url=DIFF_BASE_URL)
|
|
|
|
image_pair_set.add_image_pair(
|
|
|
|
MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_1_AS_DICT))
|
|
|
|
image_pair_set.add_image_pair(
|
|
|
|
MockImagePair(base_url=BASE_URL_1, dict_to_return=IMAGEPAIR_2_AS_DICT))
|
|
|
|
# Call as_dict() with default or reasonable column_ids_in_order.
|
|
|
|
image_pair_set.as_dict()
|
|
|
|
image_pair_set.as_dict(column_ids_in_order=['test', 'builder'])
|
|
|
|
image_pair_set.as_dict(column_ids_in_order=['test', 'builder', 'extra'])
|
|
|
|
# Call as_dict() with not enough column_ids.
|
|
|
|
with self.assertRaises(Exception):
|
|
|
|
image_pair_set.as_dict(column_ids_in_order=['builder'])
|
|
|
|
|
2014-02-13 17:17:05 +00:00
|
|
|
|
|
|
|
class MockImagePair(object):
|
|
|
|
"""Mock ImagePair object, which will return canned results."""
|
|
|
|
def __init__(self, base_url, dict_to_return):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
base_url: base_url attribute for this object
|
|
|
|
dict_to_return: dictionary to return from as_dict()
|
|
|
|
"""
|
|
|
|
self.base_url = base_url
|
|
|
|
self.extra_columns_dict = dict_to_return.get(
|
2014-05-12 20:40:29 +00:00
|
|
|
imagepair.KEY__IMAGEPAIRS__EXTRACOLUMNS, None)
|
2014-02-13 17:17:05 +00:00
|
|
|
self._dict_to_return = dict_to_return
|
|
|
|
|
|
|
|
def as_dict(self):
|
|
|
|
return self._dict_to_return
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(ImagePairSetTest)
|
|
|
|
unittest.TextTestRunner(verbosity=2).run(suite)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|