jhbuild r1853 - in trunk: . tests



Author: fpeters
Date: Sat Jan 19 14:47:30 2008
New Revision: 1853
URL: http://svn.gnome.org/viewvc/jhbuild?rev=1853&view=rev

Log:
* tests/mock.py, tests/tests.py: new unit tests covering a bit of build
policy and autotools module type adherence to config options.



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

Added: trunk/tests/mock.py
==============================================================================
--- (empty file)
+++ trunk/tests/mock.py	Sat Jan 19 14:47:30 2008
@@ -0,0 +1,80 @@
+# jhbuild - a build script for GNOME 1.x and 2.x
+# Copyright (C) 2001-2006  James Henstridge
+# Copyright (C) 2007-2008  Frederic Peters
+#
+#   mock.py: mock objects for unit testing
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+
+import jhbuild.frontends.buildscript
+import jhbuild.versioncontrol
+
+class Config:
+    buildroot = '/tmp/'
+    builddir_pattern = '%s'
+    force_policy = False
+    build_policy = 'all'
+    use_lib64 = False
+
+    nonetwork = False
+    nobuild = False
+    makeclean = False
+    makecheck = False
+    makedist = False
+    makedistcheck = False
+
+    prefix = '/tmp/'
+
+class PackageDB:
+    def __init__(self, uptodate = False):
+        self.uptodate = uptodate
+
+    def check(self, package, version=None):
+        return self.uptodate
+
+    def add(self, package, version):
+        pass
+
+class BuildScript(jhbuild.frontends.buildscript.BuildScript):
+    def __init__(self, config, module_list):
+        self.config = config
+        self.modulelist = module_list
+        self.packagedb = PackageDB()
+        self.actions = []
+    
+    def set_action(self, action, module, module_num=-1, action_target=None):
+        self.actions.append(action)
+
+    def execute(self, command, hint=None, cwd=None, extra_env=None):
+        pass
+
+    def message(self, msg, module_num = -1):
+        pass
+
+class Branch(jhbuild.versioncontrol.Branch):
+    def __init__(self):
+        pass
+
+    def srcdir(self):
+        return '/tmp/'
+    srcdir = property(srcdir)
+
+    def checkout(self, buildscript):
+        pass
+
+    def tree_id(self):
+        return 'foo'

Modified: trunk/tests/tests.py
==============================================================================
--- trunk/tests/tests.py	(original)
+++ trunk/tests/tests.py	Sat Jan 19 14:47:30 2008
@@ -1,4 +1,24 @@
 #! /usr/bin/env python
+# jhbuild - a build script for GNOME 1.x and 2.x
+# Copyright (C) 2001-2006  James Henstridge
+# Copyright (C) 2007-2008  Frederic Peters
+#
+#   tests.py: unit tests
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
 
 import sys
 import os
@@ -10,6 +30,8 @@
 from jhbuild.modtypes import Package
 from jhbuild.errors import DependencyCycleError, UsageError
 
+import mock
+
 class ModuleOrderingTestCase(unittest.TestCase):
     '''Module Ordering'''
 
@@ -112,5 +134,69 @@
         self.assertEqual(self.get_module_list(['foo']), ['baz', 'bar', 'quux', 'qux', 'foo'])
 
 
+class ModTypeTestCase(unittest.TestCase):
+    def setUp(self):
+        self.config = mock.Config()
+        self.branch = mock.Branch()
+        self.branch.config = self.config
+
+    def build(self, packagedb_params = {}, **kwargs):
+        for k in kwargs:
+            setattr(self.config, k, kwargs[k])
+        buildscript = mock.BuildScript(self.config, [self.module])
+        buildscript.packagedb = mock.PackageDB(**packagedb_params)
+        buildscript.build()
+        return buildscript.actions
+
+
+class AutotoolsModTypeTestCase(ModTypeTestCase):
+    def setUp(self):
+        ModTypeTestCase.setUp(self)
+        from jhbuild.modtypes.autotools import AutogenModule
+        self.module = AutogenModule('foo', self.branch)
+
+    def test_build(self):
+        '''Building a autotools module'''
+        self.assertEqual(self.build(),
+                ['Checking out', 'Configuring', 'Building', 'Installing'])
+
+    def test_build_no_network(self):
+        '''Building a autotools module, without network'''
+        self.assertEqual(self.build(nonetwork = True),
+                ['Configuring', 'Building', 'Installing'])
+
+    def test_update(self):
+        '''Updating a autotools module'''
+        self.assertEqual(self.build(nobuild = True), ['Checking out'])
+
+    def test_build_check(self):
+        '''Building a autotools module, with checks'''
+        self.assertEqual(self.build(makecheck = True),
+                ['Checking out', 'Configuring', 'Building', 'Checking', 'Installing'])
+
+    def test_build_clean_and_check(self):
+        '''Building a autotools module, with cleaning and checks'''
+        self.assertEqual(self.build(makecheck = True, makeclean = True),
+                ['Checking out', 'Configuring', 'Cleaning', 'Building', 'Checking', 'Installing'])
+
+
+class BuildPolicyTestCase(ModTypeTestCase):
+    def setUp(self):
+        ModTypeTestCase.setUp(self)
+        from jhbuild.modtypes.autotools import AutogenModule
+        self.module = AutogenModule('foo', self.branch)
+
+    def test_policy_all(self):
+        '''Building an uptodate module with build policy set to "all"'''
+        self.config.build_policy = 'all'
+        self.assertEqual(self.build(packagedb_params = {'uptodate': True}),
+                ['Checking out', 'Configuring', 'Building', 'Installing'])
+
+    def test_policy_updated(self):
+        '''Building an uptodate module with build policy set to "updated"'''
+        self.config.build_policy = 'updated'
+        self.assertEqual(self.build(packagedb_params = {'uptodate': True}), ['Checking out'])
+
+
 if __name__ == '__main__':
     unittest.main()



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