diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 000000000..d1638fe52 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,9 @@ +[run] +parallel = true +include = + src/algorithms/classic/graph_based/* + *_manager.py + src/maps/* + src/simulator/* + src/structures/* + src/algorithms/configuration/* diff --git a/.github/workflows/test-PRs.yml b/.github/workflows/test-PRs.yml index b50d12f13..b1818e5aa 100644 --- a/.github/workflows/test-PRs.yml +++ b/.github/workflows/test-PRs.yml @@ -12,7 +12,7 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: matrix: python-version: [3.8.5] @@ -27,8 +27,8 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - sudo apt-get install xvfb scrot - python -m pip install --upgrade pip + sudo apt-get install -y xvfb scrot gcc + python -m pip install --upgrade pip setuptools wheel pip install flake8 coverage if [ -f requirements.txt ]; then pip install -r requirements.txt; fi if [ -f tests/requirements.txt ]; then pip install -r tests/requirements.txt; fi @@ -40,5 +40,7 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Run tests with coverage and upload run: | - coverage run tests/run_tests.py --cov-report=xml --spawn-display - bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} -e PYTHON + CODECOV_EXEC="coverage run -p" + $CODECOV_EXEC tests/run_tests.py --spawn-display + ls -a + bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} -e PYTHON -f '.coverage.*' diff --git a/src/main.py b/src/main.py index 34f12be6c..1155c28ea 100644 --- a/src/main.py +++ b/src/main.py @@ -1,20 +1,23 @@ -from algorithms.configuration.configuration import Configuration -from algorithms.algorithm_manager import AlgorithmManager -from maps.map_manager import MapManager -from algorithms.lstm.trainer import Trainer -from analyzer.analyzer import Analyzer -from generator.generator import Generator -from simulator.services.debug import DebugLevel -from simulator.services.services import Services -from simulator.simulator import Simulator -from utility.misc import flatten -from utility.argparse import add_configuration_flags - -import copy import sys import os -import argparse -from typing import List, Callable + +# Compatibility for running with codecov, add 'PathBench/src' to system path for module imports +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + +from algorithms.configuration.configuration import Configuration # noqa: E402 +from algorithms.algorithm_manager import AlgorithmManager # noqa: E402 +from maps.map_manager import MapManager # noqa: E402 +from algorithms.lstm.trainer import Trainer # noqa: E402 +from analyzer.analyzer import Analyzer # noqa: E402 +from generator.generator import Generator # noqa: E402 +from simulator.services.debug import DebugLevel # noqa: E402 +from simulator.services.services import Services # noqa: E402 +from simulator.simulator import Simulator # noqa: E402 +from utility.misc import flatten # noqa: E402 +from utility.argparse import add_configuration_flags # noqa: E402 + +import argparse # noqa: E402 +from typing import List, Callable # noqa: E402 class MainRunner: main_services: Services diff --git a/tests/run_tests.py b/tests/run_tests.py index a8cf1affd..4a2aac00a 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -5,14 +5,17 @@ import unittest from unittest import TestLoader, TestSuite, TextTestRunner, TestResult -from utils import make_src_modules_importable +# Compatibility for running with codecov, add 'PathBench/tests' to system path for module imports +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + +from utils import make_src_modules_importable # noqa: E402 def run() -> bool: # add src folder to system path make_src_modules_importable() tests_path = os.path.dirname(os.path.abspath(__file__)) - + parser = argparse.ArgumentParser(prog="run_tests.py", description="PathBench test runner", formatter_class=argparse.RawTextHelpFormatter) @@ -28,6 +31,7 @@ def run() -> bool: res: TestResult = testRunner.run(tests) return (len(res.errors) == 0 and len(res.failures) == 0) + if __name__ == '__main__': res = run() sys.exit(int(not res)) diff --git a/tests/test_graphics/common.py b/tests/test_graphics/common.py index da4d248a7..ed83c9cef 100644 --- a/tests/test_graphics/common.py +++ b/tests/test_graphics/common.py @@ -45,8 +45,12 @@ def setup(args: argparse.Namespace, visualiser_args: List[str]) -> None: # enforce correct display being used pyautogui._pyautogui_x11._display = Xlib.display.Display(os.environ['DISPLAY']) + # Fall back to sys executable if no env variable to specify how to run with codecov + executable_name = os.environ.get("CODECOV_EXEC", sys.executable) + print(f"Using executable {executable_name}") + if not args.no_launch_visualiser: - launch_process([sys.executable, os.path.join(SRC_PATH, 'main.py'), '-d', args.debug, '-v', '-Vwindowed-fullscreen', + launch_process([executable_name, os.path.join(SRC_PATH, 'main.py'), '-d', args.debug, '-v', '-Vwindowed-fullscreen', '-Vaudio-library-name=null', '--deterministic'] + visualiser_args, on_kill=lambda _: pyautogui.press('esc')) diff --git a/tests/utils.py b/tests/utils.py index 0147b9dca..d12df5a47 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -22,6 +22,9 @@ def handle_display_args(args) -> None: from utility.process import launch_process sys.path.pop(0) # remove src folder from path + if 'DISPLAY' not in os.environ: + args.spawn_display = ':99' + if args.spawn_display: cmd = ["Xvfb", args.spawn_display, "-screen", "0", "2112x1376x24", "-fbdir", "/var/tmp"] if 'DISPLAY' in os.environ: