[jhbuild] tests: Create a new JhbuildConfigTestCase



commit eea1f7db0cb23f7762eb6d7dcb77bcd64bba9113
Author: Colin Walters <walters verbum org>
Date:   Thu Jul 28 09:58:23 2011 -0400

    tests: Create a new JhbuildConfigTestCase
    
    This supports more of the basic framework, and thus helps more of
    the tests pass.

 jhbuild/modtypes/autotools.py  |    4 +-
 jhbuild/modtypes/cmake.py      |    4 +-
 jhbuild/modtypes/distutils.py  |    4 +-
 jhbuild/modtypes/linux.py      |    4 +-
 jhbuild/modtypes/perl.py       |    4 +-
 jhbuild/modtypes/tarball.py    |    3 +-
 jhbuild/modtypes/testmodule.py |    4 +-
 jhbuild/modtypes/waf.py        |    4 +-
 tests/mock.py                  |   14 +++--
 tests/tests.py                 |  155 +++++++++++++++++++++-------------------
 10 files changed, 104 insertions(+), 96 deletions(-)
---
diff --git a/jhbuild/modtypes/autotools.py b/jhbuild/modtypes/autotools.py
index 9cd038a..6050d7c 100644
--- a/jhbuild/modtypes/autotools.py
+++ b/jhbuild/modtypes/autotools.py
@@ -46,7 +46,7 @@ class AutogenModule(Package, DownloadableModule):
     PHASE_DIST           = 'dist'
     PHASE_INSTALL        = 'install'
 
