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

Side by Side Diff: mojo/tools/mopy/mojo_python_tests_runner.py

Issue 878933003: Move the apptest runner and parts of mopy to the public SDK. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 | « mojo/tools/mopy/memoize.py ('k') | mojo/tools/mopy/paths.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import argparse
6 import os
7 import sys
8 import unittest
9
10 import mopy.paths
11
12
13 class MojoPythonTestRunner(object):
14 """Helper class to run python tests on the bots."""
15
16 def __init__(self, test_dir):
17 self._test_dir = test_dir
18
19 def run(self):
20 parser = argparse.ArgumentParser()
21 parser.add_argument('-v', '--verbose', action='count', default=0)
22 parser.add_argument('tests', nargs='*')
23
24 self.add_custom_commandline_options(parser)
25 args = parser.parse_args()
26 self.apply_customization(args)
27
28 loader = unittest.loader.TestLoader()
29 print "Running Python unit tests under %s..." % self._test_dir
30
31 src_root = mopy.paths.Paths().src_root
32 pylib_dir = os.path.abspath(os.path.join(src_root, self._test_dir))
33 if args.tests:
34 if pylib_dir not in sys.path:
35 sys.path.append(pylib_dir)
36 suite = unittest.TestSuite()
37 for test_name in args.tests:
38 suite.addTests(loader.loadTestsFromName(test_name))
39 else:
40 suite = loader.discover(pylib_dir, pattern='*_unittest.py')
41
42 runner = unittest.runner.TextTestRunner(verbosity=(args.verbose + 1))
43 result = runner.run(suite)
44 return 0 if result.wasSuccessful() else 1
45
46 def add_custom_commandline_options(self, parser):
47 """Allow to add custom option to the runner script."""
48 pass
49
50 def apply_customization(self, args):
51 """Allow to apply any customization to the runner."""
52 pass
OLDNEW
« no previous file with comments | « mojo/tools/mopy/memoize.py ('k') | mojo/tools/mopy/paths.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698