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

Side by Side Diff: tools/tests/base_unittest.py

Issue 124253002: add unittest for render_pictures binary (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 11 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 2014 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 A wrapper around the standard Python unittest library, adding features we need
10 for various unittests within this directory.
11 """
12
13 import os
14 import subprocess
15 import unittest
16
17
18 class TestCase(unittest.TestCase):
19
20 def run_command(self, args):
21 """Runs a program from the command line and returns stdout.
22
23 Args:
24 args: Command line to run, as a list of string parameters. args[0] is the
25 binary to run.
26
27 Returns:
28 stdout from the program, as a single string.
29
30 Raises:
31 Exception: the program exited with a nonzero return code.
32 """
33 proc = subprocess.Popen(args,
34 stdout=subprocess.PIPE,
35 stderr=subprocess.PIPE)
36 (stdout, stderr) = proc.communicate()
37 if proc.returncode is not 0:
38 raise Exception('command "%s" failed: %s' % (args, stderr))
39 return stdout
40
41 def find_path_to_program(self, program):
epoger 2014/01/03 21:46:12 I copied this function over from tools/test_render
42 """Returns path to an existing program binary.
43
44 Args:
45 program: Basename of the program to find (e.g., 'render_pictures').
46
47 Returns:
48 Absolute path to the program binary, as a string.
49
50 Raises:
51 Exception: unable to find the program binary.
52 """
53 trunk_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
54 os.pardir, os.pardir))
55 possible_paths = [os.path.join(trunk_path, 'out', 'Release', program),
56 os.path.join(trunk_path, 'out', 'Debug', program),
57 os.path.join(trunk_path, 'out', 'Release',
58 program + '.exe'),
59 os.path.join(trunk_path, 'out', 'Debug',
60 program + '.exe')]
61 for try_path in possible_paths:
62 if os.path.isfile(try_path):
63 return try_path
64 raise Exception('cannot find %s in paths %s; maybe you need to '
65 'build %s?' % (program, possible_paths, program))
66
67
68 def main(test_case_class):
69 """Run the unit tests within the given class.
70
71 Raises an Exception if any of those tests fail (in case we are running in the
72 context of run_all.py, which depends on that Exception to signal failures).
73
74 TODO(epoger): Make all of our unit tests use the Python unittest framework,
75 so we can leverage its ability to run *all* the tests and report failures at
76 the end.
77 """
78 suite = unittest.TestLoader().loadTestsFromTestCase(test_case_class)
79 results = unittest.TextTestRunner(verbosity=2).run(suite)
80 if not results.wasSuccessful():
81 raise Exception('failed unittest %s' % test_case_class)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698