-    def __init__(self, name,
+    def __init__(self, name, branch=None,
                  autogenargs='', makeargs='',
                  makeinstallargs='',
                  supports_non_srcdir_builds=True,
@@ -55,7 +55,7 @@ class AutogenModule(Package, DownloadableModule):
                  makefile='Makefile',
                  autogen_template=None,
                  check_target=True):
-        Package.__init__(self, name)
+        Package.__init__(self, name, branch=branch)
         self.autogenargs = autogenargs
         self.makeargs    = makeargs
         self.makeinstallargs = makeinstallargs
diff --git a/jhbuild/modtypes/cmake.py b/jhbuild/modtypes/cmake.py
index 6ebf590..610f5c5 100644
--- a/jhbuild/modtypes/cmake.py
+++ b/jhbuild/modtypes/cmake.py
@@ -38,9 +38,9 @@ class CMakeModule(Package, DownloadableModule):
     PHASE_DIST = 'dist'
     PHASE_INSTALL = 'install'
 
-    def __init__(self, name,
+    def __init__(self, name, branch=None,
                  cmakeargs='', makeargs='',):
-        Package.__init__(self, name)
+        Package.__init__(self, name, branch=branch)
         self.cmakeargs = cmakeargs
         self.makeargs  = makeargs
         self.supports_install_destdir = True
diff --git a/jhbuild/modtypes/distutils.py b/jhbuild/modtypes/distutils.py
index 513aa96..faddc0f 100644
--- a/jhbuild/modtypes/distutils.py
+++ b/jhbuild/modtypes/distutils.py
@@ -37,8 +37,8 @@ class DistutilsModule(Package, DownloadableModule):
     PHASE_BUILD = 'build'
     PHASE_INSTALL = 'install'
 
-    def __init__(self, name, supports_non_srcdir_builds = True):
-        Package.__init__(self, name)
+    def __init__(self, name, branch=None, supports_non_srcdir_builds = True):
+        Package.__init__(self, name, branch=branch)
         self.supports_non_srcdir_builds = supports_non_srcdir_builds
         self.supports_install_destdir = True
 
diff --git a/jhbuild/modtypes/linux.py b/jhbuild/modtypes/linux.py
index 89be4f2..a186582 100644
--- a/jhbuild/modtypes/linux.py
+++ b/jhbuild/modtypes/linux.py
@@ -62,8 +62,8 @@ class LinuxModule(Package):
     PHASE_HEADERS_INSTALL = 'headers_install'
     PHASE_INSTALL         = 'install'
 
-    def __init__(self, name, kconfigs=None, makeargs=None):
-        Package.__init__(self, name)
+    def __init__(self, name, branch=None, kconfigs=None, makeargs=None):
+        Package.__init__(self, name, branch=branch)
         self.kconfigs = kconfigs
         self.makeargs = makeargs
 
diff --git a/jhbuild/modtypes/perl.py b/jhbuild/modtypes/perl.py
index 074883e..5b12692 100644
--- a/jhbuild/modtypes/perl.py
+++ b/jhbuild/modtypes/perl.py
@@ -38,8 +38,8 @@ class PerlModule(Package, DownloadableModule):
     PHASE_BUILD = 'build'
     PHASE_INSTALL = 'install'
 
-    def __init__(self, name, makeargs=''):
-        Package.__init__(self, name)
+    def __init__(self, name, branch=None, makeargs=''):
+        Package.__init__(self, name, branch=branch)
         self.makeargs = makeargs
 
     def get_srcdir(self, buildscript):
diff --git a/jhbuild/modtypes/tarball.py b/jhbuild/modtypes/tarball.py
index 52b75c7..d7874bc 100644
--- a/jhbuild/modtypes/tarball.py
+++ b/jhbuild/modtypes/tarball.py
@@ -98,12 +98,11 @@ def parse_tarball(node, config, uri, repositories, default_repo):
             source_size, source_hash, None)
     branch.patches = patches
 
-    instance = AutogenModule(name,
+    instance = AutogenModule(name, branch,
                              autogenargs, makeargs, makeinstallargs,
                              supports_non_srcdir_builds = supports_non_srcdir_builds,
                              skip_autogen = False, autogen_sh = 'configure',
                              makefile = makefile)
-    instance.branch = branch
     instance.dependencies = dependencies
     instance.after = after
     instance.suggests = suggests
diff --git a/jhbuild/modtypes/testmodule.py b/jhbuild/modtypes/testmodule.py
index 16d9932..07b031e 100644
--- a/jhbuild/modtypes/testmodule.py
+++ b/jhbuild/modtypes/testmodule.py
@@ -43,8 +43,8 @@ class TestModule(Package, DownloadableModule):
     PHASE_FORCE_CHECKOUT = DownloadableModule.PHASE_FORCE_CHECKOUT
     PHASE_TEST           = 'test'
     
-    def __init__(self, name, test_type=None, tested_pkgs=[]):
-        Package.__init__(self, name)
+    def __init__(self, name, branch=None, test_type=None, tested_pkgs=[]):
+        Package.__init__(self, name, branch=branch)
         self.test_type    = test_type
         self.tested_pkgs  = tested_pkgs
 
diff --git a/jhbuild/modtypes/waf.py b/jhbuild/modtypes/waf.py
index 198c467..220605a 100644
--- a/jhbuild/modtypes/waf.py
+++ b/jhbuild/modtypes/waf.py
@@ -44,8 +44,8 @@ class WafModule(Package, DownloadableModule):
     PHASE_DIST           = 'dist'
     PHASE_INSTALL        = 'install'
 
-    def __init__(self, name, waf_cmd='./waf'):
-        Package.__init__(self, name)
+    def __init__(self, name, branch=None, waf_cmd='./waf'):
+        Package.__init__(self, name, branch=branch)
         self.waf_cmd = waf_cmd
         self.supports_install_destdir = True
 
diff --git a/tests/mock.py b/tests/mock.py
index d6121ac..34b8035 100644
--- a/tests/mock.py
+++ b/tests/mock.py
@@ -45,6 +45,7 @@ class Config(jhbuild.config.Config):
     module_makecheck = {}
     module_nopoison = {}
     forcecheck = False
+    partial_build = True
     autogenargs = ''
     module_autogenargs = {}
     module_extra_env = {}
@@ -66,21 +67,24 @@ class PackageDB:
 
     def __init__(self, uptodate = False):
         self.force_uptodate = uptodate
-        self.db = {}
+        self.entries = {}
 
     def check(self, package, version=None):
         if self.force_uptodate:
             return self.force_uptodate
-        return self.db.get(package, ('_none_'))[0] == version
+        return self.entries.get(package, ('_none_'))[0] == version
 
     def add(self, package, version, manifest):
-        self.db[package] = (version, time.time()+self.time_delta)
+        self.entries[package] = (version, time.time()+self.time_delta, [])
 
     def remove(self, package):
-        del self.db[package]
+        del self.entries[package]
 
     def installdate(self, package):
-        return self.db.get(package, ('_none_'))[1]
+        entry = self.entries.get(package)
+        if entry is None:
+            return None
+        return entry[1]
 
 
 class BuildScript(jhbuild.frontends.buildscript.BuildScript):
diff --git a/tests/tests.py b/tests/tests.py
index 83e574d..4ca4ec4 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -73,11 +73,65 @@ if sys.platform.startswith('win'):
             cmd_list = subprocess_win32.cmdline2list (cmdline)
             self.assertEqual (cmd_list, ['test', 'no quotes', '!=', '"no\\ quotes"'])
 
-class ModuleOrderingTestCase(unittest.TestCase):
+class TestConfig(jhbuild.config.Config):
+
+    # The Config base class calls setup_env() in the constructor, but
+    # we need to override some attributes before calling it.
+    def setup_env(self):
+        pass
+
+    def real_setup_env(self):
+        jhbuild.config.Config.setup_env(self)
+
+class JhbuildConfigTestCase(unittest.TestCase):
+    """A test case that creates a mock configuration and temporary directory."""
+
+    def setUp(self):
+        self.config = mock.Config()
+        self._old_env = os.environ.copy()
+        self._temp_dirs = []
+
+    def tearDown(self):
+        restore_environ(self._old_env)
+        for temp_dir in self._temp_dirs:
+            shutil.rmtree(temp_dir)
+
+    def make_temp_dir(self):
+        temp_dir = tempfile.mkdtemp(prefix='unittest-')
+        self._temp_dirs.append(temp_dir)
+        return temp_dir
+
+    def make_config(self):
+        temp_dir = self.make_temp_dir()
+        config = TestConfig()
+        config.checkoutroot = os.path.abspath(os.path.join(temp_dir, 'checkout'))
+        config.prefix = os.path.abspath(os.path.join(temp_dir, 'prefix'))
+        os.makedirs(config.checkoutroot)
+        os.makedirs(config.prefix)
+        config.interact = False
+        config.quiet_mode = True # Not enough to disable output entirely
+        config.progress_bar = False
+        config.real_setup_env()
+        return config
+
+    def make_branch(self, config, src_name):
+        branch_dir = os.path.join(config.checkoutroot, src_name)
+        shutil.copytree(os.path.join(os.path.dirname(__file__), src_name),
+                        branch_dir)
+        return SimpleBranch(src_name, branch_dir)
+
+    def make_terminal_buildscript(self, config, module_list):
+        module_set = jhbuild.moduleset.load(config)
+        return jhbuild.frontends.terminal.TerminalBuildScript(config, module_list, module_set)
+
+    
+
+class ModuleOrderingTestCase(JhbuildConfigTestCase):
     '''Module Ordering'''
 
     def setUp(self):
-        self.moduleset = jhbuild.moduleset.ModuleSet()
+        super(ModuleOrderingTestCase, self).setUp()
+        self.moduleset = jhbuild.moduleset.ModuleSet(config=self.config)
         self.moduleset.add(Package('foo'))
         self.moduleset.add(Package('bar'))
         self.moduleset.add(Package('baz'))
@@ -196,14 +250,18 @@ class ModuleOrderingTestCase(unittest.TestCase):
         self.assertEqual(self.get_module_list(['foo', 'bar']), ['foo', 'bar'])
 
 
-class BuildTestCase(unittest.TestCase):
+class BuildTestCase(JhbuildConfigTestCase):
     def setUp(self):
-        self.config = mock.Config()
+        super(BuildTestCase, self).setUp()
         self.branch = mock.Branch()
         self.branch.config = self.config
         self.buildscript = None
         self.moduleset = None
 
+    def tearDown(self):
+        super(BuildTestCase, self).tearDown()
+        self.buildscript = None
+
     def build(self, packagedb_params = {}, **kwargs):
         self.config.build_targets = ['install', 'test']
         for k in kwargs:
@@ -221,17 +279,12 @@ class BuildTestCase(unittest.TestCase):
         self.buildscript.build()
         return self.buildscript.actions
 
-    def tearDown(self):
-        self.buildscript = None
-
-
 class AutotoolsModTypeTestCase(BuildTestCase):
     '''Autotools steps'''
 
     def setUp(self):
-        BuildTestCase.setUp(self)
-        module = AutogenModule('foo')
-        module.branch = self.branch
+        super(AutotoolsModTypeTestCase, self).setUp()
+        module = AutogenModule('foo', branch=self.branch)
         self.modules = [module]
         self.modules[0].config = self.config
         # replace clean method as it checks for Makefile existence
@@ -284,9 +337,9 @@ class WafModTypeTestCase(BuildTestCase):
     '''Waf steps'''
 
     def setUp(self):
-        BuildTestCase.setUp(self)
+        super(WafModTypeTestCase, self).setUp()
         from jhbuild.modtypes.waf import WafModule
-        self.modules = [WafModule('foo', self.branch)]
+        self.modules = [WafModule('foo', branch=self.branch)]
         self.modules[0].waf_cmd = 'true' # set a command for waf that always exist
 
     def test_build(self):
@@ -336,8 +389,8 @@ class BuildPolicyTestCase(BuildTestCase):
     '''Build Policy'''
 
     def setUp(self):
-        BuildTestCase.setUp(self)
-        self.modules = [AutogenModule('foo', self.branch)]
+        super(BuildPolicyTestCase, self).setUp()
+        self.modules = [AutogenModule('foo', branch=self.branch)]
         self.modules[0].config = self.config
 
     def test_policy_all(self):
@@ -373,9 +426,9 @@ class TestModTypeTestCase(BuildTestCase):
     '''Tests Module Steps'''
 
     def setUp(self):
-        BuildTestCase.setUp(self)
+        super(TestModTypeTestCase, self).setUp()
         from jhbuild.modtypes.testmodule import TestModule
-        self.modules = [TestModule('foo', self.branch, 'dogtail')]
+        self.modules = [TestModule('foo', branch=self.branch, test_type='dogtail')]
 
     def test_run(self):
         '''Running a test module'''
@@ -390,10 +443,10 @@ class TwoModulesTestCase(BuildTestCase):
     '''Building two dependent modules'''
 
     def setUp(self):
-        BuildTestCase.setUp(self)
+        super(TwoModulesTestCase, self).setUp()
         self.foo_branch = mock.Branch()
-        self.modules = [AutogenModule('foo', self.foo_branch),
-                        AutogenModule('bar', self.branch)]
+        self.modules = [AutogenModule('foo', branch=self.foo_branch),
+                        AutogenModule('bar', branch=self.branch)]
         self.modules[0].config = self.config
         self.modules[1].config = self.config
 
@@ -533,17 +586,6 @@ class TwoModulesTestCase(BuildTestCase):
                  'bar:Building', 'bar:Checking', 'bar:Installing'])
 
 
