Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: gm/rebaseline_server/results_test.py

Issue 117413006: create unittest for gm/rebaseline_server/results.py (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address comments Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/python
2
3 """
4 Copyright 2013 Google Inc.
5
6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file.
8
9 Test results.py
10
11 TODO(epoger): Launch this (and other unittests within this dir) automatically
12 on the housekeeper bot, but first make sure it works properly after having been
13 checked out (from both git and svn)
14
15 TODO(epoger): Create a command to update the expected results (in
16 OUTPUT_DIR_EXPECTATIONS) when appropriate. For now, you should:
17 1. examine the results in OUTPUT_DIR and make sure they are ok
18 2. rm -rf OUTPUT_DIR_EXPECTATIONS
19 3. mv OUTPUT_DIR OUTPUT_DIR_EXPECTATIONS
20 Although, if you're using an SVN checkout, this will blow away .svn directories
21 within OUTPUT_DIR_EXPECTATIONS, which wouldn't be good...
22
23 """
24
25 import filecmp
26 import os
27 import shutil
28 import sys
29 import tempfile
30 import unittest
31
32 # Imports from within Skia
33 import results
34 import gm_json # must import results first, so that gm_json will be in sys.path
35
36 PARENT_DIR = os.path.dirname(os.path.realpath(__file__))
37 INPUT_DIR = os.path.join(PARENT_DIR, 'tests', 'inputs')
38 OUTPUT_DIR = os.path.join(PARENT_DIR, 'tests', 'outputs', 'actual')
39 OUTPUT_DIR_EXPECTATIONS = os.path.join(
40 PARENT_DIR, 'tests', 'outputs', 'expected')
41
42 class ResultsTest(unittest.TestCase):
43
44 def setUp(self):
45 self._tempdir = tempfile.mkdtemp()
46
47 def tearDown(self):
48 shutil.rmtree(self._tempdir)
49
50 def test_gm(self):
51 """Process results of a GM run with the Results object."""
52 results_obj = results.Results(
53 actuals_root=os.path.join(INPUT_DIR, 'gm-actuals'),
54 expected_root=os.path.join(INPUT_DIR, 'gm-expectations'),
55 generated_images_root=self._tempdir)
56 gm_json.WriteToFile(results_obj.get_results_of_type(results.RESULTS_ALL),
57 os.path.join(OUTPUT_DIR, 'gm.json'))
58
59
60 def find_different_files(dir1, dir2, ignore_subtree_names=None):
61 """Returns a list of any files that differ between the directory trees rooted
62 at dir1 and dir2.
63
64 Args:
65 dir1: root of a directory tree; if nonexistent, will raise OSError
66 dir2: root of another directory tree; if nonexistent, will raise OSError
67 ignore_subtree_names: list of subtree directory names to ignore;
68 defaults to ['.svn'], so all SVN files are ignores
69
70 TODO(epoger): include the dirname within each filename (not just the
71 basename), to make it easier to locate any differences
72 """
73 differing_files = []
74 if ignore_subtree_names is None:
75 ignore_subtree_names = ['.svn']
76 dircmp = filecmp.dircmp(dir1, dir2, ignore=ignore_subtree_names)
77 differing_files.extend(dircmp.left_only)
78 differing_files.extend(dircmp.right_only)
79 differing_files.extend(dircmp.common_funny)
80 differing_files.extend(dircmp.diff_files)
81 differing_files.extend(dircmp.funny_files)
82 for common_dir in dircmp.common_dirs:
83 differing_files.extend(find_different_files(
84 os.path.join(dir1, common_dir), os.path.join(dir2, common_dir)))
85 return differing_files
86
87
88 def main():
89 if not os.path.isdir(OUTPUT_DIR):
90 os.makedirs(OUTPUT_DIR)
91 suite = unittest.TestLoader().loadTestsFromTestCase(ResultsTest)
92 unittest.TextTestRunner(verbosity=2).run(suite)
93 different_files = find_different_files(OUTPUT_DIR, OUTPUT_DIR_EXPECTATIONS)
94 assert (not different_files), 'found differing files: %s' % different_files
95
96
97 if __name__ == '__main__':
98 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698