Skip to content

Commit 08d4164

Browse files
committed
ci: added pytest config to CI and fixed stuff that broke in refactor
1 parent f9f7a9a commit 08d4164

7 files changed

Lines changed: 54 additions & 21 deletions

File tree

.github/workflows/test.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Test
22

33
on:
44
push:
5-
branches: [ master, 'dev/*' ]
5+
branches: [ master ]
66
pull_request:
77
branches: [ master ]
88

@@ -57,7 +57,7 @@ jobs:
5757
run: |
5858
python -m pip install --upgrade pip wheel
5959
pip install .
60-
- name: Run eegnb install test
60+
- name: Run eegnb cli test
6161
shell: bash
6262
run: |
6363
if [ "$RUNNER_OS" == "Linux" ]; then
@@ -66,6 +66,10 @@ jobs:
6666
fi
6767
eegnb --help
6868
eegnb runexp --help
69+
- name: Run tests
70+
shell: bash
71+
run: |
72+
pytest
6973
7074
typecheck:
7175
runs-on: ${{ matrix.os }}

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
__pycache__
2-
32
*.egg-info/
43

4+
# Created by tests
5+
.coverage
6+
coverage.xml
7+
htmlcov
8+
prof
9+
510
# Built as part of docs
611
doc/auto_examples
712
doc/_build
813

914
# Built by auto_examples
1015
examples/visual_cueing/*.csv
16+
17+
# present for people who use pyenv
18+
.venv

eegnb/cli/__main__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import click
2+
import logging
3+
4+
logger = logging.getLogger(__name__)
25

36

47
@click.group(name="eegnb")
58
def main():
69
"""eeg-notebooks command line interface"""
7-
pass
10+
logging.basicConfig(level=logging.INFO)
811

912

1013
@main.command()
@@ -55,13 +58,16 @@ def runexp(
5558
run_introprompt()
5659
else:
5760
from .utils import run_experiment
58-
from eegnb.devices.eeg import EEG
61+
from eegnb.devices import EEGDevice
5962

6063
if eegdevice == "ganglion":
6164
# if the ganglion is chosen a MAC address should also be proviced
62-
eeg = EEG(device=eegdevice, mac_addr=macaddr)
65+
eeg = EEGDevice.create(device_name=eegdevice, mac_addr=macaddr)
6366
else:
64-
eeg = EEG(device=eegdevice)
67+
if eegdevice:
68+
eeg = EEGDevice.create(device_name=eegdevice)
69+
else:
70+
print("No EEG device provided, using a synthetic one.")
6571

6672
run_experiment(experiment, eeg, recdur, outfname)
6773

eegnb/cli/introprompt.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import os
2-
31
from eegnb import generate_save_fn
4-
from eegnb.devices.eeg import EEG
2+
from eegnb.devices import EEGDevice
53
from .utils import run_experiment, get_exp_desc, experiments
64

75

8-
def device_prompt() -> EEG:
6+
def device_prompt() -> EEGDevice:
97
# define the names of the available boards
108
# boards is a mapping from board code to board description
119
boards = {
@@ -51,9 +49,7 @@ def device_prompt() -> EEG:
5149
board_code = board_code + "_wifi"
5250
if board_code == "ganglion":
5351
# If the Ganglion is being used, you can enter optional Ganglion mac address
54-
ganglion_mac_address = input(
55-
"\nGanglion MAC Address (Press Enter to Autoscan): "
56-
)
52+
mac_address = input("\nGanglion MAC Address (Press Enter to Autoscan): ")
5753
elif board_code == "ganglion_wifi":
5854
# IP address is required for this board configuration
5955
ip_address = input("\nEnter Ganglion+WiFi IP Address: ")
@@ -66,13 +62,11 @@ def device_prompt() -> EEG:
6662
# initialize the EEG device
6763
if board_code.startswith("ganglion"):
6864
if board_code == "ganglion_wifi":
69-
eeg_device = EEG(device=board_code, ip_addr=ip_address)
65+
return EEGDevice.create(device_name=board_code, ip_addr=ip_address)
7066
else:
71-
eeg_device = EEG(device=board_code, mac_addr=ganglion_mac_address)
67+
return EEGDevice.create(device_name=board_code, mac_addr=mac_address)
7268
else:
73-
eeg_device = EEG(device=board_code)
74-
75-
return eeg_device
69+
return EEGDevice.create(device_name=board_code)
7670

7771

7872
def exp_prompt():

eegnb/cli/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from eegnb.devices.eeg import EEG
1+
from eegnb.devices import EEGDevice
22

33
from eegnb.experiments.visual_n170 import n170
44
from eegnb.experiments.visual_p300 import p300
@@ -27,7 +27,7 @@ def get_exp_desc(exp: str):
2727

2828

2929
def run_experiment(
30-
experiment: str, eeg_device: EEG, record_duration: float = None, save_fn=None
30+
experiment: str, eeg_device: EEGDevice, record_duration: float = None, save_fn=None
3131
):
3232
if experiment in experiments:
3333
module = experiments[experiment]

pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tool.pytest.ini_options]
2+
minversion = "6.0"
3+
addopts = "--cov-report=term --cov-report=xml --cov-report=html --cov=eegnb --profile --nbval-lax --current-env"
4+
testpaths = [
5+
"eegnb/devices",
6+
"eegnb/cli",
7+
]
8+
python_files = ["*.py", "*.ipynb"]
9+
10+
[tool.coverage.report]
11+
exclude_lines = [
12+
# Have to re-enable the standard pragma
13+
"pragma: no cover",
14+
# Don't complain if tests don't hit defensive assertion code
15+
"raise NotImplementedError"
16+
]

requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ pywinhook @ https://github.com/ActivityWatch/wheels/raw/master/pywinhook/pyWinho
2525

2626
# Test requirements
2727
mypy>=0.790
28+
pytest
29+
pytest-cov
30+
pytest-profiling
31+
coverage[toml]
32+
nbval
2833

2934
# Docs requirements
3035
sphinx==3.1.1

0 commit comments

Comments
 (0)