-class TestConfig(jhbuild.config.Config):
-
-    # The Config base class calls setup_env() in the constructor, but
-    # we need to override some attributes before calling it.
-    def setup_env(self):
-        pass
-
-    def real_setup_env(self):
-        jhbuild.config.Config.setup_env(self)
-
-
 class SimpleBranch(object):
 
     def __init__(self, name, dir_path):
@@ -585,41 +627,7 @@ def with_stdout_hidden(func):
         os.close(old_fd)
 
 
-class EndToEndTest(unittest.TestCase):
-
-    def setUp(self):
-        self.config = mock.Config()
-        self._old_env = os.environ.copy()
-        self._temp_dirs = []
-
-    def tearDown(self):
-        restore_environ(self._old_env)
-        for temp_dir in self._temp_dirs:
-            shutil.rmtree(temp_dir)
-
-    def make_temp_dir(self):
-        temp_dir = tempfile.mkdtemp(prefix='unittest-')
-        self._temp_dirs.append(temp_dir)
-        return temp_dir
-
-    def make_config(self):
-        temp_dir = self.make_temp_dir()
-        config = TestConfig()
-        config.checkoutroot = os.path.abspath(os.path.join(temp_dir, 'checkout'))
-        config.prefix = os.path.abspath(os.path.join(temp_dir, 'prefix'))
-        os.makedirs(config.checkoutroot)
-        os.makedirs(config.prefix)
-        config.interact = False
-        config.quiet_mode = True # Not enough to disable output entirely
-        config.progress_bar = False
-        config.real_setup_env()
-        return config
-
-    def make_branch(self, config, src_name):
-        branch_dir = os.path.join(config.checkoutroot, src_name)
-        shutil.copytree(os.path.join(os.path.dirname(__file__), src_name),
-                        branch_dir)
-        return SimpleBranch(src_name, branch_dir)
+class EndToEndTest(JhbuildConfigTestCase):
 
     # FIXME: broken under Win32
     def test_distutils(self):
