"""Tests for the md5 module implemented at interp-level in pypy/module/_md5."""importpy,sysfrompypy.conftestimportgettestobjspaceclassAppTestMD5(object):defsetup_class(cls):""" Create a space with the md5 module and import it for use by the tests. """cls.space=gettestobjspace(usemodules=['_md5'])cls.w_md5=cls.space.appexec([],"""(): import _md5 return _md5 """)deftest_digest_size(self):""" md5.digest_size should be 16. """assertself.md5.md5().digest_size==16deftest_MD5Type(self):""" Test the construction of an md5 object. """md5=self.md5d=md5.md5()deftest_md5object(self):""" Feed example strings into a md5 object and check the digest and hexdigest. """md5=self.md5importbinasciicases=((b"","d41d8cd98f00b204e9800998ecf8427e"),(b"a","0cc175b9c0f1b6a831c399e269772661"),(b"abc","900150983cd24fb0d6963f7d28e17f72"),(b"message digest","f96b697d7cb7938d525a2f31aaf161d0"),(b"abcdefghijklmnopqrstuvwxyz","c3fcd3d76192e4007dfb496cca67e13b"),(b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789","d174ab98d277d9f5a5611c2c9f419d9f"),(b"1234567890"*8,"57edf4a22be3c955ac49da2e2107b67a"),)forinput,expectedincases:d=md5.md5(input)assertd.hexdigest()==expectedassertd.digest()==binascii.unhexlify(expected.encode('ascii'))deftest_copy(self):""" Test the copy() method. """md5=self.md5d1=md5.md5()d1.update(b"abcde")d2=d1.copy()d2.update(b"fgh")d1.update(b"jkl")assertd1.hexdigest()=='e570e7110ecef72fcb772a9c05d03373'assertd2.hexdigest()=='e8dc4081b13434b45189a720b77b6818'deftest_buffer(self):""" Test passing a buffer object. """md5=self.md5d1=md5.md5(buffer(b"abcde"))d1.update(buffer(b"jkl"))assertd1.hexdigest()=='e570e7110ecef72fcb772a9c05d03373'deftest_unicode(self):""" Test passing unicode strings. """md5=self.md5raises(TypeError,md5.md5,"abcde")d1=md5.md5()raises(TypeError,d1.update,"jkl")