mock.py 3.34 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
# 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

21
import time
22 23 24

import jhbuild.frontends.buildscript
import jhbuild.versioncontrol
25
import jhbuild.errors
26
import jhbuild.config
27

28
class Config(jhbuild.config.Config):
29 30
    buildroot = '/tmp/'
    builddir_pattern = '%s'
31 32 33
    use_lib64 = False
    noxvfb = True

34 35 36 37 38 39 40 41 42
    force_policy = False
    build_policy = 'all'

    nonetwork = False
    nobuild = False
    makeclean = False
    makecheck = False
    makedist = False
    makedistcheck = False
43 44
    nopoison = False
    makecheck_advisory = False
45
    module_makecheck = {}
46
    module_nopoison = {}
47
    forcecheck = False
48 49 50 51 52
    autogenargs = ''
    module_autogenargs = {}
    module_extra_env = {}
    makeargs = ''
    module_makeargs = {}
53
    build_targets = ['install']
54

55
    min_age = None
56

57 58
    prefix = '/tmp/'

59 60 61
    def __init__(self):
        pass

62

63
class PackageDB:
64 65
    time_delta = 0

66
    def __init__(self, uptodate = False):
67 68
        self.force_uptodate = uptodate
        self.db = {}
69 70

    def check(self, package, version=None):
71 72 73
        if self.force_uptodate:
            return self.force_uptodate
        return self.db.get(package, ('_none_'))[0] == version
74 75

    def add(self, package, version):
76 77 78 79 80 81 82 83
        self.db[package] = (version, time.time()+self.time_delta)

    def remove(self, package):
        del self.db[package]

    def installdate(self, package):
        return self.db.get(package, ('_none_'))[1]

84 85

class BuildScript(jhbuild.frontends.buildscript.BuildScript):
86 87
    execute_is_failure = False

88 89 90 91 92 93 94
    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):
95
        self.actions.append('%s:%s' % (module.name, action))
96 97

    def execute(self, command, hint=None, cwd=None, extra_env=None):
98 99
        if self.execute_is_failure:
            raise jhbuild.errors.CommandError('Mock command asked to fail')
100 101 102

    def message(self, msg, module_num = -1):
        pass
103 104 105 106
    
    def handle_error(self, module, state, nextstate, error, altstates):
        self.actions[-1] = self.actions[-1] + ' [error]'
        return 'fail'
107 108 109 110 111 112 113 114 115 116 117 118 119 120

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'
121 122 123

def raise_command_error(*args):
    raise jhbuild.errors.CommandError('Mock Command Error Exception')