Skip to content

Commit

Permalink
make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
bvreede committed Nov 14, 2023
1 parent 1fb7323 commit 51f1a9e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
21 changes: 12 additions & 9 deletions sktalk/corpus/conversation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import warnings
from typing import Optional
from .utterance import Utterance
from .write.writer import Writer


class Conversation(Writer):
def __init__(
self, utterances: list["Utterance"], metadata: dict | None = None # noqa: F821
self, utterances: list["Utterance"], metadata: Optional[dict] = None # noqa: F821
) -> None:
"""Representation of a transcribed conversation
Expand Down Expand Up @@ -72,15 +73,20 @@ def asdict(self):
def subconversation(self,
index: int,
before: int = 0,
after: int | None = None,
after: Optional[int] = None,
time_or_index: str = "index") -> "Conversation":
"""Select utterances to provide context as a sub-conversation
Args:
index (int): The index of the utterance for which to provide context
before (int, optional): Either the number of utterances prior to indicated utterance, or the time in ms preceding the utterance's begin. Defaults to 0.
after (int, optional): Either the number of utterances after the indicated utterance, or the time in ms following the utterance's end. Defaults to None, which then assumes the same value as `before`.
time_or_index (str, optional): Use "time" to select based on time (in ms), or "index" to select a set number of utterances irrespective of timing. Defaults to "index".
before (int, optional): Either the number of utterances prior to indicated utterance,
or the time in ms preceding the utterance's begin. Defaults to 0.
after (int, optional): Either the number of utterances after the indicated utterance,
or the time in ms following the utterance's end. Defaults to None,
which then assumes the same value as `before`.
time_or_index (str, optional): Use "time" to select based on time (in ms), or "index"
to select a set number of utterances irrespective of timing.
Defaults to "index".
Raises:
IndexError: Index provided must be within range of utterances
Expand Down Expand Up @@ -124,7 +130,4 @@ def overlap(begin: int, end: int, time: list):
# time[0] is before begin and time[1] is after end
if begin <= time[0] <= end or begin <= time[1] <= end:
return True
elif time[0] <= begin and time[1] >= end:
return True
else:
return False
return time[0] <= begin and time[1] >= end
13 changes: 7 additions & 6 deletions tests/corpus/test_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ def test_write_json(self, convo, tmp_path, user_path, expected_path):


class TestConversationMetrics:
@pytest.mark.parametrize("index, before, after, time_or_index, error",
@pytest.mark.parametrize("args, error",
[
(0, 0, 1, "index", does_not_raise()),
(20, 1, 1, "index", pytest.raises(IndexError)),
(0, 50, 50, "index", does_not_raise()),
(0, 0, 0, "neither_time_nor_index",
([0, 0, 1, "index"], does_not_raise()),
([20, 1, 1, "index"], pytest.raises(IndexError)),
([0, 50, 50, "index"], does_not_raise()),
([0, 0, 0, "neither_time_nor_index"],
pytest.raises(ValueError))
])
def test_subconversation_errors(self, convo, index, before, after, time_or_index, error):
def test_subconversation_errors(self, convo, args, error):
index, before, after, time_or_index = args
with error:
convo.subconversation(index=index,
before=before,
Expand Down

0 comments on commit 51f1a9e

Please sign in to comment.