From 98c5cb69777b3438e8e34465c6494a2906500daf Mon Sep 17 00:00:00 2001 From: Ven0m0 <82972344+Ven0m0@users.noreply.github.com> Date: Mon, 16 Mar 2026 22:21:37 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20[testing=20improvement]=20Add=20?= =?UTF-8?q?unit=20tests=20for=20sanitize=5Ffilename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a new test file `Cachyos/Scripts/WIP/emu/test_sanitize_filename.py` which provides unit tests for the `sanitize_filename` function in `cia_3ds_decryptor.py`. The tests cover: - Preservation of valid characters (a-z, A-Z, 0-9, -, _, ., and spaces) - Removal of invalid characters - Fallback behavior when all characters are invalid - Mixed case preservation - Empty string handling Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- .../Scripts/WIP/emu/test_sanitize_filename.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Cachyos/Scripts/WIP/emu/test_sanitize_filename.py diff --git a/Cachyos/Scripts/WIP/emu/test_sanitize_filename.py b/Cachyos/Scripts/WIP/emu/test_sanitize_filename.py new file mode 100644 index 00000000..f676f487 --- /dev/null +++ b/Cachyos/Scripts/WIP/emu/test_sanitize_filename.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +import importlib.util +import unittest +import sys +from pathlib import Path + +# Dynamically import cia_3ds_decryptor.py +file_path = Path(__file__).parent / "cia_3ds_decryptor.py" +spec = importlib.util.spec_from_file_location("cia_3ds_decryptor", str(file_path)) +if spec is None: + raise ImportError(f"Could not load {file_path}") +decryptor = importlib.util.module_from_spec(spec) +sys.modules["cia_3ds_decryptor"] = decryptor +spec.loader.exec_module(decryptor) + + +class TestSanitizeFilename(unittest.TestCase): + def test_preservation_of_valid_characters(self): + # a-z, A-Z, 0-9, -, _, ., and spaces + input_name = "test-FILE_123.3ds" + expected = "test-FILE_123.3ds" + self.assertEqual(decryptor.sanitize_filename(input_name), expected) + + def test_removal_of_invalid_characters(self): + # !@#$%^&*()+={}[]|\:;"'<>,/? should be removed + input_name = "test!@#$ %^&*()_+= file.cia" + # VALID_CHARS = frozenset("-_abcdefghijklmnopqrstuvwxyz1234567890. ") + # "test", " ", "_", " ", "file.cia" are valid + expected = "test _ file.cia" + self.assertEqual(decryptor.sanitize_filename(input_name), expected) + + def test_fallback_behavior(self): + # If all characters are removed, the original name is returned. + input_name = "!!!@@@###" + # All are invalid, so 'out' would be empty, returns original + expected = "!!!@@@###" + self.assertEqual(decryptor.sanitize_filename(input_name), expected) + + def test_mixed_case_preservation(self): + input_name = "MixedCaseFILENAME.3ds" + expected = "MixedCaseFILENAME.3ds" + self.assertEqual(decryptor.sanitize_filename(input_name), expected) + + def test_empty_string(self): + self.assertEqual(decryptor.sanitize_filename(""), "") + +if __name__ == '__main__': + unittest.main()