~dpb/tarmac/commit-message-newline

« back to all changes in this revision

Viewing changes to tarmac/tests/__init__.py

  • Committer: Tarmac
  • Author(s): Rodney Dawes
  • Date: 2013-10-31 22:00:00 UTC
  • mfrom: (412.2.5 home-loader)
  • Revision ID: tarmac-20131031220000-ud7iqws2g5xe4acs
Fix plug-in loading to use execfile() rather than relying on imports.
Remove the mock.py that conflicts namespace with python-mock.
Add tests for the load_plugins code.
Add a plug-in for testing the load_plugins code with.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright 2009 Paul Hummer
2
 
# This file is part of Tarmac.
3
2
#
4
3
# Tarmac is free software: you can redistribute it and/or modify
5
4
# it under the terms of the GNU General Public License version 3 as
15
14
# along with Tarmac.  If not, see <http://www.gnu.org/licenses/>.
16
15
 
17
16
'''Tests for Tarmac!'''
 
17
import math
18
18
import os
19
19
import shutil
20
20
import tempfile
21
21
 
 
22
from base64 import b64encode
 
23
from bzrlib.bzrdir import BzrDir
22
24
from bzrlib.directory_service import directories
23
25
from bzrlib.tests import TestCaseInTempDir
24
26
from bzrlib.transport import register_urlparse_netloc_protocol
25
27
 
26
28
from tarmac import branch
 
29
from tarmac.bin.commands import TarmacCommand
27
30
from tarmac.config import TarmacConfig
28
 
from tarmac.tests.mock import MockLPBranch
 
31
 
 
32
 
 
33
class MockLPProject(object):
 
34
    '''A mock LP Project.'''
 
35
 
 
36
    def __init__(self):
 
37
        self.name = b64encode(
 
38
            os.urandom(int(math.ceil(0.75 * 10))), '-_')[:10]
 
39
 
 
40
 
 
41
class MockLPBranch(object):
 
42
    '''A mock LP Branch.'''
 
43
 
 
44
    def __init__(self, tree_dir, source_branch=None):
 
45
        self.tree_dir = tree_dir
 
46
        os.makedirs(tree_dir)
 
47
        if source_branch:
 
48
            source_dir = source_branch._internal_bzr_branch.bzrdir
 
49
            bzrdir = source_dir.sprout(tree_dir)
 
50
            self._internal_tree, self._internal_bzr_branch = \
 
51
                    bzrdir.open_tree_or_branch(tree_dir)
 
52
            self.revision_count = source_branch.revision_count
 
53
        else:
 
54
            self._internal_bzr_branch = BzrDir.create_branch_convenience(
 
55
                tree_dir)
 
56
            self.revision_count = 0
 
57
        self.bzr_identity = 'lp:%s' % os.path.basename(self.tree_dir)
 
58
        self.web_link = self.bzr_identity
 
59
        self.project = MockLPProject()
 
60
 
 
61
 
 
62
class cmd_mock(TarmacCommand):
 
63
    '''A mock command.'''
 
64
 
 
65
    def run(self):
 
66
        """Just a dummy command that does nothing."""
 
67
 
 
68
 
 
69
class MockModule(object):
 
70
    """A mock module."""
 
71
 
 
72
    def __init__(self):
 
73
        self.__dict__['cmd_mock'] = cmd_mock
 
74
 
 
75
 
 
76
class Thing(dict):
 
77
    """Quickly create an object with given attributes."""
 
78
 
 
79
    def __init__(self, **names):
 
80
        super(Thing, self).__init__(self, **names)
 
81
        self.__dict__.update(names)
 
82
 
 
83
    def __iter__(self):
 
84
        for item in self.values():
 
85
            if not callable(item):
 
86
                yield item
29
87
 
30
88
 
31
89
class TarmacTestCase(TestCaseInTempDir):