1#!/usr/bin/python
2
3"""
4Copyright 2013 Google Inc.
5
6Use of this source code is governed by a BSD-style license that can be
7found in the LICENSE file.
8
9Test compare_to_expectations.py
10
11TODO(epoger): Create a command to update the expected results (in
12self._output_dir_expected) when appropriate.  For now, you should:
131. examine the results in self.output_dir_actual and make sure they are ok
142. rm -rf self._output_dir_expected
153. mv self.output_dir_actual self._output_dir_expected
16Although, if you're using an SVN checkout, this will blow away .svn directories
17within self._output_dir_expected, which wouldn't be good...
18
19"""
20
21import os
22
23# Imports from within Skia
24import base_unittest
25import compare_to_expectations
26import imagediffdb
27import results
28import gm_json  # must import results first, so that gm_json will be in sys.path
29
30
31class CompareToExpectationsTest(base_unittest.TestCase):
32
33  def test_gm(self):
34    """Process results of a GM run with the ExpectationComparisons object."""
35    image_diff_db = imagediffdb.ImageDiffDB(storage_root=self.temp_dir)
36    results_obj = compare_to_expectations.ExpectationComparisons(
37        image_diff_db=image_diff_db,
38        actuals_root=os.path.join(self.input_dir, 'gm-actuals'),
39        expected_root=os.path.join(self.input_dir, 'gm-expectations'),
40        diff_base_url='/static/generated-images')
41    results_obj.get_timestamp = mock_get_timestamp
42    gm_json.WriteToFile(
43        results_obj.get_packaged_results_of_type(
44            results.KEY__HEADER__RESULTS_ALL),
45        os.path.join(self.output_dir_actual, 'gm.json'))
46
47
48def mock_get_timestamp():
49  """Mock version of BaseComparisons.get_timestamp() for testing."""
50  return 12345678
51
52
53def main():
54  base_unittest.main(CompareToExpectationsTest)
55
56
57if __name__ == '__main__':
58  main()
59