jhbuild r1839 - in trunk: . tests



Author: fpeters
Date: Fri Jan 18 16:49:25 2008
New Revision: 1839
URL: http://svn.gnome.org/viewvc/jhbuild?rev=1839&view=rev

Log:
* tests/tests.py: started unit tests, with unit tests covering build
ordering.



Added:
   trunk/tests/
   trunk/tests/tests.py
Modified:
   trunk/ChangeLog

Added: trunk/tests/tests.py
==============================================================================
--- (empty file)
+++ trunk/tests/tests.py	Fri Jan 18 16:49:25 2008
@@ -0,0 +1,116 @@
+#! /usr/bin/env python
+
+import sys
+import os
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
+
+import unittest
+
+import jhbuild.moduleset
+from jhbuild.modtypes import Package
+from jhbuild.errors import DependencyCycleError, UsageError
+
+class ModuleOrderingTestCase(unittest.TestCase):
+    '''Module Ordering'''
+
+    def setUp(self):
+        self.moduleset = jhbuild.moduleset.ModuleSet()
+        self.moduleset.add(Package('foo'))
+        self.moduleset.add(Package('bar'))
+        self.moduleset.add(Package('baz'))
+        self.moduleset.add(Package('qux'))
+        self.moduleset.add(Package('quux'))
+        self.moduleset.add(Package('corge'))
+
+    def get_module_list(self, seed, skip=[]):
+        return [x.name for x in self.moduleset.get_module_list(seed, skip)]
+
+    def test_standalone_one(self):
+        '''A standalone module'''
+        self.assertEqual(self.get_module_list(['foo']), ['foo'])
+
+    def test_standalone_two(self):
+        '''Two standalone modules'''
+        self.assertEqual(self.get_module_list(['foo', 'bar']), ['foo', 'bar'])
+
+    def test_dependency_chain_straight(self):
+        '''A straight chain of dependencies'''
+        self.moduleset.modules['foo'].dependencies = ['bar']
+        self.moduleset.modules['bar'].dependencies = ['baz']
+        self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
+
+    def test_dependency_chain_straight_skip(self):
+        '''A straight chain of dependencies, with a module to skip'''
+        self.moduleset.modules['foo'].dependencies = ['bar']
+        self.moduleset.modules['bar'].dependencies = ['baz']
+        self.assertEqual(self.get_module_list(['foo'], ['bar']), ['baz', 'foo'])
+
+    def test_dependency_chain_bi(self):
+        '''A dividing chain of dependencies'''
+        self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
+        self.moduleset.modules['bar'].dependencies = ['baz']
+        self.moduleset.modules['qux'].dependencies = ['quux']
+        self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
+
+    def test_dependency_cycle(self):
+        '''A chain of dependencies with a cycle'''
+        self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
+        self.moduleset.modules['bar'].dependencies = ['baz']
+        self.moduleset.modules['qux'].dependencies = ['quux', 'foo']
+        self.assertRaises(DependencyCycleError, self.get_module_list, ['foo'])
+
+    def test_dependency_chain_missing_dependencies(self):
+        '''A chain of dependencies with a missing <dependencies> module'''
+        self.moduleset.modules['foo'].dependencies = ['bar', 'plop']
+        self.moduleset.modules['bar'].dependencies = ['baz']
+        self.assertRaises(UsageError, self.get_module_list, ['foo'])
+
+    def test_dependency_chain_missing_after(self):
+        '''A chain of dependencies with a missing <after> module'''
+        self.moduleset.modules['foo'].dependencies = ['bar']
+        self.moduleset.modules['foo'].after = ['plop']
+        self.moduleset.modules['bar'].dependencies = ['baz']
+        self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
+
+    def test_dependency_chain_missing_suggests(self):
+        '''A chain of dependencies with a missing <suggests> module'''
+        self.moduleset.modules['foo'].dependencies = ['bar']
+        self.moduleset.modules['foo'].suggests = ['plop']
+        self.moduleset.modules['bar'].dependencies = ['baz']
+        self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'foo'])
+
+    def test_dependency_chain_after(self):
+        '''A dividing chain of dependencies with an <after> module'''
+        self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
+        self.moduleset.modules['bar'].dependencies = ['baz']
+        self.moduleset.modules['baz'].after = ['qux']
+        self.moduleset.modules['qux'].dependencies = ['quux']
+        self.assertEqual(self.get_module_list(['foo']), ['quux', 'qux', 'baz', 'bar', 'foo'])
+
+    def test_dependency_chain_suggests(self):
+        '''A dividing chain of dependencies with an <suggests> module'''
+        self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
+        self.moduleset.modules['bar'].dependencies = ['baz']
+        self.moduleset.modules['baz'].suggests = ['qux']
+        self.moduleset.modules['qux'].dependencies = ['quux']
+        self.assertEqual(self.get_module_list(['foo']), ['quux', 'qux', 'baz', 'bar', 'foo'])
+
+    def test_dependency_cycle_after(self):
+        '''A chain of dependencies with a cycle caused by an <after> module'''
+        self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
+        self.moduleset.modules['bar'].dependencies = ['baz']
+        self.moduleset.modules['qux'].dependencies = ['quux']
+        self.moduleset.modules['qux'].after = ['foo']
+        self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
+
+    def test_dependency_cycle_suggests(self):
+        '''A chain of dependencies with a cycle caused by an <suggests> module'''
+        self.moduleset.modules['foo'].dependencies = ['bar', 'qux']
+        self.moduleset.modules['bar'].dependencies = ['baz']
+        self.moduleset.modules['qux'].dependencies = ['quux']
+        self.moduleset.modules['qux'].suggests = ['foo']
+        self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
+
+
+if __name__ == '__main__':
+    unittest.main()



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