Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flake8 and mypy #63

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions libbids/instruments/eeg_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ def device_read(self) -> Union[np.ndarray, List]:
def device_stop(self) -> None:
"""Stop the device"""
if isinstance(self.stop_fn, Callable): # type: ignore
return case(Callable, self.stop_fn)()
return cast(Callable, self.stop_fn)()

fn, args, kwards = cast(Tuple, self.stop_fn)
fn, args, kwargs = cast(Tuple, self.stop_fn)
return self.device.__getattribute__(fn)(*args, **kwargs)

def flush(self) -> None:
Expand Down Expand Up @@ -185,10 +185,10 @@ def read(self, remainder: bool = False) -> Union[List, np.ndarray]:
)
has_data: np.bool_ = np.any([i.shape[0] > 0 for i in self.buffers])
if (not remainder) and period_met:
n_periods: List = [
n_periodss: List[int] = [
i.shape[0] // j for i, j in zip(self.buffers, periods)
]
period_boundaries: List = [i * j for i, j in zip(n_periods, periods)]
period_boundaries: List = [i * j for i, j in zip(n_periodss, periods)]
writebufs: List = [
i[:j] for i, j in zip(self.buffers, period_boundaries)
]
Expand Down
5 changes: 0 additions & 5 deletions libbids/instruments/ieeg_instrument.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import numpy as np # type: ignore

from datetime import datetime
from pyedflib import EdfWriter # type: ignore
from typing import (
Any,
Callable,
Expand All @@ -10,7 +6,6 @@
Tuple,
TYPE_CHECKING,
Union,
cast,
)

from .eeg_instrument import EEGInstrument
Expand Down
15 changes: 14 additions & 1 deletion libbids/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def add_run(self) -> Run:
Run
A run object that can be used to start the session
"""
return Run(self)
run: Run = Run(self)
self.on_new_run(run)
return run

@abstractmethod
def on_event_start(self, event: Event):
Expand All @@ -96,6 +98,17 @@ def on_event_end(self, event: Event):
"""
raise Exception("Not Implemented")

@abstractmethod
def on_new_run(self, run: Run) -> None:
"""Called when a new run is created

Parameters
----------
run : Run
The instance of the Run that will process the task
"""
raise Exception("Not Implemented")

@abstractmethod
def process(self, *args, **kwargs) -> np.ndarray:
"""This method is to be implemented by inheriting classes to define how
Expand Down
9 changes: 3 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from skbuild import setup
from setuptools import find_packages
from skbuild import setup # type: ignore
from setuptools import find_packages # type: ignore

setup(
name="libbids",
packages=find_packages(exclude=["tests"])
)
setup(name="libbids", packages=find_packages(exclude=["tests"]))
8 changes: 4 additions & 4 deletions tests/test_entity.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Optional

from libbids.clibbids import Entity
from libbids.clibbids import Entity # type: ignore


def test_constructor_with_name_and_optional_key_and_int_value():
def test_constructor_with_name_and_optional_key_and_int_value() -> None:
name = "Entity"
key: Optional[str] = "KEY"
value: int = 42
Expand All @@ -14,7 +14,7 @@ def test_constructor_with_name_and_optional_key_and_int_value():
assert entity.id == "KEY-42"


def test_constructor_with_name_and_optional_key_and_string_value():
def test_constructor_with_name_and_optional_key_and_string_value() -> None:
name = "Entity"
key: Optional[str] = "KEY"
value: str = "VALUE"
Expand All @@ -25,7 +25,7 @@ def test_constructor_with_name_and_optional_key_and_string_value():
assert entity.id == "KEY-VALUE"


def test_constructor_with_name_and_optional_key_and_invalid_string_value():
def test_constructor_with_name_and_optional_key_and_invalid_string_value() -> None:
name: str = "Entity"
key: Optional[str] = "KEY"
value: str = "INVALID"
Expand Down
17 changes: 9 additions & 8 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from pathlib import Path
from libbids import Dataset
from libbids.clibbids import Session
from libbids.clibbids import Session, Subject # type: ignore
from typing import cast


# Test fixture for Session class
Expand Down Expand Up @@ -41,45 +42,45 @@ def setup(self):
shutil.rmtree(self.test_dir)

# Test the path() method of Session
def test_path_test(self):
def test_path_test(self) -> None:
# Create a Session object with index 1
session: Session = Session(self.subject, 1)

# Expected path: subject path + session id
expected_path: Path = self.subject.path / "ses-01"
expected_path: Path = cast(Subject, self.subject).path / "ses-01"

# Check if the calculated path matches the expected path
assert session.path == expected_path

# Test the prefix() method of Session
def test_prefix(self):
def test_prefix(self) -> None:
# Create a Session object with index 2
session: Session = Session(self.subject, 2)

# Expected prefix: subject id + "_" + session id
expected_prefix: str = self.subject.id + "_" + session.id
expected_prefix: str = cast(Subject, self.subject).id + "_" + session.id

# Check if the calculated prefix matches the expected prefix
assert session.prefix == expected_prefix

# test the label
def test_label(self):
def test_label(self) -> None:
# Create a Session object with index 3
session: Session = Session(self.subject, 3)

# Check if the calculated prefix matches the expected prefix
assert session.label == "03"

# test padding
def test_padding(self):
def test_padding(self) -> None:
# Create a Session object with index 4
session: Session = Session(self.subject, 4)

# Check if the calculated prefix matches the expected prefix
assert session.padding == 2

# test index
def test_index(self):
def test_index(self) -> None:
# Creat a Session object with index 5
session: Session = Session(self.subject, 5)

Expand Down
10 changes: 5 additions & 5 deletions tests/test_subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from pathlib import Path
from libbids import Dataset
from libbids.clibbids import Session, Subject
from libbids.clibbids import Session, Subject # type: ignore


# Test fixture for Subject class
Expand Down Expand Up @@ -40,7 +40,7 @@ def setup(self):
shutil.rmtree(self.test_dir)

# Test the path() method of Subject
def test_path_test(self):
def test_path_test(self) -> None:
# Create a Subject object with index 1
subject: Subject = Subject(
self.dataset, dict(name="Jacob", participant_id="sub-01")
Expand All @@ -53,7 +53,7 @@ def test_path_test(self):
assert subject.path == expected_path

# Test the prefix() method of Subject
def test_prefix(self):
def test_prefix(self) -> None:
# Create a Subject object with index 2
subject: Subject = Subject(self.dataset, dict(participant_id="02"))

Expand All @@ -64,15 +64,15 @@ def test_prefix(self):
assert subject.id == expected_prefix

# test the label
def test_label(self):
def test_label(self) -> None:
# Create a Subject object with index 3
subject: Subject = Subject(self.dataset, dict(participant_id="sub-03"))

# Check if the calculated prefix matches the expected prefix
assert subject.get_participant_label() == "03"

# Test adding a session
def test_add_session(self):
def test_add_session(self) -> None:
# Create a Subject object with index 4
subject: Subject = Subject(
self.dataset, dict(participant_id="sub-04", name="J'Dinklage Morgoon")
Expand Down
Loading