[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#733489: python-apt: Improve 'Dependency' and 'BaseDependency' to get target package versions that satisfy dependencies



On Sat, Jan 25, 2014 at 12:41:14PM +0100, michael wrote:
> Julian, did you see my reply on your comment?https://github.com/michael-schaller/python-apt/commit/ef6202e2f54dc2085e4d87a01aa2a66ff7c1a437
> 
> 
> I'm not sure if GitHub sent you a notificaction...
> 

Yes, but I'm happy with that part now, it seems more readable the
way you have it. I'm not that happy about the tests part and decided
to try my own way to simplify the test code. Looks slightly more
functional-style.

-- >8 --
>From 3e33aaa11c0062b6bf97601e3221a9858a533ad2 Mon Sep 17 00:00:00 2001
From: Julian Andres Klode <jak@debian.org>
Date: Sat, 25 Jan 2014 15:46:57 +0100
Subject: [PATCH] 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.
---
 tests/test_deps.py | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/tests/test_deps.py b/tests/test_deps.py
index 0035fa8..96bcd57 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()."""
-- 
1.8.5.2

-- 
Julian Andres Klode  - Debian Developer, Ubuntu Member

See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.

Please do not top-post if possible.


Reply to: