1
# Copyright 2009 Paul Hummer
2
# This file is part of Tarmac.
4
# Tarmac is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License version 3 as
7
# the Free Software Foundation.
9
# Tarmac is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with Tarmac. If not, see <http://www.gnu.org/licenses/>.
17
'''Mock objects for Tarmac!'''
18
from base64 import b64encode
22
from bzrlib.bzrdir import BzrDir
24
from tarmac.bin.commands import TarmacCommand
27
class MockLPProject(object):
28
'''A mock LP Project.'''
31
self.name = b64encode(
32
os.urandom(int(math.ceil(0.75 * 10))), '-_')[:10]
35
class MockLPBranch(object):
36
'''A mock LP Branch.'''
38
def __init__(self, tree_dir, source_branch=None):
39
self.tree_dir = tree_dir
42
source_dir = source_branch._internal_bzr_branch.bzrdir
43
bzrdir = source_dir.sprout(tree_dir)
44
self._internal_tree, self._internal_bzr_branch = \
45
bzrdir.open_tree_or_branch(tree_dir)
46
self.revision_count = source_branch.revision_count
48
self._internal_bzr_branch = BzrDir.create_branch_convenience(
50
self.revision_count = 0
51
self.bzr_identity = 'lp:%s' % os.path.basename(self.tree_dir)
52
self.web_link = self.bzr_identity
53
self.project = MockLPProject()
56
class cmd_mock(TarmacCommand):
60
"""Just a dummy command that does nothing."""
63
class MockModule(object):
67
self.__dict__['cmd_mock'] = cmd_mock
71
"""Quickly create an object with given attributes."""
73
def __init__(self, **names):
74
super(Thing, self).__init__(self, **names)
75
self.__dict__.update(names)
78
for item in self.values():
79
if not callable(item):