Skip to content

Commit

Permalink
added test for synchronous versions
Browse files Browse the repository at this point in the history
  • Loading branch information
hitblast committed Dec 9, 2024
1 parent b103367 commit 14e0fe5
Show file tree
Hide file tree
Showing 2 changed files with 307 additions and 55 deletions.
95 changes: 40 additions & 55 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,28 @@
)

# Import local modules.
import pytest

import avro
from avro.core import config


# Test functions for this file.
@pytest.mark.asyncio
async def test_patterns_without_rules_from_config() -> NoReturn:
def test_patterns_without_rules_from_config() -> NoReturn:
"""
Tests all patterns from config that don't have rules.
"""

for pattern in config.DICT["avro"]["patterns"]:
if "rules" not in pattern and pattern.get("find", None):
assert pattern["replace"] == await avro.parse(pattern["find"])
assert pattern["replace"] == avro.parse_sync(pattern["find"])


@pytest.mark.asyncio
async def test_patterns_without_rules_not_from_config() -> NoReturn:
def test_patterns_without_rules_not_from_config() -> NoReturn:
"""
Tests all patterns not from config that don't have rules.
This test is done in addition to
test_patterns_without_rules_from_config() to ensure that text
passed manually to avro.parse are properly parsed when they
passed manually to avro.parse_sync are properly parsed when they
don't exact match a pattern that has no rules specified.
"""

Expand All @@ -49,11 +45,10 @@ async def test_patterns_without_rules_not_from_config() -> NoReturn:
}

for key, value in conjunctions.items():
assert key == await avro.parse(value)
assert key == avro.parse_sync(value)


@pytest.mark.asyncio
async def test_patterns_numbers() -> NoReturn:
def test_patterns_numbers() -> NoReturn:
"""
Test patterns - numbers
"""
Expand All @@ -73,11 +68,10 @@ async def test_patterns_numbers() -> NoReturn:
}

for key, value in numbers.items():
assert key == await avro.parse(value)
assert key == avro.parse_sync(value)


@pytest.mark.asyncio
async def test_patterns_punctuations() -> NoReturn:
def test_patterns_punctuations() -> NoReturn:
"""
Tests patterns - punctuations
"""
Expand All @@ -89,12 +83,11 @@ async def test_patterns_punctuations() -> NoReturn:
}

for key, value in punctuations.items():
assert key == await avro.parse(value)
assert value == await avro.reverse(key)
assert key == avro.parse_sync(value)
assert value == avro.reverse_sync(key)


@pytest.mark.asyncio
async def test_patterns_with_rules_svaravarna() -> NoReturn:
def test_patterns_with_rules_svaravarna() -> NoReturn:
"""
Test patterns - with rules - svaravarna / shoroborno (derived from Bengali)
"""
Expand All @@ -106,19 +99,18 @@ async def test_patterns_with_rules_svaravarna() -> NoReturn:
"ঈ": "I",
"উ": "u",
"ঊ": "oo",
"ঊ": "U",
"ঊ": "U", # noqa: F601
"এ": "e",
"ঐ": "OI",
"ও": "O",
"ঔ": "OU",
}

for key, value in svaravarna.items():
assert key == await avro.parse(value)
assert key == avro.parse_sync(value)


