diff options
author | Todd Fiala <todd.fiala@gmail.com> | 2016-04-19 04:20:35 +0000 |
---|---|---|
committer | Todd Fiala <todd.fiala@gmail.com> | 2016-04-19 04:20:35 +0000 |
commit | ca5793ea5c49842bc234b45a88467fd74667573b (patch) | |
tree | 10d115d802e30bdd8ad8ab7ac9d05b8b4e282775 /lldb/packages/Python | |
parent | 9695eb3239018647bcee02eba2f9f5b90904d1bc (diff) | |
download | bcm5719-llvm-ca5793ea5c49842bc234b45a88467fd74667573b.tar.gz bcm5719-llvm-ca5793ea5c49842bc234b45a88467fd74667573b.zip |
test infra cleanup: convert test_runner lib into package
Also does the following:
* adopts PEP8 naming convention for OptionalWith class (now
optional_with).
* moves test_runner/lldb_utils.py to lldbsuite/support/optional_with.py.
* packages tests in a subpackage of test_runner per recommendations in
http://the-hitchhikers-guide-to-packaging.readthedocs.org/en/latest/creation.html
Tests can be run from within pacakges/Python/lldbsuite/test via this
command:
python -m unittest discover test_runner
The primary cleanup this allows is avoiding the need to muck with the
PYTHONPATH variable from within the source files. This also aids some
of the static code checkers as they don't need to run code to determine
the proper python path.
llvm-svn: 266710
Diffstat (limited to 'lldb/packages/Python')
-rw-r--r-- | lldb/packages/Python/lldbsuite/support/optional_with.py (renamed from lldb/packages/Python/lldbsuite/test/test_runner/lib/lldb_utils.py) | 26 | ||||
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/dosep.py | 10 | ||||
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/test_runner/__init__.py | 0 | ||||
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/test_runner/process_control.py (renamed from lldb/packages/Python/lldbsuite/test/test_runner/lib/process_control.py) | 0 | ||||
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/test_runner/test/__init__.py | 0 | ||||
-rwxr-xr-x | lldb/packages/Python/lldbsuite/test/test_runner/test/test_process_control.py (renamed from lldb/packages/Python/lldbsuite/test/test_runner/test/process_control_tests.py) | 13 |
6 files changed, 19 insertions, 30 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/test_runner/lib/lldb_utils.py b/lldb/packages/Python/lldbsuite/support/optional_with.py index e469bbf1220..41342288bc6 100644 --- a/lldb/packages/Python/lldbsuite/test/test_runner/lib/lldb_utils.py +++ b/lldb/packages/Python/lldbsuite/support/optional_with.py @@ -1,18 +1,8 @@ -""" -The LLVM Compiler Infrastructure +# ==================================================================== +# Provides a with-style resource handler for optionally-None resources +# ==================================================================== -This file is distributed under the University of Illinois Open Source -License. See LICENSE.TXT for details. - -Provides classes used by the test results reporting infrastructure -within the LLDB test suite. - - -This module contains utilities used by the lldb test framwork. -""" - - -class OptionalWith(object): +class optional_with(object): # pylint: disable=too-few-public-methods # This is a wrapper - it is not meant to provide any extra methods. """Provides a wrapper for objects supporting "with", allowing None. @@ -22,13 +12,13 @@ class OptionalWith(object): e.g. - wrapped_lock = OptionalWith(thread.Lock()) + wrapped_lock = optional_with(thread.Lock()) with wrapped_lock: # Do something while the lock is obtained. pass might_be_none = None - wrapped_none = OptionalWith(might_be_none) + wrapped_none = optional_with(might_be_none) with wrapped_none: # This code here still works. pass @@ -40,13 +30,13 @@ class OptionalWith(object): lock.acquire() try: - code_fragament_always_run() + code_fragment_always_run() finally: if lock: lock.release() And I'd posit it is safer, as it becomes impossible to - forget the try/finally using OptionalWith(), since + forget the try/finally using optional_with(), since the with syntax can be used. """ def __init__(self, wrapped_object): diff --git a/lldb/packages/Python/lldbsuite/test/dosep.py b/lldb/packages/Python/lldbsuite/test/dosep.py index 69e85bdd9e3..e58bcaf9574 100644 --- a/lldb/packages/Python/lldbsuite/test/dosep.py +++ b/lldb/packages/Python/lldbsuite/test/dosep.py @@ -52,6 +52,7 @@ from six.moves import queue import lldbsuite import lldbsuite.support.seven as seven +from lldbsuite.support import optional_with from . import configuration from . import dotest_channels from . import dotest_args @@ -59,12 +60,7 @@ from . import result_formatter from .result_formatter import EventBuilder - -# Todo: Convert this folder layout to be relative-import friendly and -# don't hack up sys.path like this -sys.path.append(os.path.join(os.path.dirname(__file__), "test_runner", "lib")) -import lldb_utils -import process_control +from .test_runner import process_control # Status codes for running command with timeout. eTimedOut, ePassed, eFailed = 124, 0, 1 @@ -177,7 +173,7 @@ class DoTestProcessDriver(process_control.ProcessDriver): super(DoTestProcessDriver, self).__init__( soft_terminate_timeout=soft_terminate_timeout) self.output_file = output_file - self.output_lock = lldb_utils.OptionalWith(output_file_lock) + self.output_lock = optional_with.optional_with(output_file_lock) self.pid_events = pid_events self.results = None self.file_name = file_name diff --git a/lldb/packages/Python/lldbsuite/test/test_runner/__init__.py b/lldb/packages/Python/lldbsuite/test/test_runner/__init__.py new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/test_runner/__init__.py diff --git a/lldb/packages/Python/lldbsuite/test/test_runner/lib/process_control.py b/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py index a7e639e4b8b..a7e639e4b8b 100644 --- a/lldb/packages/Python/lldbsuite/test/test_runner/lib/process_control.py +++ b/lldb/packages/Python/lldbsuite/test/test_runner/process_control.py diff --git a/lldb/packages/Python/lldbsuite/test/test_runner/test/__init__.py b/lldb/packages/Python/lldbsuite/test/test_runner/test/__init__.py new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/lldb/packages/Python/lldbsuite/test/test_runner/test/__init__.py diff --git a/lldb/packages/Python/lldbsuite/test/test_runner/test/process_control_tests.py b/lldb/packages/Python/lldbsuite/test/test_runner/test/test_process_control.py index 354506d6581..817c83c4fb5 100755 --- a/lldb/packages/Python/lldbsuite/test/test_runner/test/process_control_tests.py +++ b/lldb/packages/Python/lldbsuite/test/test_runner/test/test_process_control.py @@ -12,18 +12,18 @@ within the LLDB test suite. Tests the process_control module. """ +from __future__ import print_function + # System imports. import os +import os.path import platform import unittest import sys import threading -# Add lib dir to pythonpath -sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'lib')) - # Our imports. -import process_control +from test_runner import process_control class TestInferiorDriver(process_control.ProcessDriver): @@ -77,7 +77,10 @@ class ProcessControlTests(unittest.TestCase): options=None): # Base command. - command = ([sys.executable, "inferior.py"]) + script_name = "{}/inferior.py".format(os.path.dirname(__file__)) + if not os.path.exists(script_name): + raise Exception("test inferior python script not found: {}".format(script_name)) + command = ([sys.executable, script_name]) if ignore_soft_terminate: cls._suppress_soft_terminate(command) |