Commit b5d3236c authored by qsr's avatar qsr Committed by Commit bot

Remove python bindings unittests from the build.

Instead add a run_mojo_python_bindings_tests.py that will be run from
the bots. This also refactor run_mojo_python_tests.py to factorize the
common code.

BUG=407818

Review URL: https://codereview.chromium.org/509863002

Cr-Commit-Position: refs/heads/master@{#292372}
parent a031eaad
...@@ -596,29 +596,6 @@ ...@@ -596,29 +596,6 @@
], ],
'includes': [ '../third_party/cython/python_module.gypi' ], 'includes': [ '../third_party/cython/python_module.gypi' ],
}, },
{
'target_name': 'mojo_python_unittests',
'type': 'none',
'actions': [
{
'action_name': 'run_mojo_python_unittests',
'inputs': [
'python/tests/test_core.py',
'<(SHARED_INTERMEDIATE_DIR)/mojo_python_py_module.stamp',
'<(PRODUCT_DIR)/python/mojo/__init__.py',
],
'outputs': [
'none',
],
'action': [
'python', '<@(_inputs)', '<(PRODUCT_DIR)/python',
],
},
],
'dependency': [
'mojo_python',
],
},
], ],
}], }],
], ],
......
...@@ -10,11 +10,6 @@ group("python") { ...@@ -10,11 +10,6 @@ group("python") {
] ]
} }
group("tests") {
deps = [
"//mojo/python/tests",
]
}
python_binary_module("embedder") { python_binary_module("embedder") {
python_base_module = "mojo" python_base_module = "mojo"
sources = [ sources = [
......
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//third_party/cython/rules.gni")
group("tests") {
deps = [
":test_core",
]
}
action("test_core") {
script = "test_core.py"
outputs = [
"$root_out_dir/no_file",
]
inputs = []
deps = [
"//mojo/public/python:system",
"//mojo/python:embedder",
]
args = [ rebase_path("$root_out_dir/python", root_build_dir) ]
}
...@@ -7,10 +7,6 @@ import sys ...@@ -7,10 +7,6 @@ import sys
import time import time
import unittest import unittest
# Setup sys path
for path in sys.argv[1:]:
sys.path.append(path)
# pylint: disable=F0401 # pylint: disable=F0401
from mojo.embedder import init as init_embedder from mojo.embedder import init as init_embedder
from mojo import system from mojo import system
......
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import json
import os
import sys
import time
import unittest
class MojoPythonTestRunner(object):
"""Helper class to run python tests on the bots."""
def __init__(self, test_dir):
self._test_dir = test_dir
def run(self):
parser = argparse.ArgumentParser()
parser.usage = 'run_mojo_python_tests.py [options] [tests...]'
parser.add_argument('-v', '--verbose', action='count', default=0)
parser.add_argument('--metadata', action='append', default=[],
help=('optional key=value metadata that will be stored '
'in the results files (can be used for revision '
'numbers, etc.)'))
parser.add_argument('--write-full-results-to', metavar='FILENAME',
action='store',
help='path to write the list of full results to.')
parser.add_argument('tests', nargs='*')
self.add_custom_commandline_options(parser)
args = parser.parse_args()
self.apply_customization(args)
bad_metadata = False
for val in args.metadata:
if '=' not in val:
print >> sys.stderr, ('Error: malformed metadata "%s"' % val)
bad_metadata = True
if bad_metadata:
print >> sys.stderr
parser.print_help()
return 2
chromium_src_dir = os.path.join(os.path.dirname(__file__),
os.pardir,
os.pardir,
os.pardir)
loader = unittest.loader.TestLoader()
print "Running Python unit tests under %s..." % self._test_dir
pylib_dir = os.path.join(chromium_src_dir, self._test_dir)
if args.tests:
if pylib_dir not in sys.path:
sys.path.append(pylib_dir)
suite = unittest.TestSuite()
for test_name in args.tests:
suite.addTests(loader.loadTestsFromName(test_name))
else:
suite = loader.discover(pylib_dir, pattern='*_unittest.py')
runner = unittest.runner.TextTestRunner(verbosity=(args.verbose + 1))
result = runner.run(suite)
full_results = _FullResults(suite, result, args.metadata)
if args.write_full_results_to:
with open(args.write_full_results_to, 'w') as fp:
json.dump(full_results, fp, indent=2)
fp.write("\n")
return 0 if result.wasSuccessful() else 1
def add_custom_commandline_options(self, parser):
"""Allow to add custom option to the runner script."""
pass
def apply_customization(self, args):
"""Allow to apply any customization to the runner."""
pass
TEST_SEPARATOR = '.'
def _FullResults(suite, result, metadata):
"""Convert the unittest results to the Chromium JSON test result format.
This matches run-webkit-tests (the layout tests) and the flakiness dashboard.
"""
full_results = {}
full_results['interrupted'] = False
full_results['path_delimiter'] = TEST_SEPARATOR
full_results['version'] = 3
full_results['seconds_since_epoch'] = time.time()
for md in metadata:
key, val = md.split('=', 1)
full_results[key] = val
all_test_names = _AllTestNames(suite)
failed_test_names = _FailedTestNames(result)
full_results['num_failures_by_type'] = {
'FAIL': len(failed_test_names),
'PASS': len(all_test_names) - len(failed_test_names),
}
full_results['tests'] = {}
for test_name in all_test_names:
value = {}
value['expected'] = 'PASS'
if test_name in failed_test_names:
value['actual'] = 'FAIL'
value['is_unexpected'] = True
else:
value['actual'] = 'PASS'
_AddPathToTrie(full_results['tests'], test_name, value)
return full_results
def _AllTestNames(suite):
test_names = []
# _tests is protected pylint: disable=W0212
for test in suite._tests:
if isinstance(test, unittest.suite.TestSuite):
test_names.extend(_AllTestNames(test))
else:
test_names.append(test.id())
return test_names
def _FailedTestNames(result):
return set(test.id() for test, _ in result.failures + result.errors)
def _AddPathToTrie(trie, path, value):
if TEST_SEPARATOR not in path:
trie[path] = value
return
directory, rest = path.split(TEST_SEPARATOR, 1)
if directory not in trie:
trie[directory] = {}
_AddPathToTrie(trie[directory], rest, value)
#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import sys
_script_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(_script_dir, "pylib"))
from mojo_python_tests_runner import MojoPythonTestRunner
class PythonBindingsTestRunner(MojoPythonTestRunner):
def add_custom_commandline_options(self, parser):
parser.add_argument('--build_dir', action='store',
help='path to the build output directory')
def apply_customization(self, args):
if args.build_dir:
python_build_dir = os.path.join(args.build_dir, 'python')
if python_build_dir not in sys.path:
sys.path.append(python_build_dir)
def main():
runner = PythonBindingsTestRunner(os.path.join('mojo', 'python', 'tests'))
sys.exit(runner.run())
if __name__ == '__main__':
sys.exit(main())
...@@ -3,133 +3,19 @@ ...@@ -3,133 +3,19 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import argparse
import json
import os import os
import sys import sys
import time
import unittest
_script_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(_script_dir, "pylib"))
def main(): from mojo_python_tests_runner import MojoPythonTestRunner
parser = argparse.ArgumentParser()
parser.usage = 'run_mojo_python_tests.py [options] [tests...]'
parser.add_argument('-v', '--verbose', action='count', default=0)
parser.add_argument('--metadata', action='append', default=[],
help=('optional key=value metadata that will be stored '
'in the results files (can be used for revision '
'numbers, etc.)'))
parser.add_argument('--write-full-results-to', metavar='FILENAME',
action='store',
help='path to write the list of full results to.')
parser.add_argument('tests', nargs='*')
args = parser.parse_args()
bad_metadata = False
for val in args.metadata:
if '=' not in val:
print >> sys.stderr, ('Error: malformed metadata "%s"' % val)
bad_metadata = True
if bad_metadata:
print >> sys.stderr
parser.print_help()
return 2
chromium_src_dir = os.path.join(os.path.dirname(__file__),
os.pardir,
os.pardir)
loader = unittest.loader.TestLoader()
print "Running Python unit tests under mojo/public/tools/bindings/pylib ..."
pylib_dir = os.path.join(chromium_src_dir, 'mojo', 'public',
'tools', 'bindings', 'pylib')
if args.tests:
if pylib_dir not in sys.path:
sys.path.append(pylib_dir)
suite = unittest.TestSuite()
for test_name in args.tests:
suite.addTests(loader.loadTestsFromName(test_name))
else:
suite = loader.discover(pylib_dir, pattern='*_unittest.py')
runner = unittest.runner.TextTestRunner(verbosity=(args.verbose + 1))
result = runner.run(suite)
full_results = _FullResults(suite, result, args.metadata)
if args.write_full_results_to:
with open(args.write_full_results_to, 'w') as fp:
json.dump(full_results, fp, indent=2)
fp.write("\n")
return 0 if result.wasSuccessful() else 1
TEST_SEPARATOR = '.'
def _FullResults(suite, result, metadata):
"""Convert the unittest results to the Chromium JSON test result format.
This matches run-webkit-tests (the layout tests) and the flakiness dashboard.
"""
full_results = {} def main():
full_results['interrupted'] = False runner = MojoPythonTestRunner(os.path.join('mojo', 'public', 'tools',
full_results['path_delimiter'] = TEST_SEPARATOR 'bindings', 'pylib'))
full_results['version'] = 3 sys.exit(runner.run())
full_results['seconds_since_epoch'] = time.time()
for md in metadata:
key, val = md.split('=', 1)
full_results[key] = val
all_test_names = _AllTestNames(suite)
failed_test_names = _FailedTestNames(result)
full_results['num_failures_by_type'] = {
'FAIL': len(failed_test_names),
'PASS': len(all_test_names) - len(failed_test_names),
}
full_results['tests'] = {}
for test_name in all_test_names:
value = {}
value['expected'] = 'PASS'
if test_name in failed_test_names:
value['actual'] = 'FAIL'
value['is_unexpected'] = True
else:
value['actual'] = 'PASS'
_AddPathToTrie(full_results['tests'], test_name, value)
return full_results
def _AllTestNames(suite):
test_names = []
# _tests is protected pylint: disable=W0212
for test in suite._tests:
if isinstance(test, unittest.suite.TestSuite):
test_names.extend(_AllTestNames(test))
else:
test_names.append(test.id())
return test_names
def _FailedTestNames(result):
return set(test.id() for test, _ in result.failures + result.errors)
def _AddPathToTrie(trie, path, value):
if TEST_SEPARATOR not in path:
trie[path] = value
return
directory, rest = path.split(TEST_SEPARATOR, 1)
if directory not in trie:
trie[directory] = {}
_AddPathToTrie(trie[directory], rest, value)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment