From 619752ea94420e1c22fd37542ba36803cb5aeb91 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 7 Jan 2014 01:07:22 +0100 Subject: tests: Add back test_hashsums from old and update These are automatic tests and they still work, so it's pointless not to use them. --- tests/data/hashsums/hashsum_test.data | 1 + tests/data/hashsums/hashsum_test_with_zero.data | Bin 0 -> 7 bytes tests/old/hashsum_test.data | 1 - tests/old/hashsum_test_with_zero.data | Bin 7 -> 0 bytes tests/old/test_hashsums.py | 67 ----------------------- tests/test_hashsums.py | 70 ++++++++++++++++++++++++ 6 files changed, 71 insertions(+), 68 deletions(-) create mode 100644 tests/data/hashsums/hashsum_test.data create mode 100644 tests/data/hashsums/hashsum_test_with_zero.data delete mode 100644 tests/old/hashsum_test.data delete mode 100644 tests/old/hashsum_test_with_zero.data delete mode 100644 tests/old/test_hashsums.py create mode 100644 tests/test_hashsums.py (limited to 'tests') diff --git a/tests/data/hashsums/hashsum_test.data b/tests/data/hashsums/hashsum_test.data new file mode 100644 index 00000000..19102815 --- /dev/null +++ b/tests/data/hashsums/hashsum_test.data @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git a/tests/data/hashsums/hashsum_test_with_zero.data b/tests/data/hashsums/hashsum_test_with_zero.data new file mode 100644 index 00000000..2ec9a6df Binary files /dev/null and b/tests/data/hashsums/hashsum_test_with_zero.data differ diff --git a/tests/old/hashsum_test.data b/tests/old/hashsum_test.data deleted file mode 100644 index 19102815..00000000 --- a/tests/old/hashsum_test.data +++ /dev/null @@ -1 +0,0 @@ -foo \ No newline at end of file diff --git a/tests/old/hashsum_test_with_zero.data b/tests/old/hashsum_test_with_zero.data deleted file mode 100644 index 2ec9a6df..00000000 Binary files a/tests/old/hashsum_test_with_zero.data and /dev/null differ diff --git a/tests/old/test_hashsums.py b/tests/old/test_hashsums.py deleted file mode 100644 index 0cf6beb7..00000000 --- a/tests/old/test_hashsums.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/python - -import unittest -import apt_pkg - - -class testHashes(unittest.TestCase): - " test the hashsum functions against strings and files " - - def testMD5(self): - # simple - s = "foo" - s_md5 = "acbd18db4cc2f85cedef654fccc4a4d8" - res = apt_pkg.md5sum(s) - self.assert_(res == s_md5) - # file - res = apt_pkg.md5sum(open("hashsum_test.data")) - self.assert_(res == s_md5) - # with zero (\0) in the string - s = "foo\0bar" - s_md5 = "f6f5f8cd0cb63668898ba29025ae824e" - res = apt_pkg.md5sum(s) - self.assert_(res == s_md5) - # file - res = apt_pkg.md5sum(open("hashsum_test_with_zero.data")) - self.assert_(res == s_md5) - - def testSHA1(self): - # simple - s = "foo" - s_hash = "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33" - res = apt_pkg.sha1sum(s) - self.assert_(res == s_hash) - # file - res = apt_pkg.sha1sum(open("hashsum_test.data")) - self.assert_(res == s_hash) - # with zero (\0) in the string - s = "foo\0bar" - s_hash = "e2c300a39311a2dfcaff799528415cb74c19317f" - res = apt_pkg.sha1sum(s) - self.assert_(res == s_hash) - # file - res = apt_pkg.sha1sum(open("hashsum_test_with_zero.data")) - self.assert_(res == s_hash) - - def testSHA256(self): - # simple - s = "foo" - s_hash = \ - "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae" - res = apt_pkg.sha256sum(s) - self.assert_(res == s_hash) - # file - res = apt_pkg.sha256sum(open("hashsum_test.data")) - self.assert_(res == s_hash) - # with zero (\0) in the string - s = "foo\0bar" - s_hash = \ - "d6b681bfce7155d44721afb79c296ef4f0fa80a9dd6b43c5cf74dd0f64c85512" - res = apt_pkg.sha256sum(s) - self.assert_(res == s_hash) - # file - res = apt_pkg.sha256sum(open("hashsum_test_with_zero.data")) - self.assert_(res == s_hash) - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_hashsums.py b/tests/test_hashsums.py new file mode 100644 index 00000000..1819e343 --- /dev/null +++ b/tests/test_hashsums.py @@ -0,0 +1,70 @@ +#!/usr/bin/python + +import unittest +import apt_pkg + + +class testHashes(unittest.TestCase): + " test the hashsum functions against strings and files " + + DATA_PATH = "data/hashsums/hashsum_test.data" + DATA_WITH_ZERO_PATH = "data/hashsums/hashsum_test_with_zero.data" + + def testMD5(self): + # simple + s = b"foo" + s_md5 = "acbd18db4cc2f85cedef654fccc4a4d8" + res = apt_pkg.md5sum(s) + self.assertEqual(res, s_md5) + # file + with open(self.DATA_PATH) as fobj: + self.assertEqual(apt_pkg.md5sum(fobj), s_md5) + # with zero (\0) in the string + s = b"foo\0bar" + s_md5 = "f6f5f8cd0cb63668898ba29025ae824e" + res = apt_pkg.md5sum(s) + self.assertEqual(res, s_md5) + # file + with open(self.DATA_WITH_ZERO_PATH) as fobj: + self.assertEqual(apt_pkg.md5sum(fobj), s_md5) + + def testSHA1(self): + # simple + s = b"foo" + s_hash = "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33" + res = apt_pkg.sha1sum(s) + self.assertEqual(res, s_hash) + # file + with open(self.DATA_PATH) as fobj: + self.assertEqual(apt_pkg.sha1sum(fobj), s_hash) + # with zero (\0) in the string + s = b"foo\0bar" + s_hash = "e2c300a39311a2dfcaff799528415cb74c19317f" + res = apt_pkg.sha1sum(s) + self.assertEqual(res, s_hash) + # file + with open(self.DATA_WITH_ZERO_PATH) as fobj: + self.assertEqual(apt_pkg.sha1sum(fobj), s_hash) + + def testSHA256(self): + # simple + s = b"foo" + s_hash = \ + "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae" + res = apt_pkg.sha256sum(s) + self.assertEqual(res, s_hash) + # file + with open(self.DATA_PATH) as fobj: + self.assertEqual(apt_pkg.sha256sum(fobj), s_hash) + # with zero (\0) in the string + s = b"foo\0bar" + s_hash = \ + "d6b681bfce7155d44721afb79c296ef4f0fa80a9dd6b43c5cf74dd0f64c85512" + res = apt_pkg.sha256sum(s) + self.assertEqual(res, s_hash) + # file + with open(self.DATA_WITH_ZERO_PATH) as fobj: + self.assertEqual(apt_pkg.sha256sum(fobj), s_hash) + +if __name__ == "__main__": + unittest.main() -- cgit v1.2.3