Skip to content

Commit c641996

Browse files
authored
Merge pull request #122 from CardiacModelling/116-move-tests
Move tests into package
2 parents fbb87bd + f822d6f commit c641996

29 files changed

+695
-1159
lines changed

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ ignore =
1616
exclude=
1717
.git,
1818
venv,
19-
tests/test_data,
19+
test_data,
20+
test_output,

.github/workflows/tests.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,13 @@ jobs:
3636
- name: Check code style with flake8
3737
if: ${{ matrix.python-version == env.python-latest }}
3838
run: |
39-
python -m flake8 pcpostprocess/*.py tests/*.py pcpostprocess/scripts/*.py
40-
41-
- name: Check import ordering with isort
42-
if: ${{ matrix.python-version == env.python-latest }}
43-
run: |
44-
python -m isort --verbose --check-only --diff pcpostprocess tests setup.py
39+
python -m flake8 pcpostprocess
4540
4641
- name: Extract test data
4742
run: |
48-
wget https://cardiac.nottingham.ac.uk/syncropatch_export/test_data.tar.xz -P tests/
49-
tar xvf tests/test_data.tar.xz -C tests/
50-
51-
- name: Install TeX dependencies for run_herg_qc test
52-
timeout-minutes: 5
53-
run: sudo apt-get install dvipng texlive-latex-extra texlive-fonts-recommended cm-super -y
43+
wget https://cardiac.nottingham.ac.uk/syncropatch_export/test_data.tar.xz
44+
tar xvf test_data.tar.xz
45+
rm test_data.tar.xz
5446
5547
- name: Run unit tests (without coverage testing)
5648
if: ${{ success() && matrix.python-version != env.python-latest }}

.gitignore

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
1+
# Autogenerated by setuptools-wcm
12
pcpostprocess/_version.py
2-
/tests/test_data
3+
4+
# Tests and test data
5+
.coverage
6+
/test_data
37
/test_output
48
/output
5-
*__pycache__*
9+
10+
# Compiled python
11+
*.pyc
12+
__pycache__
13+
14+
# Installation files
615
*.egg-info
7-
*.DS_Store
8-
.coverage
16+
17+
# Jupyter notebooks
18+
.ipynb_checkpoints
19+
20+
# Virtual environments
21+
venv
22+
env
23+
24+
# DS Store
25+
.DS_Store
26+
27+
# VS code config
28+
.vscode

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ This page lists the main changes made to pcpostprocess in each release.
55
## Unreleased
66
- Added
77
- [#81](https://github.com/CardiacModelling/pcpostprocess/pull/81) Added docstrings to the `hERGQC` class.
8-
- [#104](https://github.com/CardiacModelling/pcpostprocess/pull/104) Added a CHANGELOG.md and CONTRIBUTING.md
8+
- [#104](https://github.com/CardiacModelling/pcpostprocess/pull/104) Added a CHANGELOG.md and CONTRIBUTING.md.
99
- Changed
1010
- [#81](https://github.com/CardiacModelling/pcpostprocess/pull/81) Changed the constructor arguments for `hERGQC`.
11+
- [#122](https://github.com/CardiacModelling/pcpostprocess/pull/122) `fit_linear_leak` no longer accepts an `output_dir` argument.
1112
- Deprecated
1213
- Removed
1314
- [#81](https://github.com/CardiacModelling/pcpostprocess/pull/81) Removed `hERGQC.plot_dir`, `hERGQC.set_trace` and `hERGQC.set_debug`.

CONTRIBUTING.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ In addition to the rules checked by flake8, we try to use single quotes (`'`) fo
6262

6363
Class, method, and argument names are in UK english.
6464

65-
### Import ordering
66-
67-
Import ordering is tested with [isort](https://pycqa.github.io/isort/index.html).
68-
69-
To run locally, use
70-
```
71-
isort --check-only --verbose ./pcpostprocess ./tests/
72-
```
73-
74-
Isort is configured in [pyproject.toml](./pyproject.toml) under the section `tool.isort`.
75-
7665
## Documentation
7766

7867
Every method and every class should have a [docstring](https://www.python.org/dev/peps/pep-0257/) that describes in plain terms what it does, and what the expected input and output is.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ To run the tests you must first download some test data.
3434
Test data is available at [cardiac.nottingham.ac.uk/syncropatch\_export](https://cardiac.nottingham.ac.uk/syncropatch_export)
3535

3636
```sh
37-
wget https://cardiac.nottingham.ac.uk/syncropatch_export/test_data.tar.xz -P tests/
38-
tar xvf tests/test_data.tar.xz -C tests/
39-
rm tests/test_data.tar.xz
37+
wget https://cardiac.nottingham.ac.uk/syncropatch_export/test_data.tar.xz
38+
tar xvf test_data.tar.xz
39+
rm test_data.tar.xz
4040
```
4141

4242
Then you can run the tests.

pcpostprocess/directory_builder.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,27 @@ def get_git_revision_hash():
1010
Get the hash for the git commit currently being used.
1111
1212
@return The most recent commit hash or a suitable message
13-
1413
"""
15-
1614
return __commit_id__
1715

1816

1917
def get_build_type():
20-
if "dev" in __version__:
21-
return "Develop"
22-
else:
23-
return "Release"
18+
return 'Develop' if 'dev' in __version__ else 'Release'
2419

2520

26-
def setup_output_directory(dirname: str = None, subdir_name: str = None):
21+
def setup_output_directory(dirname: str):
2722
"""
2823
Create an output directory if one doesn't already exist. Place an info
2924
file in this directory which lists the date/time created, the version of
3025
pcpostprocess, the command-line arguments provided, and the most recent git
3126
commit. The two parameters allow for a user specified top-level directory and
3227
a script-defined name for a subdirectory.
3328
34-
@param Optional directory name
35-
@param Optional subdirectory name
29+
@param Directory name
3630
3731
@return The path to the created file directory (String)
3832
"""
39-
40-
if dirname is None:
41-
if subdir_name:
42-
dirname = os.path.join("output", f"{subdir_name}")
43-
else:
44-
dirname = os.path.join("output", "output")
45-
46-
if subdir_name is not None:
47-
dirname = os.path.join(dirname, subdir_name)
48-
if not os.path.exists(dirname):
49-
os.makedirs(dirname)
33+
os.makedirs(dirname, exist_ok=True)
5034

5135
with open(os.path.join(dirname, "pcpostprocess_info.txt"), "w") as description_fout:
5236
git_hash = get_git_revision_hash()

pcpostprocess/hergQC.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,8 @@ def __init__(self, voltage, sampling_rate=5, removal_time=5, noise_len=200,
7575
self.removal_time = removal_time
7676
self.noise_len = int(noise_len)
7777

78-
# Passing in a plot dir enables debug mode
7978
self._plot_dir = plot_dir
8079
self.logger = logging.getLogger(__name__)
81-
if self._plot_dir is not None:
82-
self.logger.setLevel(logging.DEBUG)
83-
# https://github.com/CardiacModelling/pcpostprocess/issues/42
84-
self._plot_dir = plot_dir
8580

8681
# Define all thresholds
8782

@@ -499,8 +494,7 @@ def qc6(self, recording1, win, label=None):
499494
i, f = win
500495
val = np.mean(recording1[i:f])
501496
valc = self.negative_tolc * np.std(recording1[:self.noise_len])
502-
if (val < valc) or not (np.isfinite(val)
503-
and np.isfinite(valc)):
497+
if (val < valc) or not (np.isfinite(val) and np.isfinite(valc)):
504498
self.logger.debug(f'qc6_{label} val: {val}, valc: {valc}')
505499
result = False
506500
else:

pcpostprocess/infer_reversal.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import logging
2-
import os
32

43
import matplotlib.pyplot as plt
54
import numpy as np
@@ -65,9 +64,6 @@ def infer_reversal_potential(current, times, voltage_segments, voltages,
6564

6665
# Optional plot
6766
if output_path is not None:
68-
dirname = os.path.dirname(output_path)
69-
if not os.path.exists(dirname):
70-
os.makedirs(dirname)
7167

7268
fig = plt.figure(figsize=figsize)
7369
ax = fig.subplots()

pcpostprocess/leak_correct.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import logging
2-
import os
3-
1+
#
2+
# Leak correction methods
3+
#
44
import numpy as np
55
from matplotlib import pyplot as plt
66

@@ -55,7 +55,7 @@ def get_leak_corrected(current, voltages, times, ramp_start_index,
5555

5656

5757
def fit_linear_leak(current, voltage, times, ramp_start_index, ramp_end_index,
58-
save_fname=None, output_dir=None, figsize=(5.54, 7)):
58+
save_fname=None, figsize=(5.54, 7)):
5959
"""
6060
Fits linear leak to a leak ramp, returning
6161
@@ -64,8 +64,6 @@ def fit_linear_leak(current, voltage, times, ramp_start_index, ramp_end_index,
6464
@param ramp_start_index: the index of the observation where the leak ramp begins
6565
@param ramp_end_index: the index of the observation where the leak ramp ends
6666
@param save_fname: if set, a debugging figure will be made and stored with this name
67-
@param output_dir: if ``save_fname`` is set, this directory will be used to store
68-
the figure, and created if it does not exist
6967
@param figsize: if ``save_fname`` is set, the figure size.
7068
7169
@return: the linear regression parameters obtained from fitting the leak
@@ -106,26 +104,26 @@ def fit_linear_leak(current, voltage, times, ramp_start_index, ramp_end_index,
106104
time_range = (0, times.max() / 5)
107105

108106
#  Current vs time
109-
ax1.set_title(r'\textbf{a}', loc='left', usetex=True)
107+
ax1.set_title(r'\textbf{a}', loc='left')
110108
ax1.set_xlabel(r'$t$ (ms)')
111109
ax1.set_ylabel(r'$I_\mathrm{obs}$ (pA)')
112110
ax1.set_xticklabels([])
113111
ax1.set_xlim(*time_range)
114112

115113
# Voltage vs time
116-
ax2.set_title(r'\textbf{b}', loc='left', usetex=True)
114+
ax2.set_title(r'\textbf{b}', loc='left')
117115
ax2.set_xlabel(r'$t$ (ms)')
118116
ax2.set_ylabel(r'$V_\mathrm{cmd}$ (mV)')
119117
ax2.set_xlim(*time_range)
120118

121119
# Current vs voltage
122-
ax3.set_title(r'\textbf{c}', loc='left', usetex=True)
120+
ax3.set_title(r'\textbf{c}', loc='left')
123121
ax3.set_xlabel(r'$V_\mathrm{cmd}$ (mV)')
124122
ax3.set_ylabel(r'$I_\mathrm{obs}$ (pA)')
125123

126124
ax4.set_xlabel(r'$t$ (ms)')
127125
ax4.set_ylabel(r'current (pA)')
128-
ax4.set_title(r'\textbf{d}', loc='left', usetex=True)
126+
ax4.set_title(r'\textbf{d}', loc='left')
129127

130128
start_t = times[ramp_start_index]
131129
end_t = times[ramp_end_index]
@@ -152,14 +150,8 @@ def fit_linear_leak(current, voltage, times, ramp_start_index, ramp_end_index,
152150
alpha=0.5, label=r'$I_\mathrm{obs} - I_\mathrm{L}$')
153151
ax4.legend(frameon=False)
154152

155-
if not os.path.exists(output_dir):
156-
os.makedirs(output_dir)
157-
158-
if output_dir:
159-
try:
160-
fig.savefig(os.path.join(output_dir, save_fname))
161-
plt.close(fig)
162-
except Exception as exc:
163-
logging.warning(str(exc))
153+
if save_fname is not None:
154+
fig.savefig(save_fname)
155+
plt.close(fig)
164156

165157
return (b_0, b_1), I_leak

0 commit comments

Comments
 (0)