Commit 7b773488 authored by Tanguy Le Carrour's avatar Tanguy Le Carrour
Browse files

Fix use case.

parent 0f06c710
......@@ -12,6 +12,14 @@ class ExtractSubTracksRequest:
class ExtractSubTracksPresenter(ABC):
@abstractmethod
def not_an_audio_track(self, a_path: str) -> None:
pass
@abstractmethod
def wrong_interval(self, a_start: str, an_end: str) -> None:
pass
@abstractmethod
def sub_track_extracted(self, a_path: str) -> None:
pass
......@@ -23,12 +31,26 @@ class ExtractSubTracksInteractor:
self.__tracks = tracks
def execute(self, request: ExtractSubTracksRequest) -> None:
track = self.__tracks[request.path]
path = Path.from_string(request.path)
try:
track = self.__tracks[request.path]
except KeyError:
return self.__presenter.not_an_audio_track(request.path)
intervals = [Interval(start, end) for (start, end) in request.intervals]
intervals = self.__process_literal_interval(request.intervals)
for idx, interval in enumerate(intervals):
sub_track = track.extract(interval)
new_path = str(path.with_suffix(f".part-{idx + 1}"))
self.__tracks[new_path] = sub_track
self.__tracks[new_path] = track.extract(interval)
self.__presenter.sub_track_extracted(new_path)
def __process_literal_interval(
self, some_intervals: List[Tuple[str, str]]
) -> List[Interval]:
results = []
for (start, end) in some_intervals:
try:
results.append(Interval(int(start), int(end)))
except AttributeError:
self.__presenter.wrong_interval(start, end)
continue
return results
......@@ -38,3 +38,20 @@ with describe(ExtractSubTracksInteractor):
expect(self.tracks.__setitem__.call_count).to.eq(2)
expect(self.presenter.sub_track_extracted.call_count).to.eq(2)
with it("handles wrong tracks"):
interactor = ExtractSubTracksInteractor(self.presenter, self.tracks)
request = ExtractSubTracksRequest("a_track.wav", [])
self.tracks.__getitem__.side_effect = KeyError()
interactor.execute(request)
expect(self.presenter.not_an_audio_track).to.have.been.called()
with it("handles wrong intervals"):
interactor = ExtractSubTracksInteractor(self.presenter, self.tracks)
request = ExtractSubTracksRequest("a_track.wav", [("1", "0")])
interactor.execute(request)
expect(self.presenter.wrong_interval).to.have.been.called()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment