Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# .github/workflows/ci.yml
name: CI

on:
push:
branches: [ main, master ]
pull_request:
workflow_dispatch:

permissions:
contents: write
Expand All @@ -12,11 +13,19 @@ jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: python -m pip install --upgrade pip
- run: pip install -r requirement.txt pytest

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirement.txt
pip install pytest

- name: Run tests
run: pytest
run: pytest -q
1 change: 1 addition & 0 deletions requirement.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pandas==2.2.2
numpy==1.26.4
selenium==4.23.1
webdriver-manager==4.0.2
pytest
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os
import sys

# Add repository root to sys.path so tests can import ecc_rankings
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
if ROOT not in sys.path:
sys.path.insert(0, ROOT)

35 changes: 25 additions & 10 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import ecc_rankings.run
import pandas as pd
from ecc_rankings.batting import BattingScraper

def test_import_run():
assert hasattr(ecc_rankings, "run")
assert callable(ecc_rankings.run.main)

def test_combine_and_score_basic():
sample = pd.DataFrame([
{"KNCB Ranking": "1", "Klasse": "1e klasse", "Player": "Alice", "matches": "2", "innings": "2", "not_outs": "0", "Runs": "80", "highest": "80", "average": "40.0", "strike_rate": "80.0", "Season": 2025},
{"KNCB Ranking": "2", "Klasse": "2e klasse", "Player": "Alice", "matches": "3", "innings": "3", "not_outs": "1", "Runs": "60", "highest": "30", "average": "30.0", "strike_rate": "75.0", "Season": 2025},
{"KNCB Ranking": "1", "Klasse": "1e klasse", "Player": "Bob", "matches": "1", "innings": "1", "not_outs": "0", "Runs": "10", "highest": "10", "average": "10.0", "strike_rate": "50.0", "Season": 2025},
])

def test_run_main_executes():
# This just checks that main() runs without error (does not validate output)
try:
ecc_rankings.run.main()
except Exception as e:
assert False, f"ecc_rankings.run.main() raised an exception: {e}"
scraper = BattingScraper(html_path="")
out = scraper.combine_and_score(sample)

assert "Player" in out.columns
assert "Points" in out.columns

alice = out.loc[out["Player"] == "Alice"].iloc[0]
bob = out.loc[out["Player"] == "Bob"].iloc[0]
assert alice["Points"] >= bob["Points"]


def test_generate_html_contains_player():
sample = pd.DataFrame([
{"KNCB Ranking": "1", "Klasse": "1e klasse", "Player": "Charlie", "matches": "1", "innings": "1", "not_outs": "0", "Runs": "25", "highest": "25", "average": "25.0", "strike_rate": "60.0", "Season": 2025},
])
scraper = BattingScraper(html_path="")
html = scraper.generate_html(sample)
assert "Charlie" in html