1 # -*- coding: utf-8 -*-
2 # vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4
3 # Copyright 2012 Neil Muller
4 # GPL 2+ - see COPYING for details
5 from unittest import TestLoader
10 from bzrlib.bzrdir import BzrDir
11 from bzrlib.tests import TestCaseInTempDir
12 from bzrlib.plugins.bzrirker.irkerhook import IrkerSender
16 return TestLoader().loadTestsFromName(__name__)
18 sample_config = ("[DEFAULT]\n"
19 "irker_project=bzrirker\n"
20 "irker_channels=irc://chat.example.test/commits\n")
22 no_project_config = ("[DEFAULT]\n"
23 "irker_channels=irc://chat.example.test/commits\n")
25 colour_config = ("[DEFAULT]\n"
26 "irker_project=bzrirker\n"
27 "irker_colours=mIRC\n"
28 "irker_channels=irc://chat.example.test/commits\n")
31 class TestConfigured(TestCaseInTempDir):
33 def test_no_colours(self):
34 irker = self.get_irker()
36 'bold': '', 'green': '', 'blue': '', 'red': '',
37 'yellow': '', 'brown': '', 'magenta': '', 'cyan': '',
38 'reset': ''}, irker.colours())
40 def test_colours(self):
41 irker = self.get_irker(colour_config)
43 'bold': '\x02', 'green': '\x0303', 'blue': '\x0302',
44 'red': '\x0305', 'yellow': '\x0307', 'brown': '\x0305',
45 'magenta': '\x0306', 'cyan': '\x0310', 'reset': '\x0F'},
48 def test_message(self):
49 irker = self.get_irker()
51 'bzrirker: Sample <john@example.test> work * 1 / : foo bar ',
54 def test_no_project(self):
55 irker = self.get_irker(no_project_config)
57 'No Project name set: Sample <john@example.test>'
58 ' work * 1 / : foo bar ',
61 def test_message_colour(self):
62 irker = self.get_irker(colour_config)
64 '\x02bzrirker:\x0f \x0303Sample <john@example.test>\x0f'
65 ' work * \x021\x0f / \x02\x0f: foo bar ', irker._format())
67 def get_irker(self, text=sample_config):
68 my_config = config.MemoryStack(text)
69 self.branch = BzrDir.create_branch_convenience('.')
70 tree = self.branch.bzrdir.open_workingtree()
71 tree.commit('foo bar\nfuzzy\nwuzzy', rev_id='A',
75 committer="Sample <john@example.test>",
77 irker = IrkerSender(self.branch, 'A', my_config)
78 # We're not calling send, so do the setup stuff here
79 irker._setup_revision_and_revno()