Skip to content

Commit

Permalink
Merge pull request #27 from justin13601/tests
Browse files Browse the repository at this point in the history
Add comprehensive tests
  • Loading branch information
mmcdermott authored May 9, 2024
2 parents f0c1483 + 9ded12d commit 3f9f40e
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 372 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/code-quality-master.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Same as `code-quality-pr.yaml` but triggered on commit to main branch
# and runs on all files (instead of only the changed ones)

name: Code Quality Main

on:
push:
branches: [master]

jobs:
code-quality:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3

- name: Run pre-commits
uses: pre-commit/action@v3.0.0
36 changes: 36 additions & 0 deletions .github/workflows/code-quality-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow finds which files were changed, prints them,
# and runs `pre-commit` on those files.

# Inspired by the sktime library:
# https://github.com/alan-turing-institute/sktime/blob/main/.github/workflows/test.yml

name: Code Quality PR

on:
pull_request:
branches: [master, "release/*", "dev"]

jobs:
code-quality:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3

- name: Find modified files
id: file_changes
uses: trilom/file-changes-action@v1.2.4
with:
output: " "

- name: List modified files
run: echo '${{ steps.file_changes.outputs.files}}'

- name: Run pre-commits
uses: pre-commit/action@v3.0.0
with:
extra_args: --files ${{ steps.file_changes.outputs.files}}
41 changes: 41 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Tests

on:
push:
branches: [master]
pull_request:
branches: [master, "release/*", "dev"]

jobs:
run_tests_ubuntu:
runs-on: ubuntu-latest

strategy:
fail-fast: false

timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"

- name: Install packages
run: |
pip install -e .[dev]
#----------------------------------------------
# run test suite
#----------------------------------------------
- name: Run tests
run: |
pytest -v --doctest-modules --ignore=profiling/ --ignore=run.py --cov=src -s
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ dependencies = [
]

[project.optional-dependencies]
dev = ["pre-commit", "pytest", "pytest-cov", ]
dev = [
"pre-commit", "pytest", "pytest-cov", "pytest-subtests", "rootutils"
]
profiling = ["psutil"]

[project.urls]
Homepage = "https://github.com/justin13601/ESGPTTaskQueryingPublic"
Expand Down
8 changes: 3 additions & 5 deletions src/esgpt_task_querying/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ def build_tree_from_config(cfg: dict[str, Any]) -> Node:
... }
... }
>>> build_tree_from_config(cfg) # doctest: +NORMALIZE_WHITESPACE
Node(
/window1,
constraints={},
endpoint_expr=(False, datetime.timedelta(days=1), True, datetime.timedelta(0))
)
Node(/window1,
constraints={},
endpoint_expr=(False, datetime.timedelta(days=1), True, datetime.timedelta(0)))
"""
nodes = {}
windows = [name for name, _ in cfg["windows"].items()]
Expand Down
4 changes: 2 additions & 2 deletions src/esgpt_task_querying/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def generate_simple_predicates(predicate_name: str, predicate_info: dict, df: pl
┌────────────┬───────────┬────────────┬──────┐
│ subject_id ┆ timestamp ┆ event_type ┆ is_A │
│ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ str ┆ i32
│ i64 ┆ i64 ┆ str ┆ i64
╞════════════╪═══════════╪════════════╪══════╡
│ 1 ┆ 1 ┆ A ┆ 1 │
│ 1 ┆ 1 ┆ B ┆ 0 │
Expand Down Expand Up @@ -142,7 +142,7 @@ def generate_predicate_columns(cfg: dict, data: list | pl.DataFrame) -> pl.DataF
┌────────────┬───────────┬──────┬──────┬───┬──────┬───────────┬──────────────────┬────────┐
│ subject_id ┆ timestamp ┆ is_A ┆ is_B ┆ … ┆ is_D ┆ is_A_or_B ┆ is_A_and_C_and_D ┆ is_any │
│ --- ┆ --- ┆ --- ┆ --- ┆ ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ i32i32 ┆ ┆ i32i32i32i32
│ i64 ┆ i64 ┆ i64i64 ┆ ┆ i64i64i64i64
╞════════════╪═══════════╪══════╪══════╪═══╪══════╪═══════════╪══════════════════╪════════╡
│ 1 ┆ 1 ┆ 1 ┆ 1 ┆ … ┆ 0 ┆ 1 ┆ 0 ┆ 1 │
│ 1 ┆ 3 ┆ 0 ┆ 0 ┆ … ┆ 0 ┆ 0 ┆ 0 ┆ 1 │
Expand Down
3 changes: 2 additions & 1 deletion src/esgpt_task_querying/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def summarize_temporal_window(
Examples:
>>> import polars as pl
>>> _ = pl.Config.set_tbl_width_chars(100)
>>> from datetime import datetime, timedelta
>>> predicates_df = pl.DataFrame(
... {
Expand All @@ -38,7 +39,7 @@ def summarize_temporal_window(
... "is_A": [1, 0, 1],
... "is_B": [0, 1, 0],
... }
... ))
... )
>>> anchor_to_subtree_root_by_subtree_anchor = pl.DataFrame(
... {
... "subject_id": [1, 1, 1],
Expand Down
3 changes: 3 additions & 0 deletions tests/test_summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,15 @@ def test_summarize_temporal_window(self):
got = summarize_temporal_window(**c)
self.assertEqual(got, want)

@unittest.skip("Not yet implemented")
def test_summarize_event_bound_window(self):
raise NotImplementedError

@unittest.skip("Not yet implemented")
def test_summarize_window(self):
raise NotImplementedError

@unittest.skip("Not yet implemented")
def test_summarize_subtree(self):
raise NotImplementedError

Expand Down
Loading

0 comments on commit 3f9f40e

Please sign in to comment.