[jhbuild] tests: Add MockModule type, don't use /tmp for paths



commit 2764a9f523a49f3aa5d7a58f4101a8c5c30cd39d
Author: Colin Walters <walters verbum org>
Date:   Wed Aug 10 05:15:56 2011 -0400

    tests: Add MockModule type, don't use /tmp for paths
    
    Some of the tests were of type AutogenModule, but just pointing to
    /tmp.  This kind of worked before for a few reasons (we weren't
    checking the error code, the old install machinery didn't use DESTDIR
    and check contents).  Even worse the tests would change behavior if
    you happened to have a Makefile in /tmp.
    
    Since some of these tests are just testing behavior of the
    buildscript, create a MockModule type that explicitly doesn't do
    anything.
    
    At the same time, for other tests, ensure we're actually looking at a
    nonexistent directory.

 tests/mock.py  |   48 +++++++++++++++++++++++++++++++++++++++++-------
 tests/tests.py |   24 +++++++++++-------------
 2 files changed, 52 insertions(+), 20 deletions(-)
---
diff --git a/tests/mock.py b/tests/mock.py
index 7cf74c2..90897b3 100644
--- a/tests/mock.py
+++ b/tests/mock.py
@@ -19,6 +19,8 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 import time
+import os
+import tempfile
 
 import jhbuild.frontends.buildscript
 import jhbuild.versioncontrol
@@ -26,7 +28,7 @@ import jhbuild.errors
 import jhbuild.config
 
 class Config(jhbuild.config.Config):
-    buildroot = '/tmp/'
+    buildroot = tempfile.mkdtemp(prefix='jhbuild-tests-')
     builddir_pattern = '%s'
     use_lib64 = False
     noxvfb = True
@@ -55,8 +57,8 @@ class Config(jhbuild.config.Config):
 
     min_age = None
 
-    prefix = '/tmp/'
-    top_builddir = '/tmp/_jhbuild'
+    prefix = os.path.join(buildroot, 'prefix')
+    top_builddir = os.path.join(buildroot, '_jhbuild')
 
     def __init__(self):
         pass
@@ -123,16 +125,48 @@ class BuildScript(jhbuild.frontends.buildscript.BuildScript):
         self.actions[-1] = self.actions[-1] + ' [error]'
         return 'fail'
 
+class MockModule(jhbuild.modtypes.Package):
+    PHASE_CHECKOUT       = 'checkout'
+    PHASE_CLEAN          = 'clean'
+    PHASE_DISTCLEAN      = 'distclean'
+    PHASE_CONFIGURE      = 'configure'
+    PHASE_BUILD          = 'build'
+    PHASE_CHECK          = 'check'
+    PHASE_DIST           = 'dist'
+    PHASE_INSTALL        = 'install'
+
+    def do_checkout(self, buildscript):
+        buildscript.set_action(_('Checking out'), self)
+
+    def do_configure(self, buildscript):
+        buildscript.set_action(_('Configuring'), self)
+    do_configure.depends = [PHASE_CHECKOUT]
+
+    def do_build(self, buildscript):
+        buildscript.set_action(_('Building'), self)
+    do_build.depends = [PHASE_CONFIGURE]
+
+    def do_install(self, buildscript):
+        buildscript.set_action(_('Installing'), self)
+        buildscript.moduleset.packagedb.add(self.name, '', None)
+    do_install.depends = [PHASE_BUILD]
+
+    def do_check(self, buildscript):
+        buildscript.set_action(_('Checking'), self)
+    do_check.depends = [PHASE_BUILD]
+    do_check.error_phases = [PHASE_CONFIGURE]
+
+
 class Branch(jhbuild.versioncontrol.Branch):
-    def __init__(self):
-        pass
+    def __init__(self, tmpdir):
+        self._tmpdir = tmpdir
 
     def srcdir(self):
-        return '/tmp/'
+        return self._tmpdir
     srcdir = property(srcdir)
 
     def checkoutdir(self):
-        return '/tmp/'
+        return self._tmpdir
     checkoutdir = property(checkoutdir)
 
     def checkout(self, buildscript):
diff --git a/tests/tests.py b/tests/tests.py
index bda4988..4f7aa5c 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -254,8 +254,9 @@ class ModuleOrderingTestCase(JhbuildConfigTestCase):
 class BuildTestCase(JhbuildConfigTestCase):
     def setUp(self):
         super(BuildTestCase, self).setUp()
-        self.branch = mock.Branch()
+        self.branch = mock.Branch(os.path.join(self.config.buildroot, 'nonexistent'))
         self.branch.config = self.config
+        self.packagedb = None
         self.buildscript = None
         self.moduleset = None
 
@@ -269,13 +270,10 @@ class BuildTestCase(JhbuildConfigTestCase):
             setattr(self.config, k, kwargs[k])
         self.config.update_build_targets()
 
-        if not self.buildscript or packagedb_params:
-            packagedb = mock.PackageDB(**packagedb_params)
-            self.moduleset = jhbuild.moduleset.ModuleSet(self.config, db=packagedb)
-            self.buildscript = mock.BuildScript(self.config, self.modules, self.moduleset)
-        else:
-            packagedb = self.buildscript.moduleset.packagedb
-            self.buildscript = mock.BuildScript(self.config, self.modules, self.moduleset)
+        if (self.packagedb is None) or (len(packagedb_params) > 0):
+            self.packagedb = mock.PackageDB(**packagedb_params)
+            self.moduleset = jhbuild.moduleset.ModuleSet(self.config, db=self.packagedb)
+        self.buildscript = mock.BuildScript(self.config, self.modules, self.moduleset)
 
         self.buildscript.build()
         return self.buildscript.actions
@@ -285,7 +283,7 @@ class AutotoolsModTypeTestCase(BuildTestCase):
 
     def setUp(self):
         super(AutotoolsModTypeTestCase, self).setUp()
-        module = AutogenModule('foo', branch=self.branch)
+        module = mock.MockModule('foo', branch=self.branch)
         self.modules = [module]
         self.modules[0].config = self.config
         # replace clean method as it checks for Makefile existence
@@ -391,7 +389,7 @@ class BuildPolicyTestCase(BuildTestCase):
 
     def setUp(self):
         super(BuildPolicyTestCase, self).setUp()
-        self.modules = [AutogenModule('foo', branch=self.branch)]
+        self.modules = [mock.MockModule('foo', branch=self.branch)]
         self.modules[0].config = self.config
 
     def test_policy_all(self):
@@ -445,9 +443,9 @@ class TwoModulesTestCase(BuildTestCase):
 
     def setUp(self):
         super(TwoModulesTestCase, self).setUp()
-        self.foo_branch = mock.Branch()
-        self.modules = [AutogenModule('foo', branch=self.foo_branch),
-                        AutogenModule('bar', branch=self.branch)]
+        self.foo_branch = mock.Branch(os.path.join(self.config.buildroot, 'nonexistent-foo'))
+        self.modules = [mock.MockModule('foo', branch=self.foo_branch),
+                        mock.MockModule('bar', branch=self.branch)]
         self.modules[0].config = self.config
         self.modules[1].config = self.config
 



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