Unverified Commit f44129c4 authored by jsmith-bdai's avatar jsmith-bdai Committed by GitHub

Fixes test-runner helper script to run from any directory (#406)

# Description

Enables running `orbit -t` from any directory

Fixes #405 

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./orbit.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] I have run all the tests with `./orbit.sh --test` and they pass
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------
Signed-off-by: 's avatarjsmith-bdai <142246516+jsmith-bdai@users.noreply.github.com>
Co-authored-by: 's avatarMayank Mittal <12863862+Mayankm96@users.noreply.github.com>
parent 8ff79600
...@@ -315,7 +315,7 @@ while [[ $# -gt 0 ]]; do ...@@ -315,7 +315,7 @@ while [[ $# -gt 0 ]]; do
# run the python provided by isaacsim # run the python provided by isaacsim
python_exe=$(extract_python_exe) python_exe=$(extract_python_exe)
shift # past argument shift # past argument
${python_exe} tools/run_all_tests.py $@ ${python_exe} ${ORBIT_PATH}/tools/run_all_tests.py $@
# exit neatly # exit neatly
break break
;; ;;
......
...@@ -34,6 +34,9 @@ from prettytable import PrettyTable ...@@ -34,6 +34,9 @@ from prettytable import PrettyTable
# Tests to skip # Tests to skip
from tests_to_skip import TESTS_TO_SKIP from tests_to_skip import TESTS_TO_SKIP
ORBIT_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
"""Path to the root directory of Orbit repository."""
def parse_args() -> argparse.Namespace: def parse_args() -> argparse.Namespace:
"""Parse command line arguments.""" """Parse command line arguments."""
...@@ -46,6 +49,21 @@ def parse_args() -> argparse.Namespace: ...@@ -46,6 +49,21 @@ def parse_args() -> argparse.Namespace:
type=str, type=str,
nargs="*", nargs="*",
) )
# configure default test directory (source directory)
default_test_dir = os.path.join(ORBIT_PATH, "source")
parser.add_argument(
"--test_dir", type=str, default=default_test_dir, help="Path to the directory containing the tests."
)
# configure default logging path based on time stamp
log_file_name = "test_results_" + datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + ".log"
default_log_path = os.path.join(ORBIT_PATH, "logs", log_file_name)
parser.add_argument(
"--log_path", type=str, default=default_log_path, help="Path to the log file to store the results in."
)
parser.add_argument("--discover_only", action="store_true", help="Only discover and print tests, don't run them.") parser.add_argument("--discover_only", action="store_true", help="Only discover and print tests, don't run them.")
parser.add_argument("--quiet", action="store_true", help="Don't print to console, only log to file.") parser.add_argument("--quiet", action="store_true", help="Don't print to console, only log to file.")
parser.add_argument("--timeout", type=int, default=600, help="Timeout for each test in seconds.") parser.add_argument("--timeout", type=int, default=600, help="Timeout for each test in seconds.")
...@@ -74,7 +92,11 @@ def test_all( ...@@ -74,7 +92,11 @@ def test_all(
Defaults to False. Defaults to False.
Returns: Returns:
True if all un-skipped tests pass or :attr:`discover_only` is True. Otherwise, False. True if all un-skipped tests pass or `discover_only` is True. Otherwise, False.
Raises:
ValueError: If any test to skip is not found under the given `test_dir`.
""" """
# Create the log directory if it doesn't exist # Create the log directory if it doesn't exist
os.makedirs(os.path.dirname(log_path), exist_ok=True) os.makedirs(os.path.dirname(log_path), exist_ok=True)
...@@ -143,11 +165,16 @@ def test_all( ...@@ -143,11 +165,16 @@ def test_all(
completed_process = subprocess.run( completed_process = subprocess.run(
["bash", orbit_shell_path, "-p", test_path], check=True, capture_output=True, timeout=timeout ["bash", orbit_shell_path, "-p", test_path], check=True, capture_output=True, timeout=timeout
) )
print(f"Completed Process: {completed_process}")
print(f"stdout: {completed_process.stdout}")
print(f"stderr: {completed_process.stderr}")
except subprocess.TimeoutExpired as e: except subprocess.TimeoutExpired as e:
print(f"Timeout occurred: {e}")
result = "TIMEDOUT" result = "TIMEDOUT"
stdout = e.stdout stdout = e.stdout
stderr = e.stderr stderr = e.stderr
except Exception as e: except Exception as e:
print(f"Exception {e}!")
result = "FAILED" result = "FAILED"
stdout = e.stdout stdout = e.stdout
stderr = e.stderr stderr = e.stderr
...@@ -234,15 +261,14 @@ if __name__ == "__main__": ...@@ -234,15 +261,14 @@ if __name__ == "__main__":
# add tests to skip to the list of tests to skip # add tests to skip to the list of tests to skip
tests_to_skip = TESTS_TO_SKIP tests_to_skip = TESTS_TO_SKIP
tests_to_skip += args.skip_tests tests_to_skip += args.skip_tests
# configure test directory (source directory)
test_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "source")
# configure logging
log_file_name = "test_results_" + datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + ".log"
log_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "logs", log_file_name)
# run all tests # run all tests
test_success = test_all( test_success = test_all(
test_dir, tests_to_skip, log_path, timeout=args.timeout, discover_only=args.discover_only, quiet=args.quiet test_dir=args.test_dir,
tests_to_skip=tests_to_skip,
log_path=args.log_path,
timeout=args.timeout,
discover_only=args.discover_only,
quiet=args.quiet,
) )
# update exit status based on all tests passing or not # update exit status based on all tests passing or not
if not test_success: if not test_success:
......
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