From 51f1a9eb2faa7aebc7cfb7b0a0e9d4fc75c6aff6 Mon Sep 17 00:00:00 2001 From: Barbara Vreede Date: Tue, 14 Nov 2023 11:59:51 +0100 Subject: [PATCH] make linter happy --- sktalk/corpus/conversation.py | 21 ++++++++++++--------- tests/corpus/test_conversation.py | 13 +++++++------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/sktalk/corpus/conversation.py b/sktalk/corpus/conversation.py index 383cb83..48521f8 100644 --- a/sktalk/corpus/conversation.py +++ b/sktalk/corpus/conversation.py @@ -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 @@ -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 @@ -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 diff --git a/tests/corpus/test_conversation.py b/tests/corpus/test_conversation.py index d84c7e7..c8d6442 100644 --- a/tests/corpus/test_conversation.py +++ b/tests/corpus/test_conversation.py @@ -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,