From ddcba1117722095bfb5f4f1c98273c54e747eea9 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 26 Feb 2013 19:06:27 -0600 Subject: Fix ALPM unittest to run when ALPM isn't present This gets some proper unittest skip decorator action now in addition to adding more testing around everything. Signed-off-by: Dan McGee --- packages/tests.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/tests.py b/packages/tests.py index 3a46086..bbe9f00 100644 --- a/packages/tests.py +++ b/packages/tests.py @@ -2,17 +2,27 @@ import unittest from .alpm import AlpmAPI + +alpm = AlpmAPI() + + class AlpmTestCase(unittest.TestCase): + + @unittest.skipUnless(alpm.available, "ALPM is unavailable") def test_version(self): - alpm = AlpmAPI() version = alpm.version() self.assertIsNotNone(version) version = version.split('.') # version is a 3-tuple, e.g., '7.0.2' self.assertEqual(3, len(version)) + @unittest.skipUnless(alpm.available, "ALPM is unavailable") + def test_vercmp(self): + self.assertEqual(0, alpm.vercmp("1.0", "1.0")) + self.assertEqual(1, alpm.vercmp("1.1", "1.0")) + + @unittest.skipUnless(alpm.available, "ALPM is unavailable") def test_compare_versions(self): - alpm = AlpmAPI() self.assertTrue(alpm.compare_versions("1.0", "<=", "2.0")) self.assertTrue(alpm.compare_versions("1.0", "<", "2.0")) self.assertFalse(alpm.compare_versions("1.0", ">=", "2.0")) @@ -24,4 +34,13 @@ class AlpmTestCase(unittest.TestCase): self.assertTrue(alpm.compare_versions("1.0", "=", "1.0-1")) self.assertFalse(alpm.compare_versions("1.0", "!=", "1.0")) + def test_behavior_when_unavailable(self): + mock_alpm = AlpmAPI() + mock_alpm.available = False + + self.assertIsNone(mock_alpm.version()) + self.assertIsNone(mock_alpm.vercmp("1.0", "1.0")) + self.assertIsNone(mock_alpm.compare_versions("1.0", "=", "1.0")) + + # vim: set ts=4 sw=4 et: -- cgit v1.2.3-24-g4f1b