diff --git a/freedium-library/src/freedium_library/services/medium/container.py b/freedium-library/src/freedium_library/services/medium/container.py index 029c085..1c0aaa1 100644 --- a/freedium-library/src/freedium_library/services/medium/container.py +++ b/freedium-library/src/freedium_library/services/medium/container.py @@ -1,10 +1,12 @@ from dependency_injector import containers, providers +from freedium_library.services.medium.validators import ( + MediumServicePathValidator, +) from freedium_library.utils.http import Request from .api import MediumApiService from .config import MediumConfig -from .validators import MediumServicePathValidator class MediumContainer(containers.DeclarativeContainer): diff --git a/freedium-library/src/freedium_library/services/medium/static/__init__.py b/freedium-library/src/freedium_library/services/medium/static/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/freedium-library/src/freedium_library/services/medium/static/tests/__init__.py b/freedium-library/src/freedium_library/services/medium/static/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/freedium-library/src/freedium_library/services/medium/static/test_static.py b/freedium-library/src/freedium_library/services/medium/static/tests/test_static.py similarity index 99% rename from freedium-library/src/freedium_library/services/medium/static/test_static.py rename to freedium-library/src/freedium_library/services/medium/static/tests/test_static.py index c1eaab8..4946266 100644 --- a/freedium-library/src/freedium_library/services/medium/static/test_static.py +++ b/freedium-library/src/freedium_library/services/medium/static/tests/test_static.py @@ -44,7 +44,7 @@ def get_domains_from_file(filepath: str) -> list[str]: def get_file_path(filename: str) -> str: - return os.path.join(os.path.dirname(os.path.abspath(__file__)), filename) + return os.path.join(os.path.dirname(os.path.abspath(__file__)), "../", filename) @pytest.mark.integration diff --git a/freedium-library/src/freedium_library/services/medium/tests/__init__.py b/freedium-library/src/freedium_library/services/medium/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/freedium-library/src/freedium_library/services/medium/validators_hashes_test.py b/freedium-library/src/freedium_library/services/medium/tests/validators_hashes_test.py similarity index 100% rename from freedium-library/src/freedium_library/services/medium/validators_hashes_test.py rename to freedium-library/src/freedium_library/services/medium/tests/validators_hashes_test.py diff --git a/freedium-library/src/freedium_library/services/medium/validators_url_test.py b/freedium-library/src/freedium_library/services/medium/tests/validators_url_test.py similarity index 100% rename from freedium-library/src/freedium_library/services/medium/validators_url_test.py rename to freedium-library/src/freedium_library/services/medium/tests/validators_url_test.py diff --git a/freedium-library/src/freedium_library/utils/http/client/tests/__init__.py b/freedium-library/src/freedium_library/utils/http/client/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/freedium-library/src/freedium_library/utils/http/client/client_test.py b/freedium-library/src/freedium_library/utils/http/client/tests/client_test.py similarity index 100% rename from freedium-library/src/freedium_library/utils/http/client/client_test.py rename to freedium-library/src/freedium_library/utils/http/client/tests/client_test.py diff --git a/freedium-library/src/freedium_library/utils/meta/tests/__init__.py b/freedium-library/src/freedium_library/utils/meta/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/freedium-library/src/freedium_library/utils/meta/pydantic_test.py b/freedium-library/src/freedium_library/utils/meta/tests/pydantic_test.py similarity index 100% rename from freedium-library/src/freedium_library/utils/meta/pydantic_test.py rename to freedium-library/src/freedium_library/utils/meta/tests/pydantic_test.py diff --git a/freedium-library/src/freedium_library/utils/datetime_test.py b/freedium-library/src/freedium_library/utils/tests/datetime_test.py similarity index 100% rename from freedium-library/src/freedium_library/utils/datetime_test.py rename to freedium-library/src/freedium_library/utils/tests/datetime_test.py diff --git a/freedium-library/src/freedium_library/utils/json_test.py b/freedium-library/src/freedium_library/utils/tests/json_test.py similarity index 100% rename from freedium-library/src/freedium_library/utils/json_test.py rename to freedium-library/src/freedium_library/utils/tests/json_test.py diff --git a/freedium-library/src/freedium_library/utils/utils/test_utf_handler.py b/freedium-library/src/freedium_library/utils/utils/test_utf_handler.py new file mode 100644 index 0000000..8a49aa1 --- /dev/null +++ b/freedium-library/src/freedium_library/utils/utils/test_utf_handler.py @@ -0,0 +1,145 @@ +from loguru import logger + +from freedium_library.utils.utils.utf_handler import UTFEncoding, UTFHandler + +logger.add("test.log", level="TRACE") + + +def test_multibyte_emoji(): + # Test string with emoji characters + text = "Noah dragged his two printers out from Settings โš™๏ธ < Printers & Scanners ๐Ÿ–จ๏ธ and dropped them in Dock or Desktop, I donโ€™t remember โ€” but you can drag to both the places.'" + + # Initialize handler with UTF-16 encoding + handler = UTFHandler(text, UTFEncoding.UTF16) + + assert str(handler) == text + + # Test position mappings around emojis + assert handler.get_encoded_position(39) == 39 # Before "Settings โš™๏ธ" + assert handler.get_encoded_position(76) == 77 # After "Scanners ๐Ÿ–จ๏ธ" + + # Test string slicing around emoji + emoji_section = handler[39:76] + assert emoji_section == "Settings โš™๏ธ < Printers & Scanners ๐Ÿ–จ๏ธ" + + # Test insertion before emoji + handler.insert(39, "") + handler.insert(77, "") + + expected = text[:39] + "" + text[39:76] + "" + text[76:] + # expected = expected.replace("๐Ÿ–จ๏ธ", "๐Ÿ–จ") + + assert bytes(str(handler), "utf-8") == bytes(expected, "utf-8") + assert str(handler) == expected + + +def test_mathematical_monospace_x(): + text = "Whilst academic research papers have highlighted performance issues with the prophet since 2017, the propagation of package popularity through the data science community has been fueled by ๐™—๐™ค๐™ฉ๐™ ๐™š๐™ญ๐™˜๐™š๐™จ๐™จ๐™ž๐™ซ๐™š ๐™˜๐™ก๐™–๐™ž๐™ข๐™จ ๐™›๐™ง๐™ค๐™ข ๐™ฉ๐™๐™š ๐™ค๐™ง๐™ž๐™œ๐™ž๐™ฃ๐™–๐™ก ๐™™๐™š๐™ซ๐™š๐™ก๐™ค๐™ฅ๐™ข๐™š๐™ฃ๐™ฉ ๐™ฉ๐™š๐™–๐™ข ๐™—๐™ช๐™ฉ ๐™ข๐™ค๐™ง๐™š ๐™ž๐™ข๐™ฅ๐™ค๐™ง๐™ฉ๐™–๐™ฃ๐™ฉ๐™ก๐™ฎ ๐™—๐™ฎ ๐™ข๐™–๐™ง๐™ ๐™š๐™ฉ๐™ž๐™ฃ๐™œ ๐™ค๐™› ๐™ฉ๐™๐™š ๐™ฃ๐™ค๐™ฃ-๐™ฅ๐™š๐™ง๐™›๐™ค๐™ง๐™ข๐™ž๐™ฃ๐™œ ๐™ฅ๐™–๐™˜๐™ ๐™–๐™œ๐™š ๐™ซ๐™ž๐™– ๐™–๐™ง๐™ฉ๐™ž๐™˜๐™ก๐™š๐™จ ๐™ค๐™ฃ ๐™ˆ๐™š๐™™๐™ž๐™ช๐™ข ๐™–๐™ฃ๐™™ ๐™จ๐™ค๐™˜๐™ž๐™–๐™ก ๐™ข๐™š๐™™๐™ž๐™–." + + handler = UTFHandler(text, UTFEncoding.UTF16) + + assert str(handler) == text + + start_pos = text.index("๐™—") + + assert handler.get_encoded_position(start_pos) == start_pos + + o_multibyte = text.index("๐™ค") + assert handler.get_encoded_position(o_multibyte) > o_multibyte + + handler.insert(189, "") + handler.insert(197, "") + + expected = text[:189] + "" + text[189:193] + "" + text[193:] + assert str(handler) == expected + + +def test_mathematical_monospace(): + text = "by ๐™—๐™ค๐™ฉ๐™ ๐™š๐™ญ" + + handler = UTFHandler(text, UTFEncoding.UTF16) + + assert str(handler) == text + + # Test encoded positions for mathematical monospace characters + assert handler.get_encoded_position(3) == 3 # Position before '๐™—' + assert handler.get_encoded_position(5) == 7 # Position after '๐™—' + assert handler.get_encoded_position(7) == 11 # Position after '๐™ค' + # assert handler.get_encoded_position(9) == 15 # Position after '๐™ฉ' + + handler.insert(3, "") + handler.insert(11, "") + + expected = text[:3] + "" + text[3:7] + "" + text[7:] + assert str(handler) == expected + + +def test_utf8_handling(): + # Test with UTF-8 encoded text containing special characters + text = "Hello ไธ–็•Œ! ๐ŸŒ" + handler = UTFHandler(text, UTFEncoding.UTF8) + + assert str(handler) == text + + # Test position mapping with UTF-8 characters + assert handler.get_encoded_position(6) == 6 # Position before 'ไธ–' + assert handler.get_encoded_position(8) == 12 # Position after '็•Œ' + + # Test insertion around UTF-8 characters + handler.insert(6, "") + handler.insert(17, "") + + expected = "Hello ไธ–็•Œ! ๐ŸŒ" + assert str(handler) == expected + + +def test_utf32_handling(): + # Test with UTF-32 encoded text + text = "Testing ๐Ÿš€ UTF-32 ๐ŸŽฏ" + handler = UTFHandler(text, UTFEncoding.UTF32) + + assert str(handler) == text + + # Test position mapping with UTF-32 characters + assert handler.get_encoded_position(8) == 8 # Position before rocket + assert handler.get_encoded_position(18) == 18 # Position before target + + # Test deletion around UTF-32 characters + handler.delete(7, 2) # Delete " ๐Ÿš€ " + assert str(handler) == "Testing UTF-32 ๐ŸŽฏ" + + +def test_edge_cases(): + # Test empty string + handler = UTFHandler("", UTFEncoding.UTF16) + assert str(handler) == "" + + # Test string with only special characters + handler = UTFHandler("๐ŸŒŸโœจ๐Ÿ’ซ", UTFEncoding.UTF16) + assert str(handler) == "๐ŸŒŸโœจ๐Ÿ’ซ" + + # Test consecutive insertions + handler.insert(0, "<") + handler.insert(10, ">") + assert str(handler) == "<๐ŸŒŸโœจ๐Ÿ’ซ>" + + # Test deletion at boundaries + handler.delete(1, 1) # Delete first emoji + assert str(handler) == "<โœจ๐Ÿ’ซ>" + + +def test_position_tracking(): + text = "Mix of ASCII and ๆผขๅญ— with ๐ŸŽฎ" + handler = UTFHandler(text, UTFEncoding.UTF16) + + # Test position tracking before and after modifications + original_pos = handler.get_encoded_position(13) # Position before ๆผข + handler.insert(13, "[") + handler.insert(17, "]") + + # Verify position tracking is maintained + new_pos = handler.get_encoded_position(14) # Should account for inserted '[' + assert new_pos == original_pos + 1 + + expected = "Mix of ASCII [and] ๆผขๅญ— with ๐ŸŽฎ" + assert str(handler) == expected