From 63b12abbdf242fa3a8346fe896e870bb99b302de Mon Sep 17 00:00:00 2001 From: Alex Pyrgiotis Date: Tue, 30 Apr 2024 13:52:00 +0300 Subject: [PATCH] tests: Fix text sanitization tests on Windows Fix a failing test case on Windows, due to a character that cannot exist in a filename. --- tests/__init__.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 8648c63..4985667 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -123,15 +123,23 @@ def uncommon_text() -> str: 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. + We reuse the same uncommon string as above, with a small exception for macOS and + Windows. + + Because the NTFS filesystem in Windows and APFS filesystem in macOS accept 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. + + Windows has the extra restriction that it cannot have escape characters in + filenames, so we replace the ASCII Escape character (\033 / U+001B) as well. [1]: https://en.wikipedia.org/wiki/Filename#Comparison_of_filename_limitations """ if platform.system() == "Darwin": uncommon_text = uncommon_text.replace("\udcf0", "") + elif platform.system() == "Windows": + uncommon_text = uncommon_text.replace("\udcf0", "").replace("\033", "") return uncommon_text + ".pdf"