[2.30] set glade3 to its 2.28 branch
[jhbuild/xnox.git] / tests / mock.py
blobae429080566c3388fecf18de2bf3382a72d3dec3
1 # jhbuild - a build script for GNOME 1.x and 2.x
2 # Copyright (C) 2001-2006 James Henstridge
3 # Copyright (C) 2007-2008 Frederic Peters
5 # mock.py: mock objects for unit testing
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 import time
23 import jhbuild.frontends.buildscript
24 import jhbuild.versioncontrol
25 import jhbuild.errors
26 import jhbuild.config
28 class Config(jhbuild.config.Config):
29 buildroot = '/tmp/'
30 builddir_pattern = '%s'
31 use_lib64 = False
32 noxvfb = True
34 force_policy = False
35 build_policy = 'all'
37 nonetwork = False
38 nobuild = False
39 makeclean = False
40 makecheck = False
41 makedist = False
42 makedistcheck = False
43 nopoison = False
44 makecheck_advisory = False
45 module_makecheck = {}
46 forcecheck = False
47 autogenargs = ''
48 module_autogenargs = {}
49 module_extra_env = {}
50 makeargs = ''
51 module_makeargs = {}
52 build_targets = ['install']
54 min_time = None
56 prefix = '/tmp/'
58 def __init__(self):
59 pass
62 class PackageDB:
63 time_delta = 0
65 def __init__(self, uptodate = False):
66 self.force_uptodate = uptodate
67 self.db = {}
69 def check(self, package, version=None):
70 if self.force_uptodate:
71 return self.force_uptodate
72 return self.db.get(package, ('_none_'))[0] == version
74 def add(self, package, version):
75 self.db[package] = (version, time.time()+self.time_delta)
77 def remove(self, package):
78 del self.db[package]
80 def installdate(self, package):
81 return self.db.get(package, ('_none_'))[1]
84 class BuildScript(jhbuild.frontends.buildscript.BuildScript):
85 execute_is_failure = False
87 def __init__(self, config, module_list):
88 self.config = config
89 self.modulelist = module_list
90 self.packagedb = PackageDB()
91 self.actions = []
93 def set_action(self, action, module, module_num=-1, action_target=None):
94 self.actions.append('%s:%s' % (module.name, action))
96 def execute(self, command, hint=None, cwd=None, extra_env=None):
97 if self.execute_is_failure:
98 raise jhbuild.errors.CommandError('Mock command asked to fail')
100 def message(self, msg, module_num = -1):
101 pass
103 def handle_error(self, module, state, nextstate, error, altstates):
104 self.actions[-1] = self.actions[-1] + ' [error]'
105 return 'fail'
107 class Branch(jhbuild.versioncontrol.Branch):
108 def __init__(self):
109 pass
111 def srcdir(self):
112 return '/tmp/'
113 srcdir = property(srcdir)
115 def checkout(self, buildscript):
116 pass
118 def tree_id(self):
119 return 'foo'
121 def raise_command_error(*args):
122 raise jhbuild.errors.CommandError('Mock Command Error Exception')