@pytest.mark.asyncio
async def test_non_ascii() -> NoReturn:
def test_non_ascii() -> NoReturn:
"""
Test processor response for non-ASCII characters.
Parse function should return any non-ASCII characters that is passed to it.
Expand All @@ -133,25 +125,23 @@ async def test_non_ascii() -> NoReturn:
}

for key, value in non_ascii.items():
assert key == await avro.parse(value)
assert key == avro.parse_sync(value)


@pytest.mark.asyncio
async def test_ascii() -> NoReturn:
def test_ascii() -> NoReturn:
"""
Test processor response for ASCII characters.
Reverse function should return any ASCII characters that is passed to it.
"""

assert "Avwg evsjvi gan MvB|" == await avro.reverse("Avwg evsjvi গান MvB|")
assert "Avwg evsjvi gan MvB|" == avro.reverse_sync("Avwg evsjvi গান MvB|")
assert (
"Avwg amar Avwg‡K wPiw`b GB banglay Lyu‡R cvB!"
== await avro.reverse("Avwg আমার Avwg‡K wPiw`b GB বাংলায় Lyu‡R cvB!")
== avro.reverse_sync("Avwg আমার Avwg‡K wPiw`b GB বাংলায় Lyu‡R cvB!")
)


@pytest.mark.asyncio
async def test_words_with_punctuations() -> NoReturn:
def test_words_with_punctuations() -> NoReturn:
"""
Test parsing and reversing of words with punctuations.
"""
Expand All @@ -164,104 +154,99 @@ async def test_words_with_punctuations() -> NoReturn:
}

for key, value in test_words.items():
assert key == await avro.parse(value)
assert value.lower() == await avro.reverse(key)
assert key == avro.parse_sync(value)
assert value.lower() == avro.reverse_sync(key)


@pytest.mark.asyncio
async def test_exceptions() -> NoReturn:
def test_exceptions() -> NoReturn:
"""
Test parsing and reversing of exceptions.
"""

assert "আমি উইকিপিডিয়া আর ফেসবুক চালাই।" == await avro.parse(
assert "আমি উইকিপিডিয়া আর ফেসবুক চালাই।" == avro.parse_sync(
"ami Wikipedia ar Facebook calai."
)
assert "ami Wikipedia ar Facebook chalai." == await avro.reverse(
assert "ami Wikipedia ar Facebook chalai." == avro.reverse_sync(
"আমি উইকিপিডিয়া আর ফেসবুক চালাই।"
)


@pytest.mark.asyncio
async def test_conversion_bijoy_func() -> NoReturn:
def test_conversion_bijoy_func() -> NoReturn:
"""
Test conversion to Bijoy directly.
"""

# Regular Conversion.
assert "Avwg evsjvq Mvb MvB;" == await avro.to_bijoy("আমি বাংলায় গান গাই;")
assert "Avwg evsjvq Mvb MvB;" == avro.to_bijoy_sync("আমি বাংলায় গান গাই;")
assert [
"Avwg evsjvi Mvb MvB|",
"Avwg Avgvi Avwg‡K wPiw`b GB evsjvq Lyu‡R cvB!",
] == await avro.to_bijoy(
] == avro.to_bijoy_sync(
"আমি বাংলার গান গাই।", "আমি আমার আমিকে চিরদিন এই বাংলায় খুঁজে পাই!"
)

# Fail-safe Conversion.
assert "Hello, World!" == await avro.to_bijoy("Hello, World!")
assert "Hello, World!" == avro.to_bijoy_sync("Hello, World!")


@pytest.mark.asyncio
async def test_conversion_unicode_func() -> NoReturn:
def test_conversion_unicode_func() -> NoReturn:
"""
Test conversion to Unicode directly.
"""

# Regular Conversion.
assert "আমি বাংলায় গান গাই;" == await avro.to_unicode("Avwg evsjvh় Mvb MvB;")
assert "আমি বাংলায় গান গাই;" == avro.to_unicode_sync("Avwg evsjvh় Mvb MvB;")
assert [
"আমি বাংলার গান গাই।",
"আমি আমার আমিকে চিরদিন এই বাংলায় খুঁজে পাই!",
] == await avro.to_unicode(
] == avro.to_unicode_sync(
"Avwg evsjvi Mvb MvB|", "Avwg Avgvi Avwg‡K wPiw`b GB evsjvq Lyu‡R cvB!"
)


@pytest.mark.asyncio
async def test_parse_sentences() -> NoReturn:
def test_parse_sentences() -> NoReturn:
"""
Test parsing of sentences (Unicode).
"""

# Default parsing.
assert "আমি বাংলায় গান গাই;" == await avro.parse("ami banglay gan gai;")
assert "আমি বাংলায় গান গাই;" == avro.parse_sync("ami banglay gan gai;")
assert [
"আমি বাংলার গান গাই।",
"আমি আমার আমিকে চিরদিন এই বাংলায় খুঁজে পাই।",
] == await avro.parse(
] == avro.parse_sync(
"ami banglar gan gai.", "ami amar amike cirodin ei banglay khu^je pai."
)

# Bijoy parsing.
assert "Avwg evsjvq Mvb MvB;" == await avro.parse(
assert "Avwg evsjvq Mvb MvB;" == avro.parse_sync(
"ami banglay gan gai;", bijoy=True
)
assert [
"Avwg evsjvi Mvb MvB|",
"Avwg Avgvi Avwg‡K wPiw`b GB evsjvq Lyu‡R cvB!",
] == await avro.parse(
] == avro.parse_sync(
"ami banglar gan gai.",
"ami amar amike cirodin ei banglay khu^je pai!",
bijoy=True,
)


@pytest.mark.asyncio
async def test_reverse_sentences() -> NoReturn:
def test_reverse_sentences() -> NoReturn:
"""
Test reversing of sentences (Unicode).
"""

# Default reversing.
assert "ami banglay gan gai." == await avro.reverse("আমি বাংলায় গান গাই।")
assert "ami banglay gan gai." == avro.reverse_sync("আমি বাংলায় গান গাই।")
assert [
"rohim, tomake korim dakche. ekhon ki rowna debe?",
"rowna dile amake bole zew.",
] == await avro.reverse(
] == avro.reverse_sync(
"রহিম, তোমাকে করিম ডাকছে। এখন কি রওনা দেবে?", "রওনা দিলে আমাকে বলে যেও।"
)

# Bijoy reversing.
assert "ami banglar gan gai." == await avro.reverse(
assert "ami banglar gan gai." == avro.reverse_sync(
"Avwg evsjvi Mvb MvB|", from_bijoy=True
)
Loading

0 comments on commit 14e0fe5

Please sign in to comment.