From 92dabff53a49c5635b6b5a5e11e9a8e875966719 Mon Sep 17 00:00:00 2001 From: Valentina Vecchio <73996787+bualust@users.noreply.github.com> Date: Fri, 18 Apr 2025 12:19:59 +0100 Subject: [PATCH 1/5] Create python-app.yml --- .github/workflows/python-app.yml | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..c99b9ce --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,38 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + pip install . + - 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 ce091f602c8539f3722baeb30e8723eecd207f4d Mon Sep 17 00:00:00 2001 From: Valentina Vecchio Date: Fri, 18 Apr 2025 13:07:42 +0100 Subject: [PATCH 2/5] act config for local actions test --- .actrc | 2 ++ .github/workflows/pre-commit.yml | 7 ++++++- README.md | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .actrc diff --git a/.actrc b/.actrc new file mode 100644 index 0000000..2786bf7 --- /dev/null +++ b/.actrc @@ -0,0 +1,2 @@ +--container-architecture=linux/amd64 +--action-offline-mode diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index ff1548a..494a45f 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -11,7 +11,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + - name: Install ruff + run: pip install ruff - name: Get pre-commit uses: pre-commit/action@v3.0.0 - name: Run pre-commit diff --git a/README.md b/README.md index ec79464..a082a03 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,16 @@ build website with bundle ```bash bundle exec jekyll serve --port 4001 ``` + +## Test actions locally + +Using [act](https://nektosact.com/introduction.html) + +Make sure Docker is running then simply +```bash +act +``` +If you want to run it on one of the actions simply +```bash +act -W .github/workflows/action.yml +``` From decdbb353c0626441c5de16babcd46309506c873 Mon Sep 17 00:00:00 2001 From: Valentina Vecchio Date: Fri, 18 Apr 2025 13:10:03 +0100 Subject: [PATCH 3/5] run ruff only on pre-commit and remove pylint and black --- .github/workflows/python-app.yml | 8 +------- pyproject.toml | 7 ++++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index c99b9ce..4041c45 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -26,13 +26,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 pytest + pip install pytest pip install . - - 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 diff --git a/pyproject.toml b/pyproject.toml index c200d72..90f02ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,8 +12,9 @@ dependencies = [ "matplotlib", ] -[project.optional-dependencies] -dev = ["pylint", "black"] - [project.scripts] randomfpl = "randomfpl:main" + +[tool.pytest.ini_options] +asyncio_mode = "strict" +asyncio_default_fixture_loop_scope = "function" From 10cb5ec71e73190be7ec43f6a5dad5ebdbeb6996 Mon Sep 17 00:00:00 2001 From: Valentina Vecchio Date: Fri, 18 Apr 2025 14:43:53 +0100 Subject: [PATCH 4/5] move parse_args to its own function --- randomfpl/fantasy_random.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/randomfpl/fantasy_random.py b/randomfpl/fantasy_random.py index c8deaa2..ea2fc71 100644 --- a/randomfpl/fantasy_random.py +++ b/randomfpl/fantasy_random.py @@ -10,6 +10,12 @@ def main(): """`main` function for RandomFPL module""" + args = parse_args() + asyncio.run(generate_team(args)) + + +def parse_args(): + """'parse_args' returns parser.parse_args()""" parser = argparse.ArgumentParser() parser.add_argument( "--show_average", @@ -51,7 +57,7 @@ def main(): ) args = parser.parse_args() - asyncio.run(generate_team(args)) + return args async def generate_team(args): From 7dfbd8e0e0288a45ff2b9e88decd88bbbd9e7082 Mon Sep 17 00:00:00 2001 From: Valentina Vecchio Date: Fri, 18 Apr 2025 15:08:17 +0100 Subject: [PATCH 5/5] feat: test generate_team(args) function --- _tests/test_generate_team.py | 16 ++++++++++++++++ randomfpl/fantasy_random.py | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 _tests/test_generate_team.py diff --git a/_tests/test_generate_team.py b/_tests/test_generate_team.py new file mode 100644 index 0000000..42a770f --- /dev/null +++ b/_tests/test_generate_team.py @@ -0,0 +1,16 @@ +from randomfpl.fantasy_random import generate_team +import argparse +import asyncio + + +def test_generate_team(): + args = argparse.Namespace( + max_expense=100, + show_average=False, + show_toprank=False, + show_ext_info=False, + veto_player=False, + veto_teams=False, + ) + team = asyncio.run(generate_team(args)) + assert team is not None diff --git a/randomfpl/fantasy_random.py b/randomfpl/fantasy_random.py index ea2fc71..26dd903 100644 --- a/randomfpl/fantasy_random.py +++ b/randomfpl/fantasy_random.py @@ -157,6 +157,8 @@ async def generate_team(args): df_mingoalscon, ) + return random_team + def print_average_quantities(df, show): """`print_average_quantities` prints average goals and assists"""