Skip to content

Commit f5b9780

Browse files
authored
feat: Github actions integration for test (#1)
github actions + rename tests
1 parent f0877ec commit f5b9780

File tree

5 files changed

+87
-8
lines changed

5 files changed

+87
-8
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: pytest unittest
2+
3+
on:
4+
pull_request:
5+
branches: [ "develop", "master" ]
6+
jobs:
7+
build:
8+
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
python-version: ["3.9"]
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Set up Python ${{ matrix.python-version }}
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
cache: 'pip' # caching pip dependencies
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install pytest
25+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
26+
27+
- name: Download artifact
28+
id: download-artifact
29+
uses: dawidd6/action-download-artifact@v2
30+
with:
31+
# Optional, the status or conclusion of a completed workflow to search for
32+
# Can be one of a workflow conclusion:
33+
# "failure", "success", "neutral", "cancelled", "skipped", "timed_out", "action_required"
34+
# Or a workflow status:
35+
# "completed", "in_progress", "queued"
36+
# Use the empty string ("") to ignore status or conclusion in the search
37+
workflow_conclusion: success
38+
run_id: 4246999530
39+
run_number: 26
40+
# Optional, uploaded artifact name,
41+
# will download all artifacts if not specified
42+
# and extract them into respective subdirectories
43+
# https://github.com/actions/download-artifact#download-all-artifacts
44+
name: datasets
45+
# Optional, a directory where to extract artifact(s), defaults to the current directory
46+
path: /home/runner/.cache/pyhealth/datasets/
47+
# Optional, search for the last workflow run whose stored an artifact named as in `name` input
48+
# default false
49+
search_artifacts: true
50+
# Optional, choose how to exit the action if no artifact is found
51+
# can be one of:
52+
# "fail", "warn", "ignore"
53+
# default fail
54+
if_no_artifact_found: warn
55+
56+
- name: validate cached data is correctly placed
57+
run: |
58+
ls -al /home/runner/.cache/pyhealth/datasets/
59+
60+
- name: Test with pytest
61+
run: |
62+
cd pyhealth/unittests
63+
pytest -rP
64+
65+
- name: dataset pickles to upload
66+
run: |
67+
ls -al /home/runner/.cache/pyhealth/datasets/
68+
- name: upload datasets pickle
69+
uses: actions/upload-artifact@v3
70+
with:
71+
name: datasets
72+
path: /home/runner/.cache/pyhealth/datasets/

pyhealth/datasets/base_ehr_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __init__(
115115
)
116116
filename = hash_str("+".join([str(arg) for arg in args_to_hash])) + ".pkl"
117117
self.filepath = os.path.join(MODULE_CACHE_PATH, filename)
118-
118+
119119
# check if cache exists or refresh_cache is True
120120
if os.path.exists(self.filepath) and (not refresh_cache):
121121
# load from cache

pyhealth/datasets/mimic3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def lab_unit(p_id, p_info):
361361

362362
if __name__ == "__main__":
363363
dataset = MIMIC3Dataset(
364-
root="/srv/local/data/physionet.org/files/mimiciii/1.4",
364+
root="https://storage.googleapis.com/pyhealth/mimiciii-demo/1.4/",
365365
tables=[
366366
"DIAGNOSES_ICD",
367367
"PROCEDURES_ICD",

pyhealth/unittests/test_datasets/test_mimic3 renamed to pyhealth/unittests/test_datasets/test_mimic3.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import datetime
22
import unittest
3+
import os, sys
4+
5+
current = os.path.dirname(os.path.realpath(__file__))
6+
repo_root = os.path.dirname(os.path.dirname(os.path.dirname(current)))
7+
sys.path.append(repo_root)
38

49
from pyhealth.datasets import MIMIC3Dataset
510

@@ -10,19 +15,16 @@
1015
# used for testing correctness
1116
# like the MIMIC4 dataset, if this test suite fails, it may be due to a regression in the
1217
# code, or due to the dataset at the root chaning.
13-
class Mimic3Tests(unittest.TestCase):
18+
class TestsMimic3(unittest.TestCase):
1419

1520
ROOT = "https://storage.googleapis.com/pyhealth/mimiciii-demo/1.4/"
1621
TABLES = ["DIAGNOSES_ICD", "PRESCRIPTIONS"]
1722
CODE_MAPPING = {"NDC": ("ATC", {"target_kwargs": {"level": 3}})}
18-
DEV = True
1923

2024
dataset = MIMIC3Dataset(
2125
root=ROOT,
2226
tables=TABLES,
2327
code_mapping=CODE_MAPPING,
24-
dev=DEV, # since we are using the demo dataset it doesn't matter.
25-
refresh_cache=True,
2628
)
2729

2830
def setUp(self):

pyhealth/unittests/test_datasets/test_mimic4 renamed to pyhealth/unittests/test_datasets/test_mimic4.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import datetime
22
import unittest
3+
import os, sys
4+
5+
current = os.path.dirname(os.path.realpath(__file__))
6+
repo_root = os.path.dirname(os.path.dirname(os.path.dirname(current)))
7+
sys.path.append(repo_root)
38

49
from pyhealth.datasets import MIMIC4Dataset
510

@@ -8,7 +13,7 @@
813
# and a single sample from the dataset.
914

1015

11-
class Mimic4Tests(unittest.TestCase):
16+
class TestMimic4(unittest.TestCase):
1217

1318
# to test the file this path needs to be updated
1419
ROOT = "https://storage.googleapis.com/pyhealth/mimiciv-demo/hosp/"
@@ -23,7 +28,7 @@ class Mimic4Tests(unittest.TestCase):
2328
dev=DEV,
2429
refresh_cache=False,
2530
)
26-
31+
2732
def setUp(self):
2833
pass
2934

0 commit comments

Comments
 (0)