From 2a731da972374b6b76c6bddfcea55a98f9074b78 Mon Sep 17 00:00:00 2001 From: Martin Medler Date: Sun, 5 May 2024 11:56:21 +0200 Subject: [PATCH] Make test scripts less path dependent --- .github/workflows/ci.yaml | 13 +++---------- examples/test.py | 6 ++++++ test/aspect/execute_tests.py | 6 ++++++ tests.sh | 9 +++------ 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1528359b..eaf30ff8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -49,10 +49,7 @@ jobs: - uses: actions/checkout@v4 - name: Integration tests - Aspect if: runner.os != 'Windows' - run: | - cd test - cd aspect - python execute_tests.py + run: python test/aspect/execute_tests.py - name: Integration tests - Aspect if: runner.os == 'Windows' run: | @@ -84,10 +81,6 @@ jobs: steps: - uses: actions/checkout@v4 - name: Integration tests - Examples - run: | - cd examples - python test.py + run: python examples/test.py - name: Integration tests - Examples with legacy WORKSPACE setup - run: | - cd examples - python test.py --legacy-workspace + run: python examples/test.py --legacy-workspace diff --git a/examples/test.py b/examples/test.py index b36a4c0d..ee212743 100755 --- a/examples/test.py +++ b/examples/test.py @@ -6,6 +6,8 @@ import sys from argparse import ArgumentParser, Namespace from dataclasses import dataclass +from os import chdir +from pathlib import Path logging.basicConfig(format="%(message)s", level=logging.INFO) @@ -138,4 +140,8 @@ def main(legacy_workspace: bool) -> int: if __name__ == "__main__": args = cli() + + # Ensure we can invoke the script from various places + chdir(Path(__file__).parent) + sys.exit(main(args.legacy_workspace)) diff --git a/test/aspect/execute_tests.py b/test/aspect/execute_tests.py index b427e85c..1661c65d 100755 --- a/test/aspect/execute_tests.py +++ b/test/aspect/execute_tests.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 import logging from argparse import ArgumentParser, Namespace +from os import chdir +from pathlib import Path from sys import exit from execution_logic import main @@ -92,6 +94,10 @@ def cli() -> Namespace: args = cli() if args.verbose: logging.getLogger().setLevel(logging.DEBUG) + + # Ensure we can invoke the script from various places + chdir(Path(__file__).parent) + exit( main( tested_versions=TESTED_VERSIONS, diff --git a/tests.sh b/tests.sh index b1d7bba5..8d887840 100755 --- a/tests.sh +++ b/tests.sh @@ -35,9 +35,7 @@ cd - echo "" echo "Execute integration tests - Aspect" echo "" -cd test/aspect -./execute_tests.py -cd - +./test/aspect/execute_tests.py echo "" echo "Execute integration tests - Applying fixes" @@ -47,10 +45,9 @@ echo "" echo "" echo "Execute integration tests - Examples with bzlmod" echo "" -cd examples -./test.py +./examples/test.py echo "" echo "Execute integration tests - Examples with WORKSPACE setup" echo "" -./test.py --legacy-workspace +./examples/test.py --legacy-workspace