From 616042874bf13d75cbe41542ea48749914e4aa8e Mon Sep 17 00:00:00 2001 From: Abel Shields Date: Fri, 8 Jan 2021 11:45:55 +0000 Subject: [PATCH 01/15] Adding source for codecov --- .github/workflows/test-PRs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-PRs.yml b/.github/workflows/test-PRs.yml index b50d12f13..bcbfd8a77 100644 --- a/.github/workflows/test-PRs.yml +++ b/.github/workflows/test-PRs.yml @@ -40,5 +40,5 @@ 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 + coverage run --source . tests/run_tests.py --cov-report=xml --spawn-display bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} -e PYTHON From 70ebf88f435b3bfa299c46a767deeac02c7a68c9 Mon Sep 17 00:00:00 2001 From: Abel Shields Date: Fri, 8 Jan 2021 12:02:41 +0000 Subject: [PATCH 02/15] Experimenting --- .github/workflows/test-PRs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-PRs.yml b/.github/workflows/test-PRs.yml index bcbfd8a77..347d29c26 100644 --- a/.github/workflows/test-PRs.yml +++ b/.github/workflows/test-PRs.yml @@ -40,5 +40,5 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Run tests with coverage and upload run: | - coverage run --source . tests/run_tests.py --cov-report=xml --spawn-display + coverage run --source src/ tests/run_tests.py --cov-report=xml --spawn-display bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} -e PYTHON From 01dd446cfab70bc691bd35c325ac9b3c19913c2c Mon Sep 17 00:00:00 2001 From: Abel Shields Date: Fri, 8 Jan 2021 12:43:45 +0000 Subject: [PATCH 03/15] Working on making codecov executable carry through tests --- .github/workflows/test-PRs.yml | 3 ++- src/main.py | 9 +++++++++ tests/test_graphics/common.py | 5 ++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-PRs.yml b/.github/workflows/test-PRs.yml index 347d29c26..02e757903 100644 --- a/.github/workflows/test-PRs.yml +++ b/.github/workflows/test-PRs.yml @@ -40,5 +40,6 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Run tests with coverage and upload run: | - coverage run --source src/ tests/run_tests.py --cov-report=xml --spawn-display + CODECOV_EXEC="coverage run --source src/ --cov-report=xml --spawn-display -o .coverage-$$RANDOM.xml" + $CODECOV_EXEC tests/run_tests.py bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} -e PYTHON diff --git a/src/main.py b/src/main.py index 34f12be6c..1ba6d29f8 100644 --- a/src/main.py +++ b/src/main.py @@ -1,3 +1,12 @@ +# Compatibility for running with codecov + +# The following path correction fixes a bug where codecov doesn't +# run the file with the same `sys.path` as the python executable would. +# It can't be put into `utility` as we can't import anything relatively until it's fixed. +import sys, os +if not sys.path[0].endswith("src"): + sys.path[0] = os.path.join(sys.path[0], "src") + from algorithms.configuration.configuration import Configuration from algorithms.algorithm_manager import AlgorithmManager from maps.map_manager import MapManager diff --git a/tests/test_graphics/common.py b/tests/test_graphics/common.py index 87f8a87e1..32411f45e 100644 --- a/tests/test_graphics/common.py +++ b/tests/test_graphics/common.py @@ -45,9 +45,12 @@ def setup(args) -> 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) + if not args.no_launch_visualiser: launch_process( - [sys.executable, os.path.join(SRC_PATH, 'main.py'), '-d', args.debug, '-v', '-Vwindowed-fullscreen', + [executable_name, os.path.join(SRC_PATH, 'main.py'), '-d', args.debug, '-v', '-Vwindowed-fullscreen', '-Vaudio-library-name=null', '--deterministic'], on_kill=lambda _: pyautogui.press('esc')) From babf8d2da03b75af743de757b897ba2c3c2d4a03 Mon Sep 17 00:00:00 2001 From: Abel Shields Date: Fri, 8 Jan 2021 14:32:37 +0000 Subject: [PATCH 04/15] Testing cov --- .github/workflows/test-PRs.yml | 4 ++-- tests/run_tests.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-PRs.yml b/.github/workflows/test-PRs.yml index 02e757903..0379ff929 100644 --- a/.github/workflows/test-PRs.yml +++ b/.github/workflows/test-PRs.yml @@ -40,6 +40,6 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Run tests with coverage and upload run: | - CODECOV_EXEC="coverage run --source src/ --cov-report=xml --spawn-display -o .coverage-$$RANDOM.xml" - $CODECOV_EXEC tests/run_tests.py + CODECOV_EXEC="coverage run --source src/ -p" + $CODECOV_EXEC tests/run_tests.py --spawn-display bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} -e PYTHON diff --git a/tests/run_tests.py b/tests/run_tests.py index a8cf1affd..5d173f516 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -1,5 +1,12 @@ -import sys -import os +# Compatibility for running with codecov + +# The following path correction fixes a bug where codecov doesn't +# run the file with the same `sys.path` as the python executable would. +# It can't be put into `utility` as we can't import anything relatively until it's fixed. +import sys, os +if not sys.path[0].endswith("tests"): + sys.path[0] = os.path.join(sys.path[0], "tests") + import argparse import atexit import unittest From 72758f3ee1e205ad57b93590c524f1c55bb38a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=5B=20=E5=A4=A7=E9=B3=84=20=5D=20Asew?= Date: Fri, 8 Jan 2021 16:25:00 +0000 Subject: [PATCH 05/15] Polished code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: [ 大鳄 ] Asew --- src/main.py | 42 ++++++++++++++++++------------------------ tests/run_tests.py | 16 ++++++---------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/src/main.py b/src/main.py index 1ba6d29f8..ca6c41240 100644 --- a/src/main.py +++ b/src/main.py @@ -1,29 +1,23 @@ -# Compatibility for running with codecov - -# The following path correction fixes a bug where codecov doesn't -# run the file with the same `sys.path` as the python executable would. -# It can't be put into `utility` as we can't import anything relatively until it's fixed. -import sys, os -if not sys.path[0].endswith("src"): - sys.path[0] = os.path.join(sys.path[0], "src") - -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 # npqa: 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 5d173f516..e391a7079 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -1,18 +1,14 @@ -# Compatibility for running with codecov - -# The following path correction fixes a bug where codecov doesn't -# run the file with the same `sys.path` as the python executable would. -# It can't be put into `utility` as we can't import anything relatively until it's fixed. -import sys, os -if not sys.path[0].endswith("tests"): - sys.path[0] = os.path.join(sys.path[0], "tests") - +import sys +import os import argparse import atexit 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 From 4c21a8d9b8c115f26bb3489df264e6baebb1a54b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=5B=20=E5=A4=A7=E9=B3=84=20=5D=20Asew?= Date: Fri, 8 Jan 2021 16:25:35 +0000 Subject: [PATCH 06/15] Formatted code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: [ 大鳄 ] Asew --- src/main.py | 2 +- tests/run_tests.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index ca6c41240..1155c28ea 100644 --- a/src/main.py +++ b/src/main.py @@ -4,7 +4,7 @@ # 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 # npqa: E402 +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 diff --git a/tests/run_tests.py b/tests/run_tests.py index e391a7079..4a2aac00a 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -15,7 +15,7 @@ def run() -> bool: 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) @@ -31,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)) From c2da3fc5a5c61c8103bffae88127a25869d264f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=5B=20=E5=A4=A7=E9=B3=84=20=5D=20Asew?= Date: Fri, 8 Jan 2021 16:27:12 +0000 Subject: [PATCH 07/15] Removed parallel testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: [ 大鳄 ] Asew --- .github/workflows/test-PRs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-PRs.yml b/.github/workflows/test-PRs.yml index 0379ff929..7a0bf620b 100644 --- a/.github/workflows/test-PRs.yml +++ b/.github/workflows/test-PRs.yml @@ -40,6 +40,6 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Run tests with coverage and upload run: | - CODECOV_EXEC="coverage run --source src/ -p" + CODECOV_EXEC="coverage run --source src/" $CODECOV_EXEC tests/run_tests.py --spawn-display bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} -e PYTHON From 4be2654a4b22d8df2aad3865ef863d165b02987b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=5B=20=E5=A4=A7=E9=B3=84=20=5D=20Asew?= Date: Fri, 8 Jan 2021 16:34:37 +0000 Subject: [PATCH 08/15] Added debug code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: [ 大鳄 ] Asew --- tests/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/utils.py b/tests/utils.py index 0147b9dca..ef6bfa6f5 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -40,6 +40,11 @@ def on_display_kill(*discard) -> None: time.sleep(0.2) if os.path.exists("/var/tmp/Xvfb_screen0"): break + + print("DISPLAY", os.environ['DISPLAY'], file=sys.stderr) + else: + print("NO DISPLAY", file=sys.stderr) + if args.view_display: display = os.environ['DISPLAY'] if args.view_display == "auto" else args.view_display From 6d7e583f096684879aa5107a65991b8663708f8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=5B=20=E5=A4=A7=E9=B3=84=20=5D=20Asew?= Date: Fri, 8 Jan 2021 16:43:50 +0000 Subject: [PATCH 09/15] Fixed CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: [ 大鳄 ] Asew --- tests/utils.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index ef6bfa6f5..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: @@ -40,11 +43,6 @@ def on_display_kill(*discard) -> None: time.sleep(0.2) if os.path.exists("/var/tmp/Xvfb_screen0"): break - - print("DISPLAY", os.environ['DISPLAY'], file=sys.stderr) - else: - print("NO DISPLAY", file=sys.stderr) - if args.view_display: display = os.environ['DISPLAY'] if args.view_display == "auto" else args.view_display From 28ba51b9c17bc5167822a9dc5732572d4e6590de Mon Sep 17 00:00:00 2001 From: Abel Shields Date: Sat, 9 Jan 2021 13:26:22 +0000 Subject: [PATCH 10/15] Added .coveragerc making parallel - no overwrites by different processes Updated coveragerc --- .coveragerc | 8 ++++++++ .github/workflows/test-PRs.yml | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 000000000..7bbd36fd2 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,8 @@ +[run] +parallel = true +include = + src/algorithms/classic/graph_based/* + *_manager.py + src/maps/* + src/simulator/* + src/structures/* diff --git a/.github/workflows/test-PRs.yml b/.github/workflows/test-PRs.yml index 7a0bf620b..c49a957de 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,7 +27,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - sudo apt-get install xvfb scrot + sudo apt-get install -y xvfb scrot python -m pip install --upgrade pip pip install flake8 coverage if [ -f requirements.txt ]; then pip install -r requirements.txt; fi @@ -40,6 +40,6 @@ jobs: flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Run tests with coverage and upload run: | - CODECOV_EXEC="coverage run --source src/" + CODECOV_EXEC="coverage run -p" $CODECOV_EXEC tests/run_tests.py --spawn-display bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} -e PYTHON From 205aeb92119cc1631946ee8256759acf8ade0197 Mon Sep 17 00:00:00 2001 From: Abel Shields Date: Sat, 9 Jan 2021 15:00:21 +0000 Subject: [PATCH 11/15] Added more to coverage --- .coveragerc | 1 + 1 file changed, 1 insertion(+) diff --git a/.coveragerc b/.coveragerc index 7bbd36fd2..d1638fe52 100644 --- a/.coveragerc +++ b/.coveragerc @@ -6,3 +6,4 @@ include = src/maps/* src/simulator/* src/structures/* + src/algorithms/configuration/* From b99204c22126bf3992e5672d79d3026a27f102bf Mon Sep 17 00:00:00 2001 From: Abel Shields Date: Sat, 9 Jan 2021 15:12:19 +0000 Subject: [PATCH 12/15] Upload all coverage --- .github/workflows/test-PRs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-PRs.yml b/.github/workflows/test-PRs.yml index c49a957de..65e923603 100644 --- a/.github/workflows/test-PRs.yml +++ b/.github/workflows/test-PRs.yml @@ -42,4 +42,4 @@ jobs: run: | CODECOV_EXEC="coverage run -p" $CODECOV_EXEC tests/run_tests.py --spawn-display - bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} -e PYTHON + bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }} -e PYTHON -f '.coverage.*' From a5703b4460066812153bd6333f190cce732705ec Mon Sep 17 00:00:00 2001 From: Abel Shields Date: Sat, 9 Jan 2021 15:56:15 +0000 Subject: [PATCH 13/15] Looking for coverage files --- .github/workflows/test-PRs.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-PRs.yml b/.github/workflows/test-PRs.yml index 65e923603..c2b47d853 100644 --- a/.github/workflows/test-PRs.yml +++ b/.github/workflows/test-PRs.yml @@ -21,14 +21,22 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Fix local runner + run: | + # Hack to get setup-python to work on act + # (see https://github.com/nektos/act/issues/251) + if [ ! -f "/etc/lsb-release" ] ; then + echo "DISTRIB_RELEASE=18.04" > /etc/lsb-release + fi + apt update && apt install -y sudo - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | - sudo apt-get install -y 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 @@ -42,4 +50,5 @@ jobs: run: | 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.*' From a7a17dbe16922716be6627d06e6b5c3f2d20a085 Mon Sep 17 00:00:00 2001 From: Abel Shields Date: Sat, 9 Jan 2021 15:58:49 +0000 Subject: [PATCH 14/15] Looking for coverage files --- .github/workflows/test-PRs.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/test-PRs.yml b/.github/workflows/test-PRs.yml index c2b47d853..b1818e5aa 100644 --- a/.github/workflows/test-PRs.yml +++ b/.github/workflows/test-PRs.yml @@ -21,14 +21,6 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Fix local runner - run: | - # Hack to get setup-python to work on act - # (see https://github.com/nektos/act/issues/251) - if [ ! -f "/etc/lsb-release" ] ; then - echo "DISTRIB_RELEASE=18.04" > /etc/lsb-release - fi - apt update && apt install -y sudo - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: From 8f5eccc6ce7552870c2ca08e527eacb46342c7d9 Mon Sep 17 00:00:00 2001 From: Abel Shields Date: Sun, 10 Jan 2021 18:05:29 +0000 Subject: [PATCH 15/15] Checking exec_name --- tests/test_graphics/common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_graphics/common.py b/tests/test_graphics/common.py index c25719585..ed83c9cef 100644 --- a/tests/test_graphics/common.py +++ b/tests/test_graphics/common.py @@ -47,6 +47,7 @@ def setup(args: argparse.Namespace, visualiser_args: List[str]) -> None: # 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([executable_name, os.path.join(SRC_PATH, 'main.py'), '-d', args.debug, '-v', '-Vwindowed-fullscreen',