Skip to content

Commit

Permalink
MRG: #238 from vocalpy/make-windows-fixes
Browse files Browse the repository at this point in the history
Make fixes for Windows / CI
  • Loading branch information
NickleDave committed Mar 20, 2023
2 parents 64fcd8d + b76482b commit 4afb900
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
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

0 comments on commit 4afb900

Please sign in to comment.