summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2014-01-25 15:46:57 +0100
committerJulian Andres Klode <jak@debian.org>2014-01-25 15:46:57 +0100
commit3e33aaa11c0062b6bf97601e3221a9858a533ad2 (patch)
treef9dc0a29c5c5cdeadcf90fc7057b6bfc0dface8e
parentcf0b0c05ee4d228363f8331c30f993b8ce5c569b (diff)
downloadpython-apt-3e33aaa11c0062b6bf97601e3221a9858a533ad2.tar.gz
tests/test_deps.py: test_dstr cleanup and fixes
Simplify the code by not stating all test cases in the code, but using a loop. Also adds more tests this way.
-rw-r--r--tests/test_deps.py35
1 files changed, 13 insertions, 22 deletions
diff --git a/tests/test_deps.py b/tests/test_deps.py
index 0035fa81..96bcd57b 100644
--- a/tests/test_deps.py
+++ b/tests/test_deps.py
@@ -6,6 +6,7 @@
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.
"""Unit tests for verifying the correctness of check_dep, etc in apt_pkg."""
+import itertools
import unittest
import apt_pkg
@@ -114,28 +115,18 @@ class TestDependencies(unittest.TestCase):
def test_dstr(self):
"""Test apt.package.BaseDependency.__dstr"""
dstr = apt.package.BaseDependency._BaseDependency__dstr
- self.assertEqual(dstr("<"), "<<")
- self.assertEqual(dstr("<"), "<")
- self.assertEqual("<<", dstr("<"))
- self.assertEqual("<", dstr("<"))
- self.assertEqual(dstr(">"), ">>")
- self.assertEqual(dstr(">"), ">")
- self.assertEqual(">>", dstr(">"))
- self.assertEqual(">", dstr(">"))
- self.assertNotEqual(dstr(">"), "<")
- self.assertNotEqual(dstr(">"), "<=")
- self.assertNotEqual(dstr(">"), "<<")
- self.assertNotEqual(dstr(">"), "!=")
- self.assertNotEqual(dstr(">"), "=")
- self.assertNotEqual(dstr(">"), "<")
- self.assertNotEqual(dstr(">"), "<=")
- self.assertNotEqual(dstr(">"), "<<")
- self.assertNotEqual(dstr(">"), "!=")
- self.assertNotEqual(dstr(">"), "=")
- self.assertFalse(dstr("<") != "<")
- self.assertFalse(dstr("<") != "<<")
- self.assertFalse(dstr(">") != ">")
- self.assertFalse(dstr(">") != ">>")
+ equal = {"<": {"<<", "<"},
+ "=": {"==", "="},
+ ">": {">>", ">"}}
+ operators = ["<<", "<", "<=", "!=", "=", "==", ">=", ">", ">>"]
+
+ for a, b in itertools.product(equal.keys(), operators):
+ if b in equal[a]:
+ self.assertEqual(dstr(a), b)
+ self.assertEqual(b, dstr(a))
+ else:
+ self.assertNotEqual(dstr(a), b)
+ self.assertNotEqual(b, dstr(a))
def testParseDepends(self):
"""dependencies: Test apt_pkg.ParseDepends()."""