From b7adda411b834929c307e558bcc3d55171d530f7 Mon Sep 17 00:00:00 2001 From: Zeth Date: Fri, 16 Aug 2019 16:50:36 +0100 Subject: [PATCH 1/2] bpo-NN: Tests for ROT-13 codec (GH-NNNN) The Rot-13 codec is for educational use but does not have unit tests, dragging down test coverage. This adds a few very simple tests. --- Lib/test/test_codecs.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index b187ca650dc693..bc4eec88e9ea1c 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -3329,5 +3329,42 @@ def test_decode_unsupported_error_handler(self): self.assertEqual(str(cm.exception), 'unsupported error handler') +class Rot13Test(unittest.TestCase): + """Test the educational ROT-13 codec.""" + def test_encode(self): + ciphertext = codecs.encode("Caesar liked ciphers", 'rot-13') + self.assertEqual(ciphertext, 'Pnrfne yvxrq pvcuref') + + def test_decode(self): + plaintext = codecs.decode('Rg gh, Oehgr?', 'rot-13') + self.assertEqual(plaintext, 'Et tu, Brute?') + + def test_incremental_encode(self): + encoder = codecs.getincrementalencoder('rot-13')() + ciphertext = encoder.encode('ABBA nag Cheryl Baker') + self.assertEqual(ciphertext, 'NOON ant Purely Onxre') + + def test_incremental_decode(self): + decoder = codecs.getincrementaldecoder('rot-13')() + plaintext = decoder.decode('terra Ares envy tha') + self.assertEqual(plaintext, 'green Nerf rail gun') + + +class Rot13UtilTest(unittest.TestCase): + """Test the ROT-13 codec via rot13 function, + i.e. the user has done something like: + $ echo "Hello World" | python -m encodings.rot_13 + """ + def test_rot13_func(self): + infile = io.StringIO('Gb or, be abg gb or, gung vf gur dhrfgvba') + outfile = io.StringIO() + encodings.rot_13.rot13(infile, outfile) + outfile.seek(0) + plain_text = outfile.read() + self.assertEqual( + plain_text, + 'To be, or not to be, that is the question') + + if __name__ == "__main__": unittest.main() From f14618cea9f0586b5a9a4b86b509a4816c0399a8 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 16 Aug 2019 16:15:15 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Misc/NEWS.d/next/Tests/2019-08-16-16-15-14.bpo-37876.m3k1w3.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Tests/2019-08-16-16-15-14.bpo-37876.m3k1w3.rst diff --git a/Misc/NEWS.d/next/Tests/2019-08-16-16-15-14.bpo-37876.m3k1w3.rst b/Misc/NEWS.d/next/Tests/2019-08-16-16-15-14.bpo-37876.m3k1w3.rst new file mode 100644 index 00000000000000..45702fc6351032 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2019-08-16-16-15-14.bpo-37876.m3k1w3.rst @@ -0,0 +1 @@ +Add tests for ROT-13 codec. \ No newline at end of file