From 2fa592eb6981018a2cfcca93c1ddca603efed07a Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Thu, 25 Apr 2024 13:17:52 +0300 Subject: [PATCH] tests: Add a fixture for uncommon filenames Add a pytest fixture that crafts a filename with Unicode characters that are not considered common for this use. By default, this fixture uses an invalid Unicode character as well, but we strip it in case of macOS (APFS) since filenames must be UTF-8 encoded. [1]: https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations --- tests/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/__init__.py b/tests/__init__.py index c7c7e47..70e7c21 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,3 +1,4 @@ +import platform import sys import zipfile from pathlib import Path @@ -117,6 +118,22 @@ def uncommon_text() -> str: return "\033[31;1;4m BaD TeΧt \u200d ❌ \033[0m" +@pytest.fixture +def uncommon_filename(uncommon_text: str) -> str: + """Craft a filename with Unicode characters that are considered not common. + + We reuse the same uncommon string as above, with a small exception for macOS. + Because the APFS filesystem in macOS accepts only UTF-8 encoded strings [1], we + cannot create a filename with invalid Unicode characters. So, in order to test the + rest of the corner cases, we replace U+DCF0 with an empty string. + + [1]: https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations + """ + if platform.system() == "Darwin": + uncommon_text = uncommon_text.replace("\udcf0", "") + return uncommon_text + ".pdf" + + @pytest.fixture def sanitized_text() -> str: """Return a sanitized version of the uncommon_text."""