Skip to content

Commit f4bea74

Browse files
gh-131178: Add tests for encodings.rot_13 command-line interface
Add `Rot13CommandLineTest` class to `Lib/test/test_codecs.py` with subprocess-based tests for `python -m encodings.rot_13`.
1 parent 9c15cc9 commit f4bea74

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎Lib/test/test_codecs.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4338,5 +4338,30 @@ def test_cache_bounded(self):
43384338
self.assertLessEqual(len(encodings._cache), encodings._MAXCACHE)
43394339

43404340

4341+
@support.requires_subprocess()
4342+
class Rot13CommandLineTest(unittest.TestCase):
4343+
"""Tests for the encodings.rot_13 command-line interface."""
4344+
4345+
def run_rot13(self, input_data):
4346+
from test.support.script_helper import spawn_python
4347+
with spawn_python('-m', 'encodings.rot_13') as proc:
4348+
out, err = proc.communicate(input_data.encode())
4349+
return out.decode()
4350+
4351+
def test_stdin_to_stdout(self):
4352+
result = self.run_rot13('Hello World')
4353+
self.assertEqual(result, 'Uryyb Jbeyq')
4354+
4355+
def test_rot13_is_own_inverse(self):
4356+
plaintext = 'To be, or not to be, that is the question'
4357+
encoded = self.run_rot13(plaintext)
4358+
decoded = self.run_rot13(encoded)
4359+
self.assertEqual(decoded, plaintext)
4360+
4361+
def test_non_alpha_unchanged(self):
4362+
result = self.run_rot13('Hello, World! 123')
4363+
self.assertEqual(result, 'Uryyb, Jbeyq! 123')
4364+
4365+
43414366
if __name__ == "__main__":
43424367
unittest.main()

0 commit comments

Comments
 (0)