diff --git a/check_kernel b/check_kernel index 04abd18..1556b1d 100755 --- a/check_kernel +++ b/check_kernel @@ -39,12 +39,17 @@ class Version(object): return str_ > str_other for self_c, other_c in zip(self.components(), other.components()): - if num_gt(self_c, other_c): - return True + if self_c == other_c: + continue + else: + return num_gt(self_c, other_c) return False # Note: not using functools.total_ordering to support Python 2.6 + def __lt__(self, other): + return not (self == other) and not (self > other) + def proc_version(): v = open('/proc/version', 'r') diff --git a/check_kernel_test.py b/check_kernel_test.py index e8cfd0c..83c7c9f 100644 --- a/check_kernel_test.py +++ b/check_kernel_test.py @@ -58,6 +58,18 @@ class VersionTestCase(unittest.TestCase): self.assertGreater(Version('3.12-12'), Version('3.12-2')) self.assertGreater(Version('2.6.32-5foo1'), Version('2.6.32-5foo0')) + self.assertGreater(Version('3.16.7-ckt9-3~deb8u1'), + Version('3.14.15-2')) + self.assertLess(Version('3.14.15-2'), + Version('3.16.7-ckt9-3~deb8u1')) + + def testSorting(self): + l = [Version('3.16.5-1'), Version('3.2.60-1+deb7u3'), + Version('3.16.3-2'), Version('3.16.7-ckt9-3~deb8u1'), + Version('3.14.15-2')] + self.assertEqual(sorted(l)[0], Version('3.2.60-1+deb7u3')) + self.assertEqual(sorted(l)[-1], Version('3.16.7-ckt9-3~deb8u1')) + if __name__ == '__main__': unittest.main()