Fixing some sequence tests

parent 77873cd9
Showing with 41 additions and 16 deletions
...@@ -18,6 +18,11 @@ def test_sequence_wrong_format(): ...@@ -18,6 +18,11 @@ def test_sequence_wrong_format():
Sequence("text", "tests/data/doc_1.txt"), Sequence("text", "tests/data/doc_1.txt"),
"Lorem ipsum dolor sit amet\nNam lectus turpis" "Lorem ipsum dolor sit amet\nNam lectus turpis"
) )
,
pytest.param(
Sequence("directory", "tests/data"),
" "
)
] ]
) )
def test_str(sequence, expected): def test_str(sequence, expected):
...@@ -57,10 +62,14 @@ def test_str(sequence, expected): ...@@ -57,10 +62,14 @@ def test_str(sequence, expected):
[ [
pytest.param( pytest.param(
Sequence("string", "Lorem ipsum dolor sit amet"), Sequence("string", "Lorem ipsum dolor sit amet"),
5 1
), ),
pytest.param( pytest.param(
Sequence("text", "tests/data/doc_1.txt"), Sequence("text", "tests/data/doc_1.txt"),
1
),
pytest.param(
Sequence("directory","tests/data" ),
2 2
) )
] ]
...@@ -74,10 +83,7 @@ def test_len(sequence, expected): ...@@ -74,10 +83,7 @@ def test_len(sequence, expected):
[ [
pytest.param( pytest.param(
Sequence("string", "Lorem ipsum"), Sequence("string", "Lorem ipsum"),
{ [Sequence() for _ in range(2)]
"child": ("token", "Lorem"),
"sequence": Sequence()
}
), ),
pytest.param( pytest.param(
Sequence("text", "tests/data/doc_1.txt"), Sequence("text", "tests/data/doc_1.txt"),
...@@ -85,6 +91,10 @@ def test_len(sequence, expected): ...@@ -85,6 +91,10 @@ def test_len(sequence, expected):
"child": [("string", "Lorem ipsum dolor sit amet"), ("string", "Nam lectus turpis")], "child": [("string", "Lorem ipsum dolor sit amet"), ("string", "Nam lectus turpis")],
"sequence": [Sequence() for _ in range(2)] "sequence": [Sequence() for _ in range(2)]
} }
),
pytest.param(
Sequence("directory","tests/data" ),
2
) )
] ]
) )
...@@ -96,17 +106,15 @@ def test_iter(sequence, expected): ...@@ -96,17 +106,15 @@ def test_iter(sequence, expected):
[ [
pytest.param( pytest.param(
Sequence("string", "Lorem ipsum dolor sit amet"), Sequence("string", "Lorem ipsum dolor sit amet"),
{ [Sequence() for _ in range(5)]
"child": ("token", "Lorem"),
"sequence": Sequence()
}
), ),
pytest.param( pytest.param(
Sequence("text", "tests/data/doc_1.txt"), Sequence("text", "tests/data/doc_1.txt"),
{ [Sequence() for _ in range(8)]
"chile": ("string", "Lorem ipsum dolor sit amet"), ),
"sequence": Sequence() pytest.param(
} Sequence("directory","tests/data" ),
2
) )
] ]
) )
...@@ -114,8 +122,25 @@ def test_getitem(sequence, expected): ...@@ -114,8 +122,25 @@ def test_getitem(sequence, expected):
assert sequence[0] == expected assert sequence[0] == expected
def test_get_depth(): @pytest.mark.parametrize(
pass "sequence, expected",
[
pytest.param(
Sequence("string", "Lorem ipsum dolor sit amet"),
(1,["tokens"])
),
pytest.param(
Sequence("text", "tests/data/doc_1.txt"),
(1, ["tokens"])
),
pytest.param(
Sequence("directory","tests/data" ),
(2, ["files", "tokens"])
)
]
)
def test_get_depth(sequence, expected):
assert sequence.depth() == expected
def test_filter(): def test_filter():
......
...@@ -64,7 +64,7 @@ class Sequence: ...@@ -64,7 +64,7 @@ class Sequence:
self.format = format self.format = format
self.children = {} self.children = {}
self.metadata = {} self.metadata = {"text": " "}
if format == "token": if format == "token":
if not isinstance(src, str): if not isinstance(src, str):
raise ValueError(f"{src} is not an instance of token") raise ValueError(f"{src} is not an instance of token")
......
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