Skip to content

Commit ac45181

Browse files
authored
Refactor unit and integration tests and corresponding github actions (#686)
* refactor integration tests * move legacy to integration * move legacy to integration * temporarily disable notebooks * update unit tests * update coverage action * fix job name * fix coverage action * reinstate notebooks * use pip * tidy up linting * wip fix or ignore mypy errors * fix or ignore mypy errors * fix plasmodium tests * fix typing
1 parent e213d1b commit ac45181

22 files changed

+891
-688
lines changed

.github/workflows/coverage.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,17 @@ jobs:
1515
- name: Checkout source
1616
uses: actions/checkout@v4
1717

18-
- name: Install poetry
19-
run: pipx install poetry==1.8.3
20-
2118
- name: Setup python
2219
uses: actions/setup-python@v5
2320
with:
2421
python-version: '3.12'
25-
cache: 'poetry'
22+
cache: 'pip'
2623

27-
- name: Install dependencies
28-
run: poetry install
24+
- name: Install package
25+
run: pip install .[dev]
2926

30-
- name: Run tests with coverage
31-
run: poetry run pytest --durations=20 -v --cov malariagen_data/anoph --cov-report=xml tests/anoph
27+
- name: Run unit tests with coverage
28+
run: pytest -v tests --ignore tests/integration --cov malariagen_data/anoph --cov-report=xml
3229

3330
- name: Upload coverage report
3431
uses: codecov/codecov-action@v3

.github/workflows/legacy_tests.yml renamed to .github/workflows/integration_tests.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: legacy_tests
1+
name: integration_tests
22
on:
33
push:
44
branches:
@@ -7,7 +7,7 @@ on:
77
branches:
88
- master
99
jobs:
10-
legacy_tests:
10+
integration_tests:
1111
strategy:
1212
fail-fast: true
1313
matrix:
@@ -23,17 +23,14 @@ jobs:
2323
- name: Checkout source
2424
uses: actions/checkout@v4
2525

26-
- name: Install poetry
27-
run: pipx install poetry==1.8.3
28-
2926
- name: Setup python
3027
uses: actions/setup-python@v5
3128
with:
3229
python-version: ${{ matrix.python-version }}
33-
cache: "poetry"
30+
cache: "pip"
3431

35-
- name: Install dependencies
36-
run: poetry install
32+
- name: Install package
33+
run: pip install .[dev]
3734

3835
- id: 'auth'
3936
name: 'Set up Google Cloud authentication'
@@ -53,14 +50,14 @@ jobs:
5350
uses: actions/cache/restore@v3
5451
with:
5552
path: gcs_cache
56-
key: gcs_cache_tests_20240922
53+
key: gcs_cache_integration_tests_20240922
5754

58-
- name: Run full test suite
59-
run: poetry run pytest --durations=20 --ignore=tests/anoph -v tests
55+
- name: Run integration tests
56+
run: pytest --durations=20 -v tests/integration
6057

6158
- name: Save GCS cache
6259
uses: actions/cache/save@v3
6360
if: always()
6461
with:
6562
path: gcs_cache
66-
key: gcs_cache_tests_20240922
63+
key: gcs_cache_integration_tests_20240922

.github/workflows/linting.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ jobs:
1212
fail-fast: true
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v4
16-
- uses: actions/setup-python@v5
15+
- name: Checkout source
16+
uses: actions/checkout@v4
17+
18+
- name: Setup python
19+
uses: actions/setup-python@v5
1720
with:
1821
python-version: '3.12'
19-
- uses: pre-commit/[email protected]
20-
- name: Install mypy
21-
run: pip install mypy
22+
cache: 'pip'
23+
24+
- name: Run pre-commit checks
25+
uses: pre-commit/[email protected]
26+
27+
- name: Install package
28+
run: pip install .[dev]
29+
2230
- name: Run mypy
2331
run: |
2432
mypy malariagen_data tests --ignore-missing-imports

.github/workflows/notebooks.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ jobs:
1919
- name: Checkout source
2020
uses: actions/checkout@v4
2121

22-
- name: Install poetry
23-
run: pipx install poetry==1.8.3
24-
2522
- name: Setup python
2623
uses: actions/setup-python@v5
2724
with:
2825
python-version: "3.12"
29-
cache: "poetry"
26+
cache: "pip"
3027

31-
- name: Install dependencies
32-
run: poetry install
28+
- name: Install package
29+
run: pip install .[dev]
3330

3431
- id: 'auth'
3532
name: 'Set up Google Cloud authentication'
@@ -52,7 +49,7 @@ jobs:
5249
key: gcs_cache_notebooks_20240922
5350

5451
- name: Run notebooks
55-
run: poetry run jupyter nbconvert --execute notebooks/*.ipynb --inplace
52+
run: jupyter nbconvert --execute notebooks/*.ipynb --inplace
5653

5754
- name: Save GCS cache
5855
uses: actions/cache/save@v3

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ jobs:
3232
- name: Install package
3333
run: pip install "${{ matrix.numpy-version }}" .[dev]
3434

35-
- name: Run fast unit tests
36-
run: pytest -v tests/anoph --typeguard-packages=malariagen_data,malariagen_data.anoph
35+
- name: Run unit tests
36+
run: pytest -v tests --ignore tests/integration --typeguard-packages=malariagen_data,malariagen_data.anoph

malariagen_data/anoph/genome_features.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,12 @@ def plot_genes(
415415

416416
# Increase the figure height by a certain factor, to accommodate labels.
417417
height_increase_factor = 1.3
418+
assert fig.height is not None
418419
fig.height = int(fig.height * height_increase_factor)
419420

420421
# Get the original y_range.
421422
# Note: fig.y_range is not subscriptable.
422-
orig_y_range = fig.y_range.start, fig.y_range.end
423+
orig_y_range = fig.y_range.start, fig.y_range.end # type: ignore
423424

424425
# Determine the midpoint of the original range, to rescale outward from there.
425426
orig_mid_y_range = (orig_y_range[0] + orig_y_range[1]) / 2
@@ -432,7 +433,7 @@ def plot_genes(
432433
new_y_end = orig_mid_y_range + new_y_range_extent_half
433434

434435
# Set the new y_range.
435-
fig.y_range = bokeh.models.Range1d(new_y_start, new_y_end)
436+
fig.y_range = bokeh.models.Range1d(new_y_start, new_y_end) # type: ignore
436437

437438
debug("determine midpoint of each gene rectangle")
438439
data["mid_x"] = (data["start"] + data["end"]) / 2
@@ -474,7 +475,7 @@ def plot_genes(
474475
data_as_cds = bokeh.models.ColumnDataSource(data)
475476

476477
# Create a LabelSet for the gene pointers.
477-
gene_pointers_ls = bokeh.models.LabelSet(
478+
gene_pointers_ls = bokeh.models.LabelSet( # type: ignore
478479
source=data_as_cds,
479480
x="mid_x",
480481
y="pointer_y",
@@ -486,7 +487,7 @@ def plot_genes(
486487
)
487488

488489
# Create a LabelSet for the gene labels.
489-
gene_labels_ls = bokeh.models.LabelSet(
490+
gene_labels_ls = bokeh.models.LabelSet( # type: ignore
490491
source=data_as_cds,
491492
x="mid_x",
492493
y="label_y",

malariagen_data/anoph/gplt_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@
127127
]
128128

129129
gene_labelset: TypeAlias = Annotated[
130-
bokeh.models.LabelSet,
130+
bokeh.models.LabelSet, # type: ignore
131131
"A LabelSet to use in the plot.",
132132
]

malariagen_data/anoph/h12.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ def plot_h12_gwss_multi_panel(
823823
figs.append(fig2)
824824

825825
# Combine plots into a single figure.
826-
fig = bokeh.layouts.gridplot(
826+
fig = bokeh.layouts.gridplot( # type: ignore
827827
figs,
828828
ncols=1,
829829
toolbar_location="above",

malariagen_data/anoph/hap_frq.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def haplotypes_frequencies(
107107
hap_dict.update(f)
108108
freq_cols["frq_" + coh] = list(hap_dict.values())
109109

110-
df_freqs = pd.DataFrame(freq_cols, index=hap_dict.keys())
110+
df_freqs = pd.DataFrame(freq_cols, index=list(hap_dict.keys()))
111111

112112
# Compute max_af.
113113
df_max_af = pd.DataFrame({"max_af": df_freqs.max(axis=1)})
@@ -230,14 +230,14 @@ def haplotypes_frequencies_advanced(
230230
freq_cols["frq_" + cohort_key_str] = list(hap_freq.values())
231231
nobs_cols["nobs_" + cohort_key_str] = list(hap_nob.values())
232232

233-
df_freqs = pd.DataFrame(freq_cols, index=hap_freq.keys())
233+
df_freqs = pd.DataFrame(freq_cols, index=list(hap_freq.keys()))
234234

235235
# Compute max_af.
236236
df_max_af = pd.DataFrame({"max_af": df_freqs.max(axis=1)})
237237

238-
df_counts = pd.DataFrame(count_cols, index=hap_count.keys())
238+
df_counts = pd.DataFrame(count_cols, index=list(hap_count.keys()))
239239

240-
df_nobs = pd.DataFrame(nobs_cols, index=hap_nob.keys())
240+
df_nobs = pd.DataFrame(nobs_cols, index=list(hap_nob.keys()))
241241

242242
# Build the final dataframe.
243243
df_haps = pd.concat([df_freqs, df_counts, df_nobs, df_max_af], axis=1)

malariagen_data/anoph/sample_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ def cohorts(
12701270
df_cohorts = pd.read_csv(f, sep=",", na_values="")
12711271

12721272
# Ensure all column names are lower case.
1273-
df_cohorts.columns = [c.lower() for c in df_cohorts.columns]
1273+
df_cohorts.columns = [c.lower() for c in df_cohorts.columns] # type: ignore
12741274

12751275
return df_cohorts
12761276

0 commit comments

Comments
 (0)