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

Make fixes for Windows / CI #238

Merged
merged 3 commits into from
Mar 20, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import pathlib
import shutil
import sys

import nox

Expand Down Expand Up @@ -43,7 +44,10 @@ def dev(session: nox.Session) -> None:
# e.g. .venv
session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True)

python = os.fsdecode(VENV_DIR.joinpath("bin/python"))
if sys.platform.startswith("linux") or sys.platform == "darwin":
python = os.fsdecode(VENV_DIR.joinpath("bin/python"))
elif sys.platform.startswith("win"):
python = os.fsdecode(VENV_DIR.joinpath("Scripts/python.exe"))

# Use the venv's interpreter to install the project along with
# all it's dev dependencies, this ensures it's installed in the right way
Expand Down
16 changes: 8 additions & 8 deletions src/crowsetta/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
from attr.validators import instance_of


def int64_to_int(val):
"""Converter that converts ``numpy.int64`` to ``int``,
returns ``int`` as is, and errors for other values.
def convert_int(val):
"""Converter that converts ``numpy.integer`` to ``int``,
returns native Python ``int`` as is, and
raises an error for any other type.
"""
if hasattr(val, "dtype"):
if val.dtype == np.int64:
return int(val)
if hasattr(val, "dtype") and isinstance(val, np.integer):
return int(val)
elif isinstance(val, int):
return val
else:
Expand Down Expand Up @@ -81,12 +81,12 @@ class Segment(object):
offset_s = attr.ib(validator=attr.validators.optional(instance_of(float)), default=None)
onset_sample = attr.ib(
validator=attr.validators.optional(instance_of(int)),
converter=attr.converters.optional(int64_to_int),
converter=attr.converters.optional(convert_int),
default=None,
)
offset_sample = attr.ib(
validator=attr.validators.optional(instance_of(int)),
converter=attr.converters.optional(int64_to_int),
converter=attr.converters.optional(convert_int),
default=None,
)
asdict = attr.asdict
Expand Down
12 changes: 6 additions & 6 deletions tests/test_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_from_keyword_bad_labels_type_raises():
Sequence.from_keyword(labels=labels, onset_samples=onset_samples, offset_samples=offset_samples)


def test_from_keyword__onset_offset_in_seconds():
def test_from_keyword_onset_offset_in_seconds():
labels = "abcde"
onsets_s = np.asarray([0.0, 0.2, 0.4, 0.6, 0.8])
offsets_s = np.asarray([0.1, 0.3, 0.5, 0.7, 0.9])
Expand All @@ -62,7 +62,7 @@ def test_from_keyword__onset_offset_in_seconds():
assert type(seq.segments) == tuple


def test_from_keyword_onset_offset_in_Hertz():
def test_from_keyword_onset_offset_in_samples():
labels = "abcde"
onset_samples = np.asarray([0, 2, 4, 6, 8])
offset_samples = np.asarray([1, 3, 5, 7, 9])
Expand All @@ -82,7 +82,7 @@ def test_from_dict_onset_offset_in_seconds():
assert type(seq.segments) == tuple


def test_from_dict_onset_offset_in_Hertz():
def test_from_dict_onset_offset_in_samples():
seq_dict = {
"labels": "abcde",
"onset_samples": np.asarray([0, 2, 4, 6, 8]),
Expand All @@ -108,17 +108,17 @@ def test_missing_onset_seconds_raises():
Sequence.from_keyword(labels="abcde", offsets_s=np.asarray([0.0, 0.2, 0.4, 0.6, 0.8]))


def test_missing_offset_Hertz_raises():
def test_missing_offset_samples_raises():
with pytest.raises(ValueError):
Sequence.from_keyword(labels="abcde", onset_samples=np.asarray([0, 2, 4, 6, 8]))


def test_missing_onset_Hertz_raises():
def test_missing_onset_samples_raises():
with pytest.raises(ValueError):
Sequence.from_keyword(labels="abcde", offset_samples=np.asarray([0, 2, 4, 6, 8]))


def test_as_dict_onset_offset_in_Hertz():
def test_as_dict_onset_offset_in_samples():
labels = "abcde"
onset_samples = np.asarray([0, 2, 4, 6, 8])
offset_samples = np.asarray([1, 3, 5, 7, 9])
Expand Down