Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jaime Collado
/
textflow
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
64a022e5
authored
Apr 06, 2022
by
Jaime Collado
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Sequence tests added
parent
80ea6919
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
18 deletions
tests/test_sequence.py
textflow/Sequence.py
tests/test_sequence.py
0 → 100644
View file @
64a022e5
import
pytest
from
textflow.Sequence
import
Sequence
class
CustomSequence
(
Sequence
):
def
__init__
(
self
,
text
:
str
):
self
.
id
=
"root"
self
.
sequences
=
text
.
split
(
" "
)
@pytest.fixture
def
sequence
():
return
CustomSequence
(
"Esto es una prueba"
)
def
test_str
(
sequence
):
assert
str
(
sequence
)
==
"id: root, sequences: ['Esto', 'es', 'una', 'prueba']"
def
test_repr
(
sequence
):
assert
repr
(
sequence
)
==
"Sequence('Esto', 'es', 'una', 'prueba')"
def
test_len
(
sequence
):
assert
len
(
sequence
)
==
4
def
test_iter
(
sequence
):
assert
list
(
sequence
)
==
[
"Esto"
,
"es"
,
"una"
,
"prueba"
]
def
test_getitem
(
sequence
):
assert
sequence
[
0
]
==
"Esto"
def
test_get_depth
():
pass
def
test_filter
():
pass
\ No newline at end of file
textflow/Sequence.py
View file @
64a022e5
...
@@ -23,7 +23,7 @@ class Sequence:
...
@@ -23,7 +23,7 @@ class Sequence:
self
.
id
=
object
self
.
id
=
object
else
:
else
:
self
.
id
=
"collection"
self
.
id
=
"collection"
self
.
sequences
=
[
"subcollection_1"
,
"subcollection_2"
,
"subcollection_
2
"
]
self
.
sequences
=
[
"subcollection_1"
,
"subcollection_2"
,
"subcollection_
3
"
]
def
__str__
(
self
):
def
__str__
(
self
):
return
f
"id: {self.id}, sequences: {self.sequences}"
return
f
"id: {self.id}, sequences: {self.sequences}"
...
@@ -52,7 +52,7 @@ class Sequence:
...
@@ -52,7 +52,7 @@ class Sequence:
raise
IndexError
(
f
"Sequence index '{i}' out of range"
)
raise
IndexError
(
f
"Sequence index '{i}' out of range"
)
else
:
else
:
return
self
.
sequences
[
i
]
return
self
.
sequences
[
i
]
else
:
# TODO: Support slices (e.g. [2:4])?
else
:
# TODO: S
hould it s
upport slices (e.g. [2:4])?
invalid_type
=
type
(
i
)
invalid_type
=
type
(
i
)
raise
TypeError
(
raise
TypeError
(
f
"Sequence indices must be integers or strings, not {invalid_type.__name__}"
f
"Sequence indices must be integers or strings, not {invalid_type.__name__}"
...
@@ -62,18 +62,4 @@ class Sequence:
...
@@ -62,18 +62,4 @@ class Sequence:
pass
# TODO
pass
# TODO
def
filter
(
self
,
level
,
criteria
):
def
filter
(
self
,
level
,
criteria
):
pass
# TODO
pass
# TODO
\ No newline at end of file
# TODO: Move these tests to the ./tests folder
if
__name__
==
"__main__"
:
sequence_from_folder
=
Sequence
(
"../tests/data/doc_1"
)
# File loading
sequence_from_file
=
Sequence
(
"lorem ipsum"
)
# String loading
sequence_from_folder
.
sequences
.
append
(
sequence_from_file
)
print
(
sequence_from_folder
)
print
(
sequence_from_folder
[
2
])
print
(
sequence_from_folder
[
"lorem ipsum"
])
for
s
in
sequence_from_folder
:
print
(
s
)
print
(
sequence_from_folder
[
20
])
# This should fail
\ No newline at end of file
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