Commit 64a022e5 by Jaime Collado

Sequence tests added

parent 80ea6919
Showing with 37 additions and 18 deletions
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
...@@ -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: Should it support 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
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 sign in to comment