-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update tests for new taxonomy parser
- Loading branch information
1 parent
6674876
commit cd1e288
Showing
5 changed files
with
57 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .parser import Parser | ||
from .taxonomy_parser import TaxonomyParser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,43 @@ | ||
import pathlib | ||
|
||
import pytest | ||
|
||
from openfoodfacts_taxonomy_parser import normalizer, parser | ||
|
||
# taxonomy in text format : test.txt | ||
TEST_TAXONOMY_TXT = str(pathlib.Path(__file__).parent.parent / "data" / "test.txt") | ||
|
||
|
||
def test_normalized_filename(neo4j): | ||
with neo4j.session() as session: | ||
x = parser.Parser(session) | ||
normalizer = x.normalized_filename | ||
name = normalizer("test") | ||
assert name == "test.txt" | ||
name = normalizer("test.txt") | ||
assert name == "test.txt" | ||
name = normalizer("t") | ||
assert name == "t.txt" | ||
@pytest.mark.parametrize( | ||
"filename, normalized_name", | ||
[ | ||
("test", "test.txt"), | ||
("test.txt", "test.txt"), | ||
("t", "t.txt"), | ||
], | ||
) | ||
def test_normalized_filename(filename: str, normalized_name: str): | ||
taxonomy_parser = parser.TaxonomyParser() | ||
assert taxonomy_parser._normalized_filename(filename) == normalized_name | ||
|
||
|
||
def test_fileiter(neo4j): | ||
with neo4j.session() as session: | ||
x = parser.Parser(session) | ||
file = x.file_iter(TEST_TAXONOMY_TXT) | ||
|
||
for counter, (_, line) in enumerate(file): | ||
assert line == "" or line[0] == "#" or ":" in line | ||
if counter == 26: | ||
assert line == "carbon_footprint_fr_foodges_value:fr:10" | ||
assert counter == 37 | ||
|
||
|
||
def test_normalizing(): | ||
text = "Numéro #1, n°1 des ¾ des Français*" | ||
text = normalizer.normalizing(text, "fr") | ||
assert text == "numero-1-n-1-des-des-francais" | ||
text = "Randôm Languäge wìth àccénts" | ||
normal_text = normalizer.normalizing(text, "fr") | ||
assert normal_text == "random-language-with-accents" | ||
normal_text = normalizer.normalizing(text, "de") | ||
assert normal_text == "randôm-languäge-wìth-àccénts" | ||
taxonomy_parser = parser.TaxonomyParser() | ||
file_iterator = taxonomy_parser._file_iter(TEST_TAXONOMY_TXT) | ||
for counter, (_, line) in enumerate(file_iterator): | ||
assert line == "" or line[0] == "#" or ":" in line | ||
if counter == 26: | ||
assert line == "carbon_footprint_fr_foodges_value:fr:10" | ||
assert counter == 37 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"text, normalized_text, lang", | ||
[ | ||
("Numéro #1, n°1 des ¾ des Français*", "numero-1-n-1-des-des-francais", "fr"), | ||
("Randôm Languäge wìth àccénts", "random-language-with-accents", "fr"), | ||
("Randôm Languäge wìth àccénts", "randôm-languäge-wìth-àccénts", "de"), | ||
], | ||
) | ||
def test_normalizing(text: str, normalized_text: str, lang: str): | ||
assert normalizer.normalizing(text, lang) == normalized_text |