From 4e42137b33a0b4a048c9fddf6310a37b833317cf Mon Sep 17 00:00:00 2001 From: Rob Hallam <0504004h@student.gla.ac.uk> Date: Tue, 3 Sep 2024 21:48:59 +0100 Subject: [PATCH] test: [mocks] add convenience classmethod and __eq__ Facilitates unit tests of TTA --- test/mocks.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/mocks.py b/test/mocks.py index 4cb016c..9ca095e 100644 --- a/test/mocks.py +++ b/test/mocks.py @@ -7,9 +7,16 @@ class MockInterval(): self.end = end self.duration = end - start + @classmethod + def from_duration(cls, duration): + return cls(start=0, end=duration) + def to_json(self): return {"start": self.start, "end": self.end} + def __eq__(self, other): + return self.start == other.start and self.end == other.end + class MockFeature(): """Mock feature object for testing""" def __init__(self, interval, source=None, feature_extractor="mock", score=0.0): @@ -21,6 +28,10 @@ class MockFeature(): def to_json(self): return {"interval": self.interval} + def __eq__(self, other): + return (self.interval == other.interval and self.source == other.source + and self.feature_extractor == other.feature_extractor) + class MockSource(): """Mock Source object for testing Feature""" def __init__(self, source=None, path=None):