Skip to content

Commit f11dac7

Browse files
authored
Create python-app.yml (#9)
* Create python-app.yml * act config for local actions test * run ruff only on pre-commit and remove pylint and black * move parse_args to its own function * feat: test generate_team(args) function
1 parent bde3836 commit f11dac7

File tree

7 files changed

+82
-5
lines changed

7 files changed

+82
-5
lines changed

.actrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--container-architecture=linux/amd64
2+
--action-offline-mode

.github/workflows/pre-commit.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ jobs:
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v4
14-
14+
- name: Set up Python
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: '3.10'
18+
- name: Install ruff
19+
run: pip install ruff
1520
- name: Get pre-commit
1621
uses: pre-commit/action@v3.0.0
1722
- name: Run pre-commit

.github/workflows/python-app.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Python application
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
build:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Set up Python 3.10
23+
uses: actions/setup-python@v3
24+
with:
25+
python-version: "3.10"
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install pytest
30+
pip install .
31+
- name: Test with pytest
32+
run: pytest

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,16 @@ build website with bundle
2828
```bash
2929
bundle exec jekyll serve --port 4001
3030
```
31+
32+
## Test actions locally
33+
34+
Using [act](https://nektosact.com/introduction.html)
35+
36+
Make sure Docker is running then simply
37+
```bash
38+
act
39+
```
40+
If you want to run it on one of the actions simply
41+
```bash
42+
act -W .github/workflows/action.yml
43+
```

_tests/test_generate_team.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from randomfpl.fantasy_random import generate_team
2+
import argparse
3+
import asyncio
4+
5+
6+
def test_generate_team():
7+
args = argparse.Namespace(
8+
max_expense=100,
9+
show_average=False,
10+
show_toprank=False,
11+
show_ext_info=False,
12+
veto_player=False,
13+
veto_teams=False,
14+
)
15+
team = asyncio.run(generate_team(args))
16+
assert team is not None

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ dependencies = [
1212
"matplotlib",
1313
]
1414

15-
[project.optional-dependencies]
16-
dev = ["pylint", "black"]
17-
1815
[project.scripts]
1916
randomfpl = "randomfpl:main"
17+
18+
[tool.pytest.ini_options]
19+
asyncio_mode = "strict"
20+
asyncio_default_fixture_loop_scope = "function"

randomfpl/fantasy_random.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
def main():
1212
"""`main` function for RandomFPL module"""
13+
args = parse_args()
14+
asyncio.run(generate_team(args))
15+
16+
17+
def parse_args():
18+
"""'parse_args' returns parser.parse_args()"""
1319
parser = argparse.ArgumentParser()
1420
parser.add_argument(
1521
"--show_average",
@@ -51,7 +57,7 @@ def main():
5157
)
5258

5359
args = parser.parse_args()
54-
asyncio.run(generate_team(args))
60+
return args
5561

5662

5763
async def generate_team(args):
@@ -151,6 +157,8 @@ async def generate_team(args):
151157
df_mingoalscon,
152158
)
153159

160+
return random_team
161+
154162

155163
def print_average_quantities(df, show):
156164
"""`print_average_quantities` prints average goals and assists"""

0 commit comments

Comments
 (0)