Commit 72218dcc authored by Tanguy Le Carrour's avatar Tanguy Le Carrour
Browse files

Reorganise and rename interface classes.

parent fc1b8a26
......@@ -3,10 +3,8 @@ from typing import Tuple
import click
from splito.interfaces.cli import (
ExtractSubTracksController,
ExtractSubTracksPresenter,
)
import splito.interfaces.from_base_types as controllers
import splito.interfaces.to_terminal as presenters
from splito.use_cases.extract_sub_tracks import ExtractSubTracksInteractor
......@@ -21,8 +19,8 @@ def cli(ctx: click.Context) -> None:
@click.argument("track")
@click.argument("intervals", nargs=-1)
def extract(ctx: click.Context, track: str, intervals: Tuple[str]) -> None:
controller = ExtractSubTracksController(track, list(intervals))
presenter = ExtractSubTracksPresenter()
controller = controllers.ExtractSubTracks(track, list(intervals))
presenter = presenters.ExtractSubTracks()
interactor = ExtractSubTracksInteractor(presenter, ctx.obj["tracks"])
controller.call(interactor)
click.echo(presenter.to_string())
......
from typing import List, Tuple
from splito.use_cases.extract_sub_tracks import (
ExtractSubTracksRequest,
ExtractSubTracksInteractor,
)
class ExtractSubTracks:
def __init__(self, a_path: str, some_interval_paires: List[str]) -> None:
self.__request = ExtractSubTracksRequest(
a_path, self.__extract_intervals(some_interval_paires)
)
def __extract_intervals(
self, some_interval_paires: List[str]
) -> List[Tuple[str, str]]:
intervals: List[Tuple[str, str]] = []
for paire in some_interval_paires:
interval = paire.split("-", 1)
if len(interval) == 2:
intervals.append((interval[0], interval[1]))
else:
intervals.append((interval[0], "0"))
return intervals
def call(self, interactor: ExtractSubTracksInteractor) -> None:
interactor.execute(self.__request)
......@@ -7,19 +7,16 @@ from splito.use_cases.extract_sub_tracks import (
ExtractSubTracksInteractor,
ExtractSubTracksRequest,
)
from splito.interfaces.cli import (
ExtractSubTracksController,
ExtractSubTracksPresenter,
)
from splito.interfaces.from_base_types import ExtractSubTracks
with describe(ExtractSubTracksController):
with describe(ExtractSubTracks):
with before.each as self:
self.interactor = mock.create_autospec(spec=ExtractSubTracksInteractor)
with it("handles good parameters"):
controller = ExtractSubTracksController("a_path", ["1-2"])
controller = ExtractSubTracks("a_path", ["1-2"])
controller.call(self.interactor)
......@@ -28,36 +25,10 @@ with describe(ExtractSubTracksController):
)
with it("handles bad parameters"):
controller = ExtractSubTracksController("a_path", ["1~2.3"])
controller = ExtractSubTracks("a_path", ["1~2.3"])
controller.call(self.interactor)
expect(self.interactor.execute).to.have.been.called(
ExtractSubTracksRequest("a_path", [("1~2.3", "0")])
)
with describe(ExtractSubTracksPresenter):
with it("handles extracting sub-tracks"):
presenter = ExtractSubTracksPresenter()
presenter.sub_track_extracted("a_path/a_file-1.mp3")
expect(presenter.exit_code()).to.eq(0)
expect(presenter.to_string()).to.contain("a_path/a_file-1.mp3")
with it("handles wrong track"):
presenter = ExtractSubTracksPresenter()
presenter.not_an_audio_track("a_path/a_file-1.mp3")
expect(presenter.exit_code()).to.eq(1)
expect(presenter.to_string()).to.contain("a_path/a_file-1.mp3")
with it("handles wrong intervals"):
presenter = ExtractSubTracksPresenter()
presenter.wrong_interval("1", "0")
expect(presenter.to_string()).to.contain("WARN")
from typing import List, Tuple
from typing import List
from splito.use_cases.extract_sub_tracks import (
ExtractSubTracksRequest,
ExtractSubTracksInteractor,
ExtractSubTracksPresenter as __ExtractSubTracksPresenter,
)
from splito.use_cases.extract_sub_tracks import ExtractSubTracksPresenter
class ExtractSubTracksController:
def __init__(self, a_path: str, some_interval_paires: List[str]) -> None:
self.__request = ExtractSubTracksRequest(
a_path, self.__extract_intervals(some_interval_paires)
)
def __extract_intervals(
self, some_interval_paires: List[str]
) -> List[Tuple[str, str]]:
intervals: List[Tuple[str, str]] = []
for paire in some_interval_paires:
interval = paire.split("-", 1)
if len(interval) == 2:
intervals.append((interval[0], interval[1]))
else:
intervals.append((interval[0], "0"))
return intervals
def call(self, interactor: ExtractSubTracksInteractor) -> None:
interactor.execute(self.__request)
class ExtractSubTracksPresenter(__ExtractSubTracksPresenter):
class ExtractSubTracks(ExtractSubTracksPresenter):
def __init__(self) -> None:
self.__exit_code = 1
self.__sub_tracks: List[str] = []
......
from mamba import describe, it # type: ignore
from robber import expect # type: ignore
from splito.interfaces.to_terminal import ExtractSubTracks
with describe(ExtractSubTracks):
with it("handles extracting sub-tracks"):
presenter = ExtractSubTracks()
presenter.sub_track_extracted("a_path/a_file-1.mp3")
expect(presenter.exit_code()).to.eq(0)
expect(presenter.to_string()).to.contain("a_path/a_file-1.mp3")
with it("handles wrong track"):
presenter = ExtractSubTracks()
presenter.not_an_audio_track("a_path/a_file-1.mp3")
expect(presenter.exit_code()).to.eq(1)
expect(presenter.to_string()).to.contain("a_path/a_file-1.mp3")
with it("handles wrong intervals"):
presenter = ExtractSubTracks()
presenter.wrong_interval("1", "0")
expect(presenter.to_string()).to.contain("WARN")
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