diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index 37ac57063c3539..5a8dcaf24f5504 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -4338,5 +4338,30 @@ def test_cache_bounded(self): self.assertLessEqual(len(encodings._cache), encodings._MAXCACHE) +@support.requires_subprocess() +class Rot13CommandLineTest(unittest.TestCase): + """Tests for the encodings.rot_13 command-line interface.""" + + def run_rot13(self, input_data): + from test.support.script_helper import spawn_python + with spawn_python('-m', 'encodings.rot_13') as proc: + out, err = proc.communicate(input_data.encode()) + return out.decode() + + def test_stdin_to_stdout(self): + result = self.run_rot13('Hello World') + self.assertEqual(result, 'Uryyb Jbeyq') + + def test_rot13_is_own_inverse(self): + plaintext = 'To be, or not to be, that is the question' + encoded = self.run_rot13(plaintext) + decoded = self.run_rot13(encoded) + self.assertEqual(decoded, plaintext) + + def test_non_alpha_unchanged(self): + result = self.run_rot13('Hello, World! 123') + self.assertEqual(result, 'Uryyb, Jbeyq! 123') + + if __name__ == "__main__": unittest.main() diff --git a/Misc/NEWS.d/next/Tests/2026-10-13-00-00-00.gh-issue-131178.mlMLJXT.rst b/Misc/NEWS.d/next/Tests/2026-10-13-00-00-00.gh-issue-131178.mlMLJXT.rst new file mode 100644 index 00000000000000..7dc2c3c01efdba --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2026-10-13-00-00-00.gh-issue-131178.mlMLJXT.rst @@ -0,0 +1 @@ +Add tests for ``encodings.rot_13`` command-line interface.