Sketchy, sketchy tests
authorNeil <neil@dip.sun.ac.za>
Sun, 11 Nov 2012 10:58:23 +0000 (12:58 +0200)
committerNeil <neil@dip.sun.ac.za>
Sun, 11 Nov 2012 10:58:23 +0000 (12:58 +0200)
tests/testirker.py

index 8bec6d0d065955ae1035b67ec09bbea634062c6c..fb7c49d73b99424daace12e4c58ce5e52662f9aa 100644 (file)
@@ -15,3 +15,61 @@ from bzrlib.plugins.bzrirker.irkerhook import IrkerSender
 
 def test_suite():
     return TestLoader().loadTestsFromName(__name__)
+
+sample_config=("[DEFAULT]\n"
+        "irker_url=bzr://test.example.test/bzrirker\n"
+        "irker_project=bzrirker\n"
+        "irker_channels=irc://chat.example.test/commits\n")
+
+colour_config=("[DEFAULT]\n"
+        "irker_url=bzr://test.example.test/bzrirker\n"
+        "irker_project=bzrirker\n"
+        "irker_colours=mIRC\n"
+        "irker_channels=irc://chat.example.test/commits\n")
+
+
+class TestConfigured(TestCaseInTempDir):
+
+    def test_url(self):
+        irker = self.get_irker()
+        self.assertEqual('bzr://test.example.test/bzrirker', irker.url())
+
+    def test_colours(self):
+        irker = self.get_irker()
+        self.assertEqual({
+            'bold': '', 'green': '', 'blue': '', 'red': '',
+            'yellow': '', 'brown': '', 'magenta': '', 'cyan': '',
+            'reset': ''}, irker.colours())
+
+        irker = self.get_irker(color_config)
+        self.assertEqual({
+            'bold': '\x02', 'green': '\x0303', 'blue': '\x0302',
+            'red': '\x0305', 'yellow': '\x0307', 'brown': '\x0305',
+            'magenta': '\x0306', 'cyan': '\x0310', 'reset': '\x0F'},
+            irker.colours())
+
+    def test_message(self):
+        irker = self.get_irker()
+        self.assertEqual(
+                '', irker._format())
+        irker = self.get_irker(color_config)
+        self.assertEqual(
+                '', irker._format())
+
+
+    def get_irker(sef, text=sample_config):
+        my_config = config.MemoryStack(text)
+        self.branch = BzrDir.create_branch_convenience('.')
+        tree = self.branch.bzrdir.open_workingtree()
+        tree.commit('foo bar baz\nfuzzy\nwuzzy', rev_id='A',
+                allow_pointless=True,
+                timestamp=1,
+                timezone=0,
+                committer="Sample <john@example.test>",
+                )
+        irker = IrkerSender(self.branch, 'A', my_config)
+        # We're not calling send, so do the setup stuff here
+        irker._setup_revision_and_revno()
+        return irker
+        
+