Author: dsommers Date: 2010-05-20 12:31:09 +0000 (Thu, 20 May 2010) New Revision: 512
Modified: trunk/unittests/unittest.py trunk/v7/hash.py Log: Added unit-test for v7/hash.py
Also rearranged the code a little bit. Tested on Fedora 13 and RHEL4.6(!)
Signed-off-by: David Sommerseth davids@redhat.com
Modified: trunk/unittests/unittest.py =================================================================== --- trunk/unittests/unittest.py 2010-05-20 09:45:54 UTC (rev 511) +++ trunk/unittests/unittest.py 2010-05-20 12:31:09 UTC (rev 512) @@ -120,6 +120,7 @@ tests.LoadModules((('v7','redhatrelease'), ('v7','command'), ('v7','hal'), + ('v7','hash'), ('tests/info', 'info') )) # Run all tests
Modified: trunk/v7/hash.py =================================================================== --- trunk/v7/hash.py 2010-05-20 09:45:54 UTC (rev 511) +++ trunk/v7/hash.py 2010-05-20 12:31:09 UTC (rev 512) @@ -16,28 +16,35 @@ # The Report object packages and/or presents test results in text, rpm, or html form. #
+import sys + hashModule = None try: - import hashlib - hashModule = hashlib + hashModule = __import__('hashlib') except: - pass - -if not hashModule: try: - import md5 - hashModule = md5 + hashModule = __import__('md5') except: print "Error: could not find hash library"
-if __name__ == "__main__": + +def unit_test(): print hashModule content = "Boo" m=hashModule.md5() m.update(content) - print content - + digest = m.hexdigest()
+ print "Digest test of '%s': %s ..." % (content, digest), + if digest == '2e4d1b829d740c57ff602b7d3d8658a5': + print "PASS" + return 0 + else: + print "FAILED" + return 1 + +if __name__ == "__main__": + sys.exit(unit_test())
v7-commits@lists.stg.fedorahosted.org