1
# Copyright 2011 Canonical, Ltd.
3
# This file is part of Tarmac.
5
# Tarmac is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License version 3 as
7
# published by 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/>.
16
"""Tests ignore merge mode plug-in."""
18
from tarmac.plugins.ignoremergemode import IgnoreMergeMode, IgnoreMerge, UNIGNORE_KEYWORD
19
from tarmac.tests import TarmacTestCase
20
from tarmac.tests.mock import Thing
25
class IgnoreMergeModeTests(TarmacTestCase):
26
"""Test the ignore merge mode plugin."""
30
super(IgnoreMergeModeTests, self).setUp()
31
self.ignoremergefile = tempfile.mkstemp()[1]
32
self.plugin = IgnoreMergeMode()
33
self.proposal = Thing(
34
source_branch = Thing(display_name='lp:foo/bar'),
35
description = 'foo %s bar' % UNIGNORE_KEYWORD)
36
self.target = Thing(config=Thing(ignoremerge_on=self.ignoremergefile))
39
super(IgnoreMergeModeTests, self).tearDown()
41
os.remove(self.ignoremergefile)
45
def test_no_block(self):
46
"""Test that with no ignore mode file, we don't reject the branch"""
47
self.target = Thing(config=Thing())
48
# should not raise anything
49
self.plugin.run(command=None, target=self.target, source=None,
50
proposal=self.proposal)
52
def test_ignore_branch(self):
53
"""Ensure an ordinary branch raise an exception and so, ignored"""
54
self.proposal.description = "foo"
55
self.assertRaises(IgnoreMerge, self.plugin.run, command=None,
56
target=self.target, source=None,
57
proposal=self.proposal)
59
def test_unignored_branch(self):
60
"""Ensure the special branch that can pass the merge ignore check"""
61
self.plugin.run(command=None, target=self.target, source=None,
62
proposal=self.proposal)
64
def test_in_ignore_mode(self):
65
"""Test that we are in ignored mode with one file"""
66
self.assertTrue(self.plugin._in_ignore_mode([self.ignoremergefile]))
68
def test_ignore_mode_with_two_files(self):
69
"""Test that we are in ignore mode with two files, one not existing"""
70
self.assertTrue(self.plugin._in_ignore_mode(["abcd", self.ignoremergefile]))
72
def test_not_ignore_mode(self):
73
"""Test that we are not in ignore mode with two unexisting files, one empty"""
74
self.assertFalse(self.plugin._in_ignore_mode(["abcd", ""]))
76
def test_ignored_branch(self):
77
"""Test that a ignored branch should be ignored"""
78
self.assertTrue(self.plugin._branch_should_be_ignored("foo"))
80
def test_unignored_branch(self):
81
"""Test that a branch with the right keyword should not be ignored"""
82
self.assertFalse(self.plugin._branch_should_be_ignored("foo %s" % UNIGNORE_KEYWORD))