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

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

Issue 274623002: make compare_rendered_pictures_test.py run end-to-end test (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use subprocess.check_output() Created 6 years, 7 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
« no previous file with comments | « no previous file | gm/rebaseline_server/compare_rendered_pictures_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 A wrapper around the standard Python unittest library, adding features we need 9 A wrapper around the standard Python unittest library, adding features we need
10 for various unittests within this directory. 10 for various unittests within this directory.
11 """ 11 """
12 12
13 import filecmp 13 import filecmp
14 import os 14 import os
15 import shutil 15 import shutil
16 import tempfile 16 import tempfile
17 import unittest 17 import unittest
18 18
19 PARENT_DIR = os.path.dirname(os.path.realpath(__file__)) 19 PARENT_DIR = os.path.dirname(os.path.realpath(__file__))
20 TRUNK_DIR = os.path.dirname(os.path.dirname(PARENT_DIR))
20 TESTDATA_DIR = os.path.join(PARENT_DIR, 'testdata') 21 TESTDATA_DIR = os.path.join(PARENT_DIR, 'testdata')
21 OUTPUT_DIR_ACTUAL = os.path.join(TESTDATA_DIR, 'outputs', 'actual') 22 OUTPUT_DIR_ACTUAL = os.path.join(TESTDATA_DIR, 'outputs', 'actual')
22 OUTPUT_DIR_EXPECTED = os.path.join(TESTDATA_DIR, 'outputs', 'expected') 23 OUTPUT_DIR_EXPECTED = os.path.join(TESTDATA_DIR, 'outputs', 'expected')
23 24
24 25
25 class TestCase(unittest.TestCase): 26 class TestCase(unittest.TestCase):
26 27
27 def setUp(self): 28 def setUp(self):
28 self._input_dir = os.path.join(TESTDATA_DIR, 'inputs') 29 self._input_dir = os.path.join(TESTDATA_DIR, 'inputs')
29 self._output_dir_actual = os.path.join(OUTPUT_DIR_ACTUAL, self.id()) 30 self._output_dir_actual = os.path.join(OUTPUT_DIR_ACTUAL, self.id())
(...skipping 22 matching lines...) Expand all
52 ('found differing files:\n' + 53 ('found differing files:\n' +
53 '\n'.join(['tkdiff %s %s &' % ( 54 '\n'.join(['tkdiff %s %s &' % (
54 os.path.join(self._output_dir_actual, basename), 55 os.path.join(self._output_dir_actual, basename),
55 os.path.join(self._output_dir_expected, basename)) 56 os.path.join(self._output_dir_expected, basename))
56 for basename in different_files])) 57 for basename in different_files]))
57 58
58 def shortDescription(self): 59 def shortDescription(self):
59 """Tell unittest framework to not print docstrings for test cases.""" 60 """Tell unittest framework to not print docstrings for test cases."""
60 return None 61 return None
61 62
63 def find_path_to_program(self, program):
64 """Returns path to an existing program binary.
65
66 Args:
67 program: Basename of the program to find (e.g., 'render_pictures').
68
69 Returns:
70 Absolute path to the program binary, as a string.
71
72 Raises:
73 Exception: unable to find the program binary.
74 """
75 possible_paths = [os.path.join(TRUNK_DIR, 'out', 'Release', program),
76 os.path.join(TRUNK_DIR, 'out', 'Debug', program),
77 os.path.join(TRUNK_DIR, 'out', 'Release',
78 program + '.exe'),
79 os.path.join(TRUNK_DIR, 'out', 'Debug',
80 program + '.exe')]
81 for try_path in possible_paths:
82 if os.path.isfile(try_path):
83 return try_path
84 raise Exception('cannot find %s in paths %s; maybe you need to '
85 'build %s?' % (program, possible_paths, program))
86
62 87
63 def create_empty_dir(path): 88 def create_empty_dir(path):
64 """Create an empty directory at the given path.""" 89 """Create an empty directory at the given path."""
65 if os.path.isdir(path): 90 if os.path.isdir(path):
66 shutil.rmtree(path) 91 shutil.rmtree(path)
67 elif os.path.lexists(path): 92 elif os.path.lexists(path):
68 os.remove(path) 93 os.remove(path)
69 os.makedirs(path) 94 os.makedirs(path)
70 95
71 96
(...skipping 22 matching lines...) Expand all
94 for common_dir in dircmp.common_dirs: 119 for common_dir in dircmp.common_dirs:
95 differing_files.extend(find_different_files( 120 differing_files.extend(find_different_files(
96 os.path.join(dir1, common_dir), os.path.join(dir2, common_dir))) 121 os.path.join(dir1, common_dir), os.path.join(dir2, common_dir)))
97 return differing_files 122 return differing_files
98 123
99 124
100 def main(test_case_class): 125 def main(test_case_class):
101 """Run the unit tests within the given class.""" 126 """Run the unit tests within the given class."""
102 suite = unittest.TestLoader().loadTestsFromTestCase(test_case_class) 127 suite = unittest.TestLoader().loadTestsFromTestCase(test_case_class)
103 results = unittest.TextTestRunner(verbosity=2).run(suite) 128 results = unittest.TextTestRunner(verbosity=2).run(suite)
OLDNEW
« no previous file with comments | « no previous file | gm/rebaseline_server/compare_rendered_pictures_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698