Added test case based on recommended test cases from RFC 4648 (GH-27747)

This commit is contained in:
andrei kulakov 2021-08-13 06:50:37 -04:00 committed by GitHub
parent a2ce538e16
commit 230403a6a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 0 deletions

View File

@ -714,6 +714,45 @@ class BaseXYTestCase(unittest.TestCase):
def test_ErrorHeritage(self):
self.assertTrue(issubclass(binascii.Error, ValueError))
def test_RFC4648_test_cases(self):
# test cases from RFC 4648 section 10
b64encode = base64.b64encode
b32hexencode = base64.b32hexencode
b32encode = base64.b32encode
b16encode = base64.b16encode
self.assertEqual(b64encode(b""), b"")
self.assertEqual(b64encode(b"f"), b"Zg==")
self.assertEqual(b64encode(b"fo"), b"Zm8=")
self.assertEqual(b64encode(b"foo"), b"Zm9v")
self.assertEqual(b64encode(b"foob"), b"Zm9vYg==")
self.assertEqual(b64encode(b"fooba"), b"Zm9vYmE=")
self.assertEqual(b64encode(b"foobar"), b"Zm9vYmFy")
self.assertEqual(b32encode(b""), b"")
self.assertEqual(b32encode(b"f"), b"MY======")
self.assertEqual(b32encode(b"fo"), b"MZXQ====")
self.assertEqual(b32encode(b"foo"), b"MZXW6===")
self.assertEqual(b32encode(b"foob"), b"MZXW6YQ=")
self.assertEqual(b32encode(b"fooba"), b"MZXW6YTB")
self.assertEqual(b32encode(b"foobar"), b"MZXW6YTBOI======")
self.assertEqual(b32hexencode(b""), b"")
self.assertEqual(b32hexencode(b"f"), b"CO======")
self.assertEqual(b32hexencode(b"fo"), b"CPNG====")
self.assertEqual(b32hexencode(b"foo"), b"CPNMU===")
self.assertEqual(b32hexencode(b"foob"), b"CPNMUOG=")
self.assertEqual(b32hexencode(b"fooba"), b"CPNMUOJ1")
self.assertEqual(b32hexencode(b"foobar"), b"CPNMUOJ1E8======")
self.assertEqual(b16encode(b""), b"")
self.assertEqual(b16encode(b"f"), b"66")
self.assertEqual(b16encode(b"fo"), b"666F")
self.assertEqual(b16encode(b"foo"), b"666F6F")
self.assertEqual(b16encode(b"foob"), b"666F6F62")
self.assertEqual(b16encode(b"fooba"), b"666F6F6261")
self.assertEqual(b16encode(b"foobar"), b"666F6F626172")
class TestMain(unittest.TestCase):
def tearDown(self):