Skip to content

Commit

Permalink
add some pytest to test ascii filtering fct
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMainguy committed Oct 18, 2024
1 parent 0b6d1df commit fbe6132
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tests/utils/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import zipfile
from typing import Generator

from ppanggolin.utils import is_compressed, read_compressed_or_not, write_compressed_or_not

from ppanggolin.utils import is_compressed, read_compressed_or_not, write_compressed_or_not, has_non_ascii, replace_non_ascii

class TestCompressed:
"""
Expand Down Expand Up @@ -157,3 +156,27 @@ def test_write_uncompressed(self, plain_file_path: Path) -> None:
f.write("Test data")
with open(plain_file_path, 'r') as f:
assert f.read() == "Test data"


# Test cases for has_non_ascii
@pytest.mark.parametrize("input_string, expected", [
("Escherichia_coli", False), # All ASCII characters
("Escherichia_colí", True), # Contains non-ASCII character 'í'
("simple_string", False), # Simple ASCII string
("Ωmega", True), # Contains non-ASCII character 'Ω'
("", False), # Empty string should return False
])
def test_has_non_ascii(input_string, expected):
assert has_non_ascii(input_string) == expected

# Test cases for replace_non_ascii
@pytest.mark.parametrize("input_string, replacement, expected", [
("Escherichia_coli", "_", "Escherichia_coli"), # All ASCII characters, no replacement needed
("Escherichia_colí", "_", "Escherichia_col_"), # Replace 'í' with '_'
("Ωmega", "-", "-mega"), # Replace 'Ω' with '-'
("Escherichia_Ωcoli", "X", "Escherichia_Xcoli"),# Replace 'Ω' with 'X'
("", "_", ""), # Empty string, no replacement
])
def test_replace_non_ascii(input_string, replacement, expected):
assert replace_non_ascii(input_string, replacement) == expected

0 comments on commit fbe6132

Please sign in to comment.