def test_current(self): """Test deciding if an object is up-to-date Simple comparison of different "signature" values. """ obj = my_obj('111') assert not current(obj.get_signature(), signature(my_obj('110'))) assert current(obj.get_signature(), signature(my_obj('111'))) assert not current(obj.get_signature(), signature(my_obj('112')))
def test_signature(self): """Test generating a signature""" o1 = my_obj(value = '111') s = signature(o1) assert '698d51a19d8a121ce581499d7b701668' == s, s o2 = my_obj(value = 222) s = signature(o2) assert 'bcbe3365e6ac95ea2c0343a2395834dd' == s, s try: signature('string') except AttributeError, e: assert string.find(str(e), "unable to fetch contents") == 0, str(e)
def test_signature(self): """Test generating a signature""" o1 = my_obj(value='111') s = signature(o1) assert '698d51a19d8a121ce581499d7b701668' == s, s o2 = my_obj(value=222) s = signature(o2) assert 'bcbe3365e6ac95ea2c0343a2395834dd' == s, s try: signature('string') except AttributeError, e: assert string.find(str(e), "unable to fetch contents") == 0, str(e)
def get_signature(self): if not hasattr(self, "sig"): self.sig = signature(self) return self.sig
try: signature('string') except AttributeError, e: assert string.find(str(e), "unable to fetch contents") == 0, str(e) else: raise AttributeError, "unexpected get_contents() attribute" # Make sure we don't eat AttributeErrors raised internally # by the get_contents() method (or anything it calls). caught = None try: class xxx: def get_contents(self): raise AttributeError, "internal AttributeError" signature(xxx()) except AttributeError, e: assert str(e) == "internal AttributeError", e caught = 1 assert caught, "did not catch expected AttributeError" def test_to_string(self): assert '698d51a19d8a121ce581499d7b701668' == to_string('698d51a19d8a121ce581499d7b701668') def test_from_string(self): assert '698d51a19d8a121ce581499d7b701668' == from_string('698d51a19d8a121ce581499d7b701668') if __name__ == "__main__": suite = unittest.makeSuite(MD5TestCase, 'test_') if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1)
signature('string') except AttributeError, e: assert string.find(str(e), "unable to fetch contents") == 0, str(e) else: raise AttributeError, "unexpected get_contents() attribute" # Make sure we don't eat AttributeErrors raised internally # by the get_contents() method (or anything it calls). caught = None try: class xxx: def get_contents(self): raise AttributeError, "internal AttributeError" signature(xxx()) except AttributeError, e: assert str(e) == "internal AttributeError", e caught = 1 assert caught, "did not catch expected AttributeError" def test_to_string(self): assert '698d51a19d8a121ce581499d7b701668' == to_string( '698d51a19d8a121ce581499d7b701668') def test_from_string(self): assert '698d51a19d8a121ce581499d7b701668' == from_string( '698d51a19d8a121ce581499d7b701668') if __name__ == "__main__":