Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Bioneland
Splito
Commits
45ff3605
Commit
45ff3605
authored
Nov 01, 2020
by
Tanguy Le Carrour
Browse files
Implement a Path class in the domain.
parent
b139daf9
Changes
2
Hide whitespace changes
Inline
Side-by-side
splito/domain/audio_editing/model.py
View file @
45ff3605
from
abc
import
ABC
from
abc
import
ABC
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
import
pathlib
@
dataclass
(
frozen
=
True
)
@
dataclass
(
frozen
=
True
)
...
@@ -8,6 +9,22 @@ class Interval:
...
@@ -8,6 +9,22 @@ class Interval:
end
:
int
=
0
end
:
int
=
0
@
dataclass
(
frozen
=
True
)
class
Path
:
__path
:
str
@
classmethod
def
from_string
(
cls
,
a_string
:
str
)
->
"Path"
:
return
Path
(
a_string
)
def
__str__
(
self
)
->
str
:
return
self
.
__path
def
with_suffix
(
self
,
a_suffix
:
str
)
->
"Path"
:
path
=
pathlib
.
Path
(
self
.
__path
)
return
Path
(
str
(
path
.
with_suffix
(
f
"
{
a_suffix
}{
path
.
suffix
}
"
)))
class
Track
(
ABC
):
class
Track
(
ABC
):
def
extract
(
self
,
an_interval
:
Interval
)
->
"Track"
:
def
extract
(
self
,
an_interval
:
Interval
)
->
"Track"
:
raise
NotImplementedError
()
raise
NotImplementedError
()
...
...
splito/domain/audio_editing/model_spec.py
View file @
45ff3605
from
mamba
import
describe
,
it
,
_it
# type: ignore
from
mamba
import
describe
,
it
,
_it
# type: ignore
from
robber
import
expect
# type: ignore
from
robber
import
expect
# type: ignore
from
splito.domain.audio_editing.model
import
Interval
from
splito.domain.audio_editing.model
import
Interval
,
Path
with
describe
(
Interval
):
with
describe
(
Interval
):
...
@@ -26,3 +26,29 @@ with describe(Interval):
...
@@ -26,3 +26,29 @@ with describe(Interval):
_
=
Interval
(
1
,
1
)
_
=
Interval
(
1
,
1
)
expect
(
action
).
to
.
throw
(
Exception
)
expect
(
action
).
to
.
throw
(
Exception
)
with
describe
(
Path
):
with
describe
(
Path
.
from_string
):
with
it
(
"returns a Path object"
):
path
=
Path
.
from_string
(
"a_path/a_file.ext"
)
expect
(
path
).
to
.
be
.
instanceof
(
Path
)
with
describe
(
Path
.
__str__
):
with
it
(
"returns the actual path as a string"
):
path
=
Path
.
from_string
(
"a_path/a_file.ext"
)
expect
(
str
(
path
)).
to
.
eq
(
"a_path/a_file.ext"
)
with
describe
(
Path
.
with_suffix
):
with
it
(
"returns a new Path object with an extra suffix"
):
path
=
Path
.
from_string
(
"a_path/a_file.ext"
)
path
=
path
.
with_suffix
(
".suffix"
)
expect
(
path
).
to
.
eq
(
Path
.
from_string
(
"a_path/a_file.suffix.ext"
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment