131d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org#!/usr/bin/python
231d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
331d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org"""
431d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgCopyright 2014 Google Inc.
531d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
631d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgUse of this source code is governed by a BSD-style license that can be
731d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgfound in the LICENSE file.
831d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
931d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgTest compare_configs.py
1031d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
1131d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgTODO(epoger): Create a command to update the expected results (in
1231d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgself._output_dir_expected) when appropriate.  For now, you should:
1331d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org1. examine the results in self._output_dir_actual and make sure they are ok
1431d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org2. rm -rf self._output_dir_expected
1531d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org3. mv self._output_dir_actual self._output_dir_expected
1631d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgAlthough, if you're using an SVN checkout, this will blow away .svn directories
1731d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgwithin self._output_dir_expected, which wouldn't be good...
1831d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
1931d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org"""
2031d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
2131d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgimport os
2231d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgimport sys
2331d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
2431d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org# Imports from within Skia
2531d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgimport base_unittest
2631d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgimport compare_configs
2731d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgimport results
2831d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgimport gm_json  # must import results first, so that gm_json will be in sys.path
2931d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
3031d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
3131d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgclass CompareConfigsTest(base_unittest.TestCase):
3231d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
3331d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org  def test_gm(self):
3431d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org    """Process results of a GM run with the ConfigComparisons object."""
3531d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org    results_obj = compare_configs.ConfigComparisons(
3631d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org        configs=('8888', 'gpu'),
3731d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org        actuals_root=os.path.join(self._input_dir, 'gm-actuals'),
3831d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org        generated_images_root=self._temp_dir,
3931d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org        diff_base_url='/static/generated-images')
4031d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org    results_obj.get_timestamp = mock_get_timestamp
4131d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org    gm_json.WriteToFile(
4231d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org        results_obj.get_packaged_results_of_type(
4331d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org            results.KEY__HEADER__RESULTS_ALL),
4431d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org        os.path.join(self._output_dir_actual, 'gm.json'))
4531d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
4631d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
4731d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgdef mock_get_timestamp():
4831d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org  """Mock version of BaseComparisons.get_timestamp() for testing."""
4931d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org  return 12345678
5031d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
5131d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
5231d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgdef main():
5331d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org  base_unittest.main(CompareConfigsTest)
5431d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
5531d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org
5631d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.orgif __name__ == '__main__':
5731d0b3d806a1aa86b7edaa442b3821f5d548e184commit-bot@chromium.org  main()
58