fix: resolve CI/CD issues - fixed coverage and ruff paths, removed unused imports
This commit is contained in:
@@ -1,55 +1,103 @@
|
|||||||
"""Tests for the converter module."""
|
"""Tests for the converter module."""
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from regex_humanizer.converter import convert_to_english, generate_description
|
from regex_humanizer.converter import convert_to_english, generate_description
|
||||||
|
|
||||||
|
|
||||||
class TestConvertToEnglish:
|
class TestConvertToEnglish:
|
||||||
|
"""Tests for the convert_to_english function."""
|
||||||
|
|
||||||
def test_convert_literal(self):
|
def test_convert_literal(self):
|
||||||
|
"""Test converting a literal pattern."""
|
||||||
result = convert_to_english("hello")
|
result = convert_to_english("hello")
|
||||||
assert "hello" in result.lower() or "letter" in result.lower()
|
assert "hello" in result.lower() or "letter" in result.lower()
|
||||||
|
|
||||||
def test_convert_character_class(self):
|
def test_convert_character_class(self):
|
||||||
|
"""Test converting a character class."""
|
||||||
result = convert_to_english("[abc]")
|
result = convert_to_english("[abc]")
|
||||||
assert "any" in result.lower() or "character" in result.lower()
|
assert "any" in result.lower() or "character" in result.lower()
|
||||||
|
|
||||||
def test_convert_inverted_class(self):
|
def test_convert_inverted_class(self):
|
||||||
|
"""Test converting an inverted character class."""
|
||||||
result = convert_to_english("[^abc]")
|
result = convert_to_english("[^abc]")
|
||||||
assert "except" in result.lower()
|
assert "except" in result.lower()
|
||||||
|
|
||||||
def test_convert_quantifier_star(self):
|
def test_convert_quantifier_star(self):
|
||||||
|
"""Test converting the * quantifier."""
|
||||||
result = convert_to_english("a*")
|
result = convert_to_english("a*")
|
||||||
assert "zero" in result.lower() or "more" in result.lower()
|
assert "zero" in result.lower() or "more" in result.lower()
|
||||||
|
|
||||||
def test_convert_quantifier_plus(self):
|
def test_convert_quantifier_plus(self):
|
||||||
|
"""Test converting the + quantifier."""
|
||||||
result = convert_to_english("a+")
|
result = convert_to_english("a+")
|
||||||
assert "one" in result.lower() or "more" in result.lower()
|
assert "one" in result.lower() or "more" in result.lower()
|
||||||
|
|
||||||
def test_convert_quantifier_question(self):
|
def test_convert_quantifier_question(self):
|
||||||
|
"""Test converting the ? quantifier."""
|
||||||
result = convert_to_english("a?")
|
result = convert_to_english("a?")
|
||||||
assert "optionally" in result.lower() or "zero" in result.lower()
|
assert "optionally" in result.lower() or "zero" in result.lower()
|
||||||
|
|
||||||
def test_convert_anchors(self):
|
def test_convert_anchors(self):
|
||||||
|
"""Test converting anchors."""
|
||||||
result = convert_to_english("^start$")
|
result = convert_to_english("^start$")
|
||||||
assert "start" in result.lower() and "end" in result.lower()
|
assert "start" in result.lower() and "end" in result.lower()
|
||||||
|
|
||||||
def test_convert_alternation(self):
|
def test_convert_alternation(self):
|
||||||
|
"""Test converting alternation."""
|
||||||
result = convert_to_english("a|b")
|
result = convert_to_english("a|b")
|
||||||
assert "or" in result.lower()
|
assert "or" in result.lower()
|
||||||
|
|
||||||
def test_convert_group(self):
|
def test_convert_group(self):
|
||||||
|
"""Test converting a group."""
|
||||||
result = convert_to_english("(abc)")
|
result = convert_to_english("(abc)")
|
||||||
assert "group" in result.lower()
|
assert "group" in result.lower()
|
||||||
|
|
||||||
|
def test_convert_non_capturing_group(self):
|
||||||
|
"""Test converting a non-capturing group."""
|
||||||
|
result = convert_to_english("(?:abc)")
|
||||||
|
assert "non-capturing" in result.lower() or "group" in result.lower()
|
||||||
|
|
||||||
def test_convert_special_sequence_digit(self):
|
def test_convert_special_sequence_digit(self):
|
||||||
|
"""Test converting digit sequence."""
|
||||||
result = convert_to_english(r"\d")
|
result = convert_to_english(r"\d")
|
||||||
assert "digit" in result.lower()
|
assert "digit" in result.lower()
|
||||||
|
|
||||||
def test_convert_special_sequence_word(self):
|
def test_convert_special_sequence_word(self):
|
||||||
|
"""Test converting word character sequence."""
|
||||||
result = convert_to_english(r"\w")
|
result = convert_to_english(r"\w")
|
||||||
assert "word" in result.lower()
|
assert "word" in result.lower()
|
||||||
|
|
||||||
def test_convert_email_pattern(self):
|
def test_convert_email_pattern(self):
|
||||||
result = convert_to_english(r"^\w+@[a-z]+\.[a]+$")
|
"""Test converting an email pattern."""
|
||||||
|
result = convert_to_english(r"^\w+@[a-z]+\.[a-z]+$")
|
||||||
assert "start" in result.lower() and "end" in result.lower()
|
assert "start" in result.lower() and "end" in result.lower()
|
||||||
|
|
||||||
|
def test_convert_phone_pattern(self):
|
||||||
|
"""Test converting a phone pattern."""
|
||||||
|
result = convert_to_english(r"\d{3}-\d{3}-\d{4}")
|
||||||
|
assert "digit" in result.lower()
|
||||||
|
|
||||||
|
def test_convert_empty_pattern(self):
|
||||||
|
"""Test converting an empty pattern."""
|
||||||
|
result = convert_to_english("")
|
||||||
|
assert result
|
||||||
|
|
||||||
|
def test_convert_complex_pattern(self):
|
||||||
|
"""Test converting a complex pattern."""
|
||||||
|
pattern = r"^(https?|ftp)://[^\s/$.?#].[^\s]*$"
|
||||||
|
result = convert_to_english(pattern)
|
||||||
|
assert "start" in result.lower() and "end" in result.lower()
|
||||||
|
|
||||||
|
|
||||||
|
class TestGenerateDescription:
|
||||||
|
"""Tests for the generate_description function."""
|
||||||
|
|
||||||
|
def test_generate_description_empty(self):
|
||||||
|
"""Test generating description for empty list."""
|
||||||
|
result = generate_description([])
|
||||||
|
assert "empty" in result.lower()
|
||||||
|
|
||||||
|
def test_generate_description_literal(self):
|
||||||
|
"""Test generating description for a literal."""
|
||||||
|
from regex_humanizer.parser import Literal
|
||||||
|
result = generate_description([Literal(value="a")])
|
||||||
|
assert "letter" in result.lower() or "a" in result.lower()
|
||||||
|
|||||||
Reference in New Issue
Block a user