From b1697b8afa49f3300bb4912adac41844be4f8274 Mon Sep 17 00:00:00 2001 From: Ben Wooding <38587669+Kiguli@users.noreply.github.com> Date: Fri, 5 Sep 2025 10:13:04 +0100 Subject: [PATCH 1/5] Testing Workflow for versions testing installation for python 3.9, 3.10 and 3.11. --- .github/workflows/python-package.yml | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/python-package.yml diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..e56abb6 --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,40 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest From 58133db2130020e1d4a911aaa62eb471048f1fc3 Mon Sep 17 00:00:00 2001 From: Ben Wooding <38587669+Kiguli@users.noreply.github.com> Date: Fri, 5 Sep 2025 10:23:28 +0100 Subject: [PATCH 2/5] Modify linting and testing to exclude FOSSIL parts --- .github/workflows/python-package.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index e56abb6..9e34c50 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -32,9 +32,9 @@ jobs: - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude fossil-main,ex/benchmarks-deterministic/FOSSIL-versions # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude fossil-main,ex/benchmarks-deterministic/FOSSIL-versions - name: Test with pytest run: | - pytest + pytest --ignore=fossil-main --ignore=ex/benchmarks-deterministic/FOSSIL-versions From 8770039f62e45afd7aa83c3a72b067f42b23672d Mon Sep 17 00:00:00 2001 From: Ben Wooding <38587669+Kiguli@users.noreply.github.com> Date: Fri, 5 Sep 2025 10:28:15 +0100 Subject: [PATCH 3/5] Create test for main.py execution --- tests/test_main.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/test_main.py diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..1538dc8 --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,13 @@ +import subprocess +import sys +import os + +def test_main_runs(): + """Check that main.py runs without errors.""" + result = subprocess.run( + [sys.executable, os.path.join(os.path.dirname(__file__), "..", "main.py")], + capture_output=True, + text=True + ) + # Assert that the script exits successfully + assert result.returncode == 0, f"main.py failed with error:\n{result.stderr}" From 9a5f1f6bde80e31c8535960f028cca8158a4945b Mon Sep 17 00:00:00 2001 From: Ben Wooding <38587669+Kiguli@users.noreply.github.com> Date: Fri, 5 Sep 2025 10:33:56 +0100 Subject: [PATCH 4/5] Rename test and check benchmark script execution --- tests/test_main.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 1538dc8..87bc86c 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,12 +2,23 @@ import sys import os -def test_main_runs(): - """Check that main.py runs without errors.""" +def test_benchmark_runs(): + """Check that the benchmark script runs without errors.""" + + # Path to the benchmark script (update if needed) + benchmark_path = os.path.join( + os.path.dirname(__file__), + "..", "ex", "benchmarks-deterministic", "PRoTECT-versions", "ex1_dt_DS.py" + ) + + # Verify the file exists before running + assert os.path.exists(benchmark_path), f"Benchmark script not found: {benchmark_path}" + result = subprocess.run( - [sys.executable, os.path.join(os.path.dirname(__file__), "..", "main.py")], + [sys.executable, benchmark_path], capture_output=True, text=True ) - # Assert that the script exits successfully - assert result.returncode == 0, f"main.py failed with error:\n{result.stderr}" + + # Assert successful exit + assert result.returncode == 0, f"Benchmark failed with error:\n{result.stderr}" From c916f5dae83475f1f7a24392894d56d879523cba Mon Sep 17 00:00:00 2001 From: Ben Wooding <38587669+Kiguli@users.noreply.github.com> Date: Fri, 5 Sep 2025 10:36:27 +0100 Subject: [PATCH 5/5] Update test to include PYTHONPATH environment variable --- tests/test_main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 87bc86c..22bcb8f 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -5,20 +5,21 @@ def test_benchmark_runs(): """Check that the benchmark script runs without errors.""" - # Path to the benchmark script (update if needed) benchmark_path = os.path.join( os.path.dirname(__file__), "..", "ex", "benchmarks-deterministic", "PRoTECT-versions", "ex1_dt_DS.py" ) - # Verify the file exists before running assert os.path.exists(benchmark_path), f"Benchmark script not found: {benchmark_path}" + env = os.environ.copy() + env["PYTHONPATH"] = os.path.join(os.path.dirname(__file__), "..") + result = subprocess.run( [sys.executable, benchmark_path], capture_output=True, - text=True + text=True, + env=env ) - # Assert successful exit assert result.returncode == 0, f"Benchmark failed with error:\n{result.stderr}"