From eccf4625aa854bec7174fc1af5d59bd3c8023dff Mon Sep 17 00:00:00 2001 From: Saurabh Singh Date: Tue, 9 Sep 2025 15:40:43 +0200 Subject: [PATCH] added status --- .github/workflows/ci.yml | 21 +++++++++++++++------ requirement.txt | 1 + tests/conftest.py | 8 ++++++++ tests/test_basic.py | 35 +++++++++++++++++++++++++---------- 4 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 tests/conftest.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fb0fe3..86af761 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,10 @@ -# .github/workflows/ci.yml name: CI + on: push: branches: [ main, master ] pull_request: + workflow_dispatch: permissions: contents: write @@ -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 diff --git a/requirement.txt b/requirement.txt index 7d74b2a..9428964 100644 --- a/requirement.txt +++ b/requirement.txt @@ -2,3 +2,4 @@ pandas==2.2.2 numpy==1.26.4 selenium==4.23.1 webdriver-manager==4.0.2 +pytest \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..fbff44f --- /dev/null +++ b/tests/conftest.py @@ -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) + diff --git a/tests/test_basic.py b/tests/test_basic.py index c229b39..64c73d8 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -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