@@ -3343,5 +3343,42 @@ def test_decode_unsupported_error_handler(self):
3343
3343
self .assertEqual (str (cm .exception ), 'unsupported error handler' )
3344
3344
3345
3345
3346
+ class Rot13Test (unittest .TestCase ):
3347
+ """Test the educational ROT-13 codec."""
3348
+ def test_encode (self ):
3349
+ ciphertext = codecs .encode ("Caesar liked ciphers" , 'rot-13' )
3350
+ self .assertEqual (ciphertext , 'Pnrfne yvxrq pvcuref' )
3351
+
3352
+ def test_decode (self ):
3353
+ plaintext = codecs .decode ('Rg gh, Oehgr?' , 'rot-13' )
3354
+ self .assertEqual (plaintext , 'Et tu, Brute?' )
3355
+
3356
+ def test_incremental_encode (self ):
3357
+ encoder = codecs .getincrementalencoder ('rot-13' )()
3358
+ ciphertext = encoder .encode ('ABBA nag Cheryl Baker' )
3359
+ self .assertEqual (ciphertext , 'NOON ant Purely Onxre' )
3360
+
3361
+ def test_incremental_decode (self ):
3362
+ decoder = codecs .getincrementaldecoder ('rot-13' )()
3363
+ plaintext = decoder .decode ('terra Ares envy tha' )
3364
+ self .assertEqual (plaintext , 'green Nerf rail gun' )
3365
+
3366
+
3367
+ class Rot13UtilTest (unittest .TestCase ):
3368
+ """Test the ROT-13 codec via rot13 function,
3369
+ i.e. the user has done something like:
3370
+ $ echo "Hello World" | python -m encodings.rot_13
3371
+ """
3372
+ def test_rot13_func (self ):
3373
+ infile = io .StringIO ('Gb or, be abg gb or, gung vf gur dhrfgvba' )
3374
+ outfile = io .StringIO ()
3375
+ encodings .rot_13 .rot13 (infile , outfile )
3376
+ outfile .seek (0 )
3377
+ plain_text = outfile .read ()
3378
+ self .assertEqual (
3379
+ plain_text ,
3380
+ 'To be, or not to be, that is the question' )
3381
+
3382
+
3346
3383
if __name__ == "__main__" :
3347
3384
unittest .main ()
0 commit comments