@@ -627,8 +635,7 @@ class EndToEndTest(unittest.TestCase):
         module_list = [DistutilsModule('hello',
                                        self.make_branch(config, 'distutils'))]
         module_list[0].config = self.config
-        build = jhbuild.frontends.terminal.TerminalBuildScript(
-            config, module_list)
+        build = self.make_terminal_buildscript(config, module_list)
         with_stdout_hidden(build.build)
         proc = subprocess.Popen(['hello'], stdout=subprocess.PIPE)
         stdout, stderr = proc.communicate()
@@ -638,10 +645,9 @@ class EndToEndTest(unittest.TestCase):
     def test_autotools(self):
         config = self.make_config()
         module_list = [AutogenModule('hello',
-                                     self.make_branch(config, 'autotools'))]
+                                     branch=self.make_branch(config, 'autotools'))]
         module_list[0].config = self.config
-        build = jhbuild.frontends.terminal.TerminalBuildScript(
-            config, module_list)
+        build = self.make_terminal_buildscript(config, module_list)
         with_stdout_hidden(build.build)
         proc = subprocess.Popen(['hello'], stdout=subprocess.PIPE)
         stdout, stderr = proc.communicate()
@@ -654,12 +660,11 @@ class EndToEndTest(unittest.TestCase):
     def test_autotools_with_libtool(self):
         config = self.make_config()
         module_list = [
-            AutogenModule('libhello', self.make_branch(config, 'libhello')),
-            AutogenModule('hello', self.make_branch(config, 'hello'))]
+            AutogenModule('libhello', branch=self.make_branch(config, 'libhello')),
+            AutogenModule('hello', branch=self.make_branch(config, 'hello'))]
         module_list[0].config = self.config
         module_list[1].config = self.config
-        build = jhbuild.frontends.terminal.TerminalBuildScript(
-            config, module_list)
+        build = self.make_terminal_buildscript(config, module_list)
         with_stdout_hidden(build.build)
         proc = subprocess.Popen(['hello'], stdout=subprocess.PIPE)
         stdout, stderr = proc.communicate()



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