summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-07-17 19:40:47 +0200
committerJulian Andres Klode <jak@debian.org>2009-07-17 19:40:47 +0200
commitcbd822c9dfe8cf18d828bd558290f15775b4d837 (patch)
treeb9ee1d702dd85a5dc2cbd9303e7f31ca6b8ffa52
parent9bd7c1dcf9942d6ce294aa5ac58d90d6c1aa9f51 (diff)
downloadpython-apt-cbd822c9dfe8cf18d828bd558290f15775b4d837.tar.gz
tests: First work on the new testsuite.
The module tests.test_all will run all available tests. Each test placed herein must be using unittest and provide at least 1 test case. It must be prefixed with test_.
-rw-r--r--tests/__init__.py1
-rw-r--r--tests/old/__init__.py13
-rw-r--r--tests/old/apt-test.py (renamed from tests/apt-test.py)0
-rw-r--r--tests/old/cache.py (renamed from tests/cache.py)0
-rw-r--r--tests/old/data/sources.list (renamed from tests/data/sources.list)0
-rw-r--r--tests/old/data/sources.list.testDistribution (renamed from tests/data/sources.list.testDistribution)0
-rw-r--r--tests/old/depcache.py (renamed from tests/depcache.py)0
-rw-r--r--tests/old/getcache_mem_corruption.py (renamed from tests/getcache_mem_corruption.py)0
-rw-r--r--tests/old/hashsum_test.data (renamed from tests/hashsum_test.data)0
-rw-r--r--tests/old/hashsum_test_with_zero.data (renamed from tests/hashsum_test_with_zero.data)bin7 -> 7 bytes
-rw-r--r--tests/old/lock.py (renamed from tests/lock.py)0
-rwxr-xr-xtests/old/memleak.py (renamed from tests/memleak.py)0
-rw-r--r--tests/old/pkgproblemresolver.py (renamed from tests/pkgproblemresolver.py)0
-rw-r--r--tests/old/pkgrecords.py (renamed from tests/pkgrecords.py)0
-rw-r--r--tests/old/pkgsrcrecords.py (renamed from tests/pkgsrcrecords.py)0
-rwxr-xr-xtests/old/refcount.py (renamed from tests/refcount.py)0
-rw-r--r--tests/old/test-data-ports/sources.list (renamed from tests/test-data-ports/sources.list)0
-rw-r--r--tests/old/test_aptsources.py (renamed from tests/test_aptsources.py)0
-rw-r--r--tests/old/test_aptsources_ports.py (renamed from tests/test_aptsources_ports.py)0
-rwxr-xr-xtests/old/test_debextract.py (renamed from tests/test_debextract.py)0
-rw-r--r--tests/old/test_extract_archive.py (renamed from tests/test_extract_archive.py)0
-rw-r--r--tests/old/test_hashsums.py (renamed from tests/test_hashsums.py)0
-rw-r--r--tests/test_all.py17
-rw-r--r--tests/test_hashes.py93
24 files changed, 124 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/tests/__init__.py
@@ -0,0 +1 @@
+
diff --git a/tests/old/__init__.py b/tests/old/__init__.py
new file mode 100644
index 00000000..afd0f074
--- /dev/null
+++ b/tests/old/__init__.py
@@ -0,0 +1,13 @@
+import os
+import unittest
+
+
+
+if __name__ == '__main__':
+ os.chdir(os.path.dirname(__file__))
+ print os.getcwd()
+
+ for path in os.listdir('.'):
+ if path.endswith('.py'):
+ exec 'from %s import *' % path[:-3]
+ unittest.main()
diff --git a/tests/apt-test.py b/tests/old/apt-test.py
index fac2ff43..fac2ff43 100644
--- a/tests/apt-test.py
+++ b/tests/old/apt-test.py
diff --git a/tests/cache.py b/tests/old/cache.py
index f0bf6761..f0bf6761 100644
--- a/tests/cache.py
+++ b/tests/old/cache.py
diff --git a/tests/data/sources.list b/tests/old/data/sources.list
index 5481d4f0..5481d4f0 100644
--- a/tests/data/sources.list
+++ b/tests/old/data/sources.list
diff --git a/tests/data/sources.list.testDistribution b/tests/old/data/sources.list.testDistribution
index 0f40e85a..0f40e85a 100644
--- a/tests/data/sources.list.testDistribution
+++ b/tests/old/data/sources.list.testDistribution
diff --git a/tests/depcache.py b/tests/old/depcache.py
index 0d59648e..0d59648e 100644
--- a/tests/depcache.py
+++ b/tests/old/depcache.py
diff --git a/tests/getcache_mem_corruption.py b/tests/old/getcache_mem_corruption.py
index c6e5ff80..c6e5ff80 100644
--- a/tests/getcache_mem_corruption.py
+++ b/tests/old/getcache_mem_corruption.py
diff --git a/tests/hashsum_test.data b/tests/old/hashsum_test.data
index 19102815..19102815 100644
--- a/tests/hashsum_test.data
+++ b/tests/old/hashsum_test.data
diff --git a/tests/hashsum_test_with_zero.data b/tests/old/hashsum_test_with_zero.data
index 2ec9a6df..2ec9a6df 100644
--- a/tests/hashsum_test_with_zero.data
+++ b/tests/old/hashsum_test_with_zero.data
Binary files differ
diff --git a/tests/lock.py b/tests/old/lock.py
index d45b3964..d45b3964 100644
--- a/tests/lock.py
+++ b/tests/old/lock.py
diff --git a/tests/memleak.py b/tests/old/memleak.py
index 5299f35f..5299f35f 100755
--- a/tests/memleak.py
+++ b/tests/old/memleak.py
diff --git a/tests/pkgproblemresolver.py b/tests/old/pkgproblemresolver.py
index 0d6d0611..0d6d0611 100644
--- a/tests/pkgproblemresolver.py
+++ b/tests/old/pkgproblemresolver.py
diff --git a/tests/pkgrecords.py b/tests/old/pkgrecords.py
index 2fe6ad20..2fe6ad20 100644
--- a/tests/pkgrecords.py
+++ b/tests/old/pkgrecords.py
diff --git a/tests/pkgsrcrecords.py b/tests/old/pkgsrcrecords.py
index 2ea9dd3a..2ea9dd3a 100644
--- a/tests/pkgsrcrecords.py
+++ b/tests/old/pkgsrcrecords.py
diff --git a/tests/refcount.py b/tests/old/refcount.py
index a29744ae..a29744ae 100755
--- a/tests/refcount.py
+++ b/tests/old/refcount.py
diff --git a/tests/test-data-ports/sources.list b/tests/old/test-data-ports/sources.list
index a6b2f6ed..a6b2f6ed 100644
--- a/tests/test-data-ports/sources.list
+++ b/tests/old/test-data-ports/sources.list
diff --git a/tests/test_aptsources.py b/tests/old/test_aptsources.py
index 3761f3ff..3761f3ff 100644
--- a/tests/test_aptsources.py
+++ b/tests/old/test_aptsources.py
diff --git a/tests/test_aptsources_ports.py b/tests/old/test_aptsources_ports.py
index 09d6e9d9..09d6e9d9 100644
--- a/tests/test_aptsources_ports.py
+++ b/tests/old/test_aptsources_ports.py
diff --git a/tests/test_debextract.py b/tests/old/test_debextract.py
index 4ba498ae..4ba498ae 100755
--- a/tests/test_debextract.py
+++ b/tests/old/test_debextract.py
diff --git a/tests/test_extract_archive.py b/tests/old/test_extract_archive.py
index ce202b06..ce202b06 100644
--- a/tests/test_extract_archive.py
+++ b/tests/old/test_extract_archive.py
diff --git a/tests/test_hashsums.py b/tests/old/test_hashsums.py
index 0cf6beb7..0cf6beb7 100644
--- a/tests/test_hashsums.py
+++ b/tests/old/test_hashsums.py
diff --git a/tests/test_all.py b/tests/test_all.py
new file mode 100644
index 00000000..ea74e09b
--- /dev/null
+++ b/tests/test_all.py
@@ -0,0 +1,17 @@
+#!/usr/bin/python
+# Copyright (C) 2009 Julian Andres Klode <jak@debian.org>
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+"""Run all available unit tests."""
+import os
+import unittest
+
+if __name__ == '__main__':
+ os.chdir(os.path.dirname(__file__))
+ for path in os.listdir('.'):
+ if path.endswith('.py') and os.path.isfile(path):
+ exec('from %s import *' % path[:-3])
+
+ unittest.main()
diff --git a/tests/test_hashes.py b/tests/test_hashes.py
new file mode 100644
index 00000000..24e25f9c
--- /dev/null
+++ b/tests/test_hashes.py
@@ -0,0 +1,93 @@
+#!/usr/bin/python
+#
+# Copyright (C) 2009 Julian Andres Klode <jak@debian.org>
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+"""Unit tests for verifying the correctness of hashsums in apt_pkg.
+
+Unit tests to verify the correctness of Hashes, HashString and the various
+functions like md5sum."""
+import unittest
+import hashlib
+
+import apt_pkg
+
+
+class TestHashes(unittest.TestCase):
+ """Test apt_pkg.Hashes() and the various apt_pkg.*sum() functions."""
+
+ def setUp(self):
+ """Prepare the tests, create reference values..."""
+ self.file = open(apt_pkg.__file__, "rb")
+ self.value = self.file.read()
+ self.hashes = apt_pkg.Hashes(self.value)
+ self.file.seek(0)
+ self.fhashes = apt_pkg.Hashes(self.file)
+ # Reference values.
+ self.md5 = hashlib.md5(self.value).hexdigest()
+ self.sha1 = hashlib.sha1(self.value).hexdigest()
+ self.sha256 = hashlib.sha256(self.value).hexdigest()
+ self.file.seek(0)
+
+ def tearDown(self):
+ """Cleanup, Close the file object used for the tests."""
+ self.file.close()
+
+ def test_md5sum(self):
+ """Test apt_pkg.md5sum()"""
+ self.assertEqual(apt_pkg.md5sum(self.value), self.md5)
+ self.assertEqual(apt_pkg.md5sum(self.file), self.md5)
+
+ def test_sha1sum(self):
+ """Test apt_pkg.sha1sum()"""
+ self.assertEqual(apt_pkg.sha1sum(self.value), self.sha1)
+ self.assertEqual(apt_pkg.sha1sum(self.file), self.sha1)
+
+ def test_sha256sum(self):
+ """Test apt_pkg.sha256sum()"""
+ self.assertEqual(apt_pkg.sha256sum(self.value), self.sha256)
+ self.assertEqual(apt_pkg.sha256sum(self.file), self.sha256)
+
+ def test_bytes(self):
+ """Test apt_pkg.Hashes(bytes)"""
+ self.assertEqual(self.hashes.md5, self.md5)
+ self.assertEqual(self.hashes.sha1, self.sha1)
+ self.assertEqual(self.hashes.sha256, self.sha256)
+
+ def test_file(self):
+ """Test apt_pkg.Hashes(file)."""
+ self.assertEqual(self.hashes.md5, self.fhashes.md5)
+ self.assertEqual(self.hashes.sha1, self.fhashes.sha1)
+ self.assertEqual(self.hashes.sha256, self.fhashes.sha256)
+
+
+class TestHashString(unittest.TestCase):
+ """Test apt_pkg.HashString()."""
+
+ def setUp(self):
+ """Prepare the test by reading the file."""
+ self.hashes = apt_pkg.Hashes(open(apt_pkg.__file__))
+ self.md5 = apt_pkg.HashString("MD5Sum", self.hashes.md5)
+ self.sha1 = apt_pkg.HashString("SHA1", self.hashes.sha1)
+ self.sha256 = apt_pkg.HashString("SHA256", self.hashes.sha256)
+
+ def test_md5(self):
+ """Test apt_pkg.HashString().md5"""
+ self.assertEqual("MD5Sum:%s" % self.hashes.md5, str(self.md5))
+ self.assertTrue(self.md5.verify_file(apt_pkg.__file__))
+
+ def test_sha1(self):
+ """Test apt_pkg.HashString().sha1"""
+ self.assertEqual("SHA1:%s" % self.hashes.sha1, str(self.sha1))
+ self.assertTrue(self.sha1.verify_file(apt_pkg.__file__))
+
+ def test_sha256(self):
+ """Test apt_pkg.HashString().sha256"""
+ self.assertEqual("SHA256:%s" % self.hashes.sha256, str(self.sha256))
+ self.assertTrue(self.sha256.verify_file(apt_pkg.__file__))
+
+
+if __name__ == "__main__":
+ unittest.main()