-
-
Notifications
You must be signed in to change notification settings - Fork 0
🧪 [testing improvement] Add tests for decryptor parser and sanitizer #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,61 @@ | ||||||||||||||||||||||||||||||||||||
| #!/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 TestParser(unittest.TestCase): | ||||||||||||||||||||||||||||||||||||
| def test_parse_ctrtool_output_full(self): | ||||||||||||||||||||||||||||||||||||
| text = """ | ||||||||||||||||||||||||||||||||||||
| Title id: 0004000000000100 | ||||||||||||||||||||||||||||||||||||
| TitleVersion: 10 | ||||||||||||||||||||||||||||||||||||
| Crypto Key: Secure | ||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||
| info = decryptor.parse_ctrtool_output(text) | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(info.title_id, "0004000000000100") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(info.title_version, "10") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(info.crypto_key, "Crypto Key: Secure") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def test_parse_ctrtool_output_partial(self): | ||||||||||||||||||||||||||||||||||||
|
Check notice on line 28 in Cachyos/Scripts/WIP/emu/test_decryptor_parser.py
|
||||||||||||||||||||||||||||||||||||
| text = "Title id: 0004000000000100" | ||||||||||||||||||||||||||||||||||||
| info = decryptor.parse_ctrtool_output(text) | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(info.title_id, "0004000000000100") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(info.title_version, "0") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(info.crypto_key, "") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def test_parse_ctrtool_output_empty(self): | ||||||||||||||||||||||||||||||||||||
| info = decryptor.parse_ctrtool_output("") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(info.title_id, "") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(info.title_version, "0") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(info.crypto_key, "") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def test_parse_twl_ctrtool_output_full(self): | ||||||||||||||||||||||||||||||||||||
|
Check notice on line 41 in Cachyos/Scripts/WIP/emu/test_decryptor_parser.py
|
||||||||||||||||||||||||||||||||||||
| text = """ | ||||||||||||||||||||||||||||||||||||
| TitleId: 0004800000000100 | ||||||||||||||||||||||||||||||||||||
| TitleVersion: 5 | ||||||||||||||||||||||||||||||||||||
| Encrypted: YES | ||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||
| info = decryptor.parse_twl_ctrtool_output(text) | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(info.title_id, "0004800000000100") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(info.title_version, "5") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(info.crypto_key, "YES") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def test_sanitize_filename(self): | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(decryptor.sanitize_filename("Game Name (USA)!?.cia"), "Game Name USA.cia") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(decryptor.sanitize_filename("valid_name-123.3ds"), "valid_name-123.3ds") | ||||||||||||||||||||||||||||||||||||
| # Test that it preserves case (if TRANSLATE_TABLE is correct) | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(decryptor.sanitize_filename("UPPERCASE.CIA"), "UPPERCASE.CIA") | ||||||||||||||||||||||||||||||||||||
| # If all characters are invalid, it returns the original string | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(decryptor.sanitize_filename("!!!"), "!!!") | ||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure the bug fix for
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if __name__ == '__main__': | ||||||||||||||||||||||||||||||||||||
| unittest.main() | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+61
|
||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dynamic import logic is duplicated in
test_decryptor_counters.py. To improve maintainability and reduce code duplication, consider refactoring this logic into a shared test helper function. For example, you could create atest_helper.pywith a function that handles the module loading, which both test files can then import and use.