Rev 199: Merged TestCaseWithQueue work. in http://bzr.daniel-watkins.co.uk/pqm/xmlrpc

Daniel Watkins daniel at daniel-watkins.co.uk
Fri Aug 1 01:26:16 BST 2008


At http://bzr.daniel-watkins.co.uk/pqm/xmlrpc

------------------------------------------------------------
revno: 199
revision-id: daniel at daniel-watkins.co.uk-20080801002438-5dr54mllw4mryztt
parent: daniel at daniel-watkins.co.uk-20080801002408-10h7dh7ayz2q9jn7
parent: daniel at daniel-watkins.co.uk-20080722171149-aut0g1391q5zdpjv
committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
branch nick: xmlrpc
timestamp: Fri 2008-08-01 01:24:38 +0100
message:
  Merged TestCaseWithQueue work.
modified:
  pqm/tests/__init__.py          i_74708178-eda5-4993-8549-5eddd090ce8e
  pqm/tests/test_pqm.py          x_Robert_Collins_<robert.collins at canonical.com>_Thu_Aug__4_22:52:41_2005_804.0
  pqm/ui/tests/test_twisted.py   x_Robert_Collins_<robert.collins at canonical.com>_Sat_Jul__9_22:36:13_2005_7873.0
    ------------------------------------------------------------
    revno: 176.1.12
    revision-id: daniel at daniel-watkins.co.uk-20080722171149-aut0g1391q5zdpjv
    parent: daniel at daniel-watkins.co.uk-20080722170203-rr1mr5tlq1vxm9x6
    committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
    branch nick: TestCaseWithQueue
    timestamp: Tue 2008-07-22 18:11:49 +0100
    message:
      Fixed failing tests.
    modified:
      pqm/tests/test_pqm.py          x_Robert_Collins_<robert.collins at canonical.com>_Thu_Aug__4_22:52:41_2005_804.0
    ------------------------------------------------------------
    revno: 176.1.11
    revision-id: daniel at daniel-watkins.co.uk-20080722170203-rr1mr5tlq1vxm9x6
    parent: daniel at daniel-watkins.co.uk-20080717104404-m2mkd8o1luidl0s0
    committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
    branch nick: TestCaseWithQueue
    timestamp: Tue 2008-07-22 18:02:03 +0100
    message:
      Converted TestCaseWithQueue to subclass bzrlib.tests.TestCaseWithTransport.
    modified:
      pqm/tests/__init__.py          i_74708178-eda5-4993-8549-5eddd090ce8e
      pqm/tests/test_pqm.py          x_Robert_Collins_<robert.collins at canonical.com>_Thu_Aug__4_22:52:41_2005_804.0
    ------------------------------------------------------------
    revno: 176.1.10
    revision-id: daniel at daniel-watkins.co.uk-20080717104404-m2mkd8o1luidl0s0
    parent: daniel at daniel-watkins.co.uk-20080717102329-dnul7uxcu03b5bih
    committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
    branch nick: TestCaseWithQueue
    timestamp: Thu 2008-07-17 11:44:04 +0100
    message:
      Fixed up as per lifeless' review comments.
    modified:
      pqm/tests/__init__.py          i_74708178-eda5-4993-8549-5eddd090ce8e
    ------------------------------------------------------------
    revno: 176.1.9
    revision-id: daniel at daniel-watkins.co.uk-20080717102329-dnul7uxcu03b5bih
    parent: daniel at daniel-watkins.co.uk-20080710164650-dd3c037m6wah8yuq
    parent: robertc at robertcollins.net-20080717100934-40fjde09nglggsub
    committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
    branch nick: TestCaseWithQueue
    timestamp: Thu 2008-07-17 11:23:29 +0100
    message:
      Merged pqm.dev r182.
    added:
      pqm/commandline.py             commandline.py-20080416102158-op31dy0lnkeo91ww-1
      pqm/errors.py                  errors.py-20080528044209-lpacj0a0ub4woseh-1
      pqm/script.py                  script.py-20080528044209-lpacj0a0ub4woseh-2
      pqm/tests/test_commandline.py  test_commandline.py-20080416102209-p18w8m9sw21704j9-1
    modified:
      .bzrignore                     bzrignore-20060322120158-35e5bcdaf76b6fdf
      Makefile.am                    i_Automake_rules_for_toplevel_tla-pqm_directory
      bin/pqm                        i_Simple_patch_queue_manager_for_tla
      configure.ac                   i_Toplevel_Autoconf_configuration_script
      pqm/__init__.py                i_dc99ede3-0c64-434d-ac84-305c06455a8d
      pqm/tests/__init__.py          i_74708178-eda5-4993-8549-5eddd090ce8e
      pqm/tests/test_lockfile.py     test_lockfile.py-20060111035725-07e8b573302c8fef
      pqm/tests/test_pqm.py          x_Robert_Collins_<robert.collins at canonical.com>_Thu_Aug__4_22:52:41_2005_804.0
      pqm/ui/tests/test_twisted.py   x_Robert_Collins_<robert.collins at canonical.com>_Sat_Jul__9_22:36:13_2005_7873.0
      pqm/ui/twistd.py               x_Robert_Collins_<robert.collins at canonical.com>_Sun_Jul_10_02:00:08_2005_15556.0
    ------------------------------------------------------------
    revno: 176.1.8
    revision-id: daniel at daniel-watkins.co.uk-20080710164650-dd3c037m6wah8yuq
    parent: daniel at daniel-watkins.co.uk-20080710164337-y4962o5sczz0tqv7
    committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
    branch nick: TestCaseWithQueue
    timestamp: Thu 2008-07-10 17:46:50 +0100
    message:
      Converted TestTwistedUI to subclass TestCaseWithQueue.
    modified:
      pqm/ui/tests/test_twisted.py   x_Robert_Collins_<robert.collins at canonical.com>_Sat_Jul__9_22:36:13_2005_7873.0
    ------------------------------------------------------------
    revno: 176.1.7
    revision-id: daniel at daniel-watkins.co.uk-20080710164337-y4962o5sczz0tqv7
    parent: daniel at daniel-watkins.co.uk-20080710164201-zmw1dgimft79nd1f
    committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
    branch nick: TestCaseWithQueue
    timestamp: Thu 2008-07-10 17:43:37 +0100
    message:
      Import cleanup.
    modified:
      pqm/tests/test_pqm.py          x_Robert_Collins_<robert.collins at canonical.com>_Thu_Aug__4_22:52:41_2005_804.0
      pqm/ui/tests/test_twisted.py   x_Robert_Collins_<robert.collins at canonical.com>_Sat_Jul__9_22:36:13_2005_7873.0
    ------------------------------------------------------------
    revno: 176.1.6
    revision-id: daniel at daniel-watkins.co.uk-20080710164201-zmw1dgimft79nd1f
    parent: daniel at daniel-watkins.co.uk-20080710163552-maaev5jnyg7iyp3h
    committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
    branch nick: TestCaseWithQueue
    timestamp: Thu 2008-07-10 17:42:01 +0100
    message:
      Converted TestWithQueueDirectory to subclass TestCaseWithQueue.
    modified:
      pqm/tests/test_pqm.py          x_Robert_Collins_<robert.collins at canonical.com>_Thu_Aug__4_22:52:41_2005_804.0
    ------------------------------------------------------------
    revno: 176.1.5
    revision-id: daniel at daniel-watkins.co.uk-20080710163552-maaev5jnyg7iyp3h
    parent: daniel at daniel-watkins.co.uk-20080710162506-tpi33egh01pu79tg
    committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
    branch nick: TestCaseWithQueue
    timestamp: Thu 2008-07-10 17:35:52 +0100
    message:
      Removed need for scriptname to be a instance variable.
    modified:
      pqm/tests/test_pqm.py          x_Robert_Collins_<robert.collins at canonical.com>_Thu_Aug__4_22:52:41_2005_804.0
    ------------------------------------------------------------
    revno: 176.1.4
    revision-id: daniel at daniel-watkins.co.uk-20080710162506-tpi33egh01pu79tg
    parent: daniel at daniel-watkins.co.uk-20080710161953-ohx24ca1c88s9m0j
    committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
    branch nick: TestCaseWithQueue
    timestamp: Thu 2008-07-10 17:25:06 +0100
    message:
      Added pqm.tests.TestCaseWithQueue.
    modified:
      pqm/tests/__init__.py          i_74708178-eda5-4993-8549-5eddd090ce8e
      pqm/tests/test_pqm.py          x_Robert_Collins_<robert.collins at canonical.com>_Thu_Aug__4_22:52:41_2005_804.0
    ------------------------------------------------------------
    revno: 176.1.3
    revision-id: daniel at daniel-watkins.co.uk-20080710161953-ohx24ca1c88s9m0j
    parent: daniel at daniel-watkins.co.uk-20080710160216-hazgu51bbkw9fums
    committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
    branch nick: TestCaseWithQueue
    timestamp: Thu 2008-07-10 17:19:53 +0100
    message:
      Moved QueueSetup to pqm.tests.QueueSetup.
    modified:
      pqm/tests/__init__.py          i_74708178-eda5-4993-8549-5eddd090ce8e
      pqm/tests/test_pqm.py          x_Robert_Collins_<robert.collins at canonical.com>_Thu_Aug__4_22:52:41_2005_804.0
    ------------------------------------------------------------
    revno: 176.1.2
    revision-id: daniel at daniel-watkins.co.uk-20080710160216-hazgu51bbkw9fums
    parent: daniel at daniel-watkins.co.uk-20080710155822-i9toa3rw19sp0pt2
    committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
    branch nick: empty-queue
    timestamp: Thu 2008-07-10 17:02:16 +0100
    message:
      Added 'empty' parameter to QueueSetup, to define whether there should be anything in the queue.
    modified:
      pqm/tests/test_pqm.py          x_Robert_Collins_<robert.collins at canonical.com>_Thu_Aug__4_22:52:41_2005_804.0
    ------------------------------------------------------------
    revno: 176.1.1
    revision-id: daniel at daniel-watkins.co.uk-20080710155822-i9toa3rw19sp0pt2
    parent: robertc at robertcollins.net-20080710074340-dl0w25nbutl88sz2
    committer: Daniel Watkins <daniel at daniel-watkins.co.uk>
    branch nick: empty-queue
    timestamp: Thu 2008-07-10 16:58:22 +0100
    message:
      Added processing option on QueueSetup, to define whether any further queue requests are being processed.
    modified:
      pqm/tests/test_pqm.py          x_Robert_Collins_<robert.collins at canonical.com>_Thu_Aug__4_22:52:41_2005_804.0
-------------- next part --------------
=== modified file 'pqm/tests/__init__.py'
--- a/pqm/tests/__init__.py	2006-01-11 03:58:41 +0000
+++ b/pqm/tests/__init__.py	2008-07-22 17:02:03 +0000
@@ -0,0 +1,81 @@
+import os
+import shutil
+from textwrap import dedent
+
+from bzrlib.tests import TestCaseWithTransport
+
+
+sample_message = dedent("""\
+    From: John.Citizen at example.com
+    Subject: A new action
+    star-merge http://www.example.com/foo/bar http://www.example.com/bar/baz
+    """)
+
+sample_message_2 = dedent("""\
+    From: John.Citizen at example.com
+    Subject: A new action
+    star-merge http://www.example.com/qux/thud http://www.example.com/fred/waldo
+    """)
+
+sample_message_bad = dedent("""\
+    From: John.Citizen at example.com
+    Subject: A new action
+    star-merge http://www.example.com/foo/bar http://www.example.com/foo/unregistered
+    """)
+
+
+class QueueSetup(object):
+    """Setup a queue with mock messages in it."""
+
+    def __init__(self, processing=True, empty=False):
+        self.configFileName = "Foo"
+        self.cwd = os.path.abspath(os.path.curdir)
+        self.processing = processing
+        self.empty = empty
+        if not empty:
+            self.message = sample_message
+            self.message_bad = sample_message_bad
+            self.message3 = sample_message_2
+
+    def setUp(self):
+        myFile=open(self.configFileName, "w")
+        myFile.write(dedent("""\
+            [DEFAULT]
+            queuedir=%s/queue
+            [http://www.example.com/bar/baz]
+            project=project
+            [http://www.example.com/fred/waldo]
+            """ % self.cwd))
+        myFile.close()
+        self.queuedir = os.path.join(self.cwd, "queue")
+        try:
+            os.mkdir(self.queuedir)
+            os.mkdir(self.queuedir + '/pqm')
+        except OSError:
+            pass
+        if not self.processing:
+            open("%s/stop.patch" % (self.queuedir,), "w").close()
+        if not self.empty:
+            self.messageFileName = os.path.join(self.queuedir,
+                                                "patch.00000001")
+            messageFile = open(self.messageFileName, "w")
+            messageFile.write(self.message)
+            messageFile.close()
+            self.messageFileNameBad = os.path.join(self.queuedir,
+                                                   "patch.00000002")
+            messageFile = open(self.messageFileNameBad, "w")
+            messageFile.write(self.message_bad)
+            messageFile.close()
+            self.messageFileName3 = os.path.join(self.queuedir,
+                                                 "patch.00000003")
+            messageFile = open(self.messageFileName3, "w")
+            messageFile.write(self.message3)
+            messageFile.close()
+
+
+class TestCaseWithQueue(TestCaseWithTransport):
+
+    def getQueue(self, processing=True, empty=False):
+        queue = QueueSetup(processing, empty)
+        queue.setUp()
+        return queue

=== modified file 'pqm/tests/test_pqm.py'
--- a/pqm/tests/test_pqm.py	2008-07-17 10:09:34 +0000
+++ b/pqm/tests/test_pqm.py	2008-07-22 17:11:49 +0000
@@ -9,25 +9,16 @@
 from twisted.trial import unittest
 
 import pqm
+from pqm.tests import (sample_message,
+                       sample_message_2,
+                       sample_message_bad,
+                       TestCaseWithQueue,
+                      )
+
 from pqm.errors import PQMCmdFailure
 from pqm.PQMConfigParser import ConfigParser
 from pqm.script import Command, CommandRunner, DebugCommand, MergeCommand
 
-sample_message = dedent("""\
-    From: John.Citizen at example.com
-    Subject: A new action
-    star-merge http://www.example.com/foo/bar http://www.example.com/bar/baz
-    """)
-sample_message_2 = dedent("""\
-    From: John.Citizen at example.com
-    Subject: A new action
-    star-merge http://www.example.com/qux/thud http://www.example.com/fred/waldo
-    """)
-sample_message_bad = dedent("""\
-    From: John.Citizen at example.com
-    Subject: A new action
-    star-merge http://www.example.com/foo/bar http://www.example.com/foo/unregistered
-    """)
 sample_signed_message = dedent("""\
     From: whee at bar.com (Matthew Thomas)
     Subject: [trivial] fix various actions portlet icons
@@ -115,83 +106,24 @@
     """)
 
 
-class QueueSetup(object):
-    """Setup a queue with mock messages in it."""
-
-    def __init__(self):
-        self.configFileName = "Foo"
-        self.cwd = os.path.abspath(os.path.curdir)
-        self.message = sample_message
-        self.message_bad = sample_message_bad
-        self.message3 = sample_message_2
-
-    def setUp(self):
-        myFile=open(self.configFileName, "w")
-        myFile.write(dedent("""\
-            [DEFAULT]
-            queuedir=%s/queue
-            [http://www.example.com/bar/baz]
-            project=project
-            [http://www.example.com/fred/waldo]
-            """) % self.cwd)
-        myFile.close()
-        self.queuedir = os.path.join(self.cwd, "queue")
-        try:
-            os.mkdir(self.queuedir)
-            os.mkdir(self.queuedir + '/pqm')
-        except OSError:
-            pass
-        self.messageFileName = os.path.join(self.queuedir, "patch.00000001")
-        messageFile = open(self.messageFileName, "w")
-        messageFile.write(self.message)
-        messageFile.close()
-        self.messageFileNameBad = os.path.join(self.queuedir, "patch.00000002")
-        messageFile = open(self.messageFileNameBad, "w")
-        messageFile.write(self.message_bad)
-        messageFile.close()
-        self.messageFileName3 = os.path.join(self.queuedir, "patch.00000003")
-        messageFile = open(self.messageFileName3, "w")
-        messageFile.write(self.message3)
-        messageFile.close()
-
-    def tearDown(self):
-        os.unlink(self.configFileName)
-        shutil.rmtree(self.queuedir, ignore_errors=True)
-
-
-class TestWithQueueDirectory(unittest.TestCase):
-
-    def setUp(self):
-        unittest.TestCase.setUp(self)
-        self.queue = QueueSetup()
-        self.queue.setUp()
+class TestWithQueueDirectory(TestCaseWithQueue):
 
     def testName(self):
         patch = pqm.Script('foo.script', logging, False, 0, None, None)
         self.assertEqual(patch.filename, 'foo.script')
-        self.scriptname = 'fpp'
-
-    def tearDown(self):
-        try:
-            os.unlink(self.scriptname)
-        except OSError:
-            pass
-        self.queue.tearDown()
-
-    def getScript(self, content):
+
+    def getScript(self, queue, content):
         """Get a script for testing with."""
-        self.scriptname = 'foo.script'
-        scriptFile = open(self.scriptname, "w")
-        scriptFile.write(content)
-        scriptFile.close()
+        self.build_tree_contents([('foo.script', content)])
         pqm.pqm_subdir = os.path.abspath('queue/pqm')
         configp = ConfigParser()
-        configp.read([self.queue.configFileName])
+        configp.read([queue.configFileName])
         handler = pqm.BranchSpecOptionHandler(configp)
-        return pqm.Script(self.scriptname, logging, False, 54, handler, configp)
+        return pqm.Script('foo.script', logging, False, 54, handler, configp)
 
     def testFields(self):
-        script = self.getScript(sample_message)
+        queue = self.getQueue()
+        script = self.getScript(queue, sample_message)
         self.assertEqual(script.getSender(), "John.Citizen at example.com")
         self.assertEqual(script.getSubject(), "A new action")
         self.assertEqual(script.getContent(),
@@ -200,7 +132,7 @@
         self.assertEqual(script.getLines(),
             [("star-merge http://www.example.com/foo/bar "
               "http://www.example.com/bar/baz")])
-        self.assertEqual([pqm.MergeCommand(None,
+        self.assertEqual([MergeCommand(None,
                                            None,
                                            None,
                                            'http://www.example.com/foo/bar',
@@ -208,7 +140,8 @@
                          script.getCommands())
 
     def testGPGFields(self):
-        script = self.getScript(sample_signed_message)
+        queue = self.getQueue()
+        script = self.getScript(queue, sample_signed_message)
         self.assertEqual(script.getSender(), "whee at bar.com (Matthew Thomas)")
         self.assertEqual(script.getSubject(),
             "[trivial] fix various actions portlet icons")
@@ -229,7 +162,7 @@
             [("star-merge http://www.example.com/argh/blah "
               "http://www.example.com/bing/bong")])
         self.assertEqual(
-            [pqm.MergeCommand(None,
+            [MergeCommand(None,
                               None,
                               None,
                               'http://www.example.com/argh/blah',
@@ -238,27 +171,30 @@
 
     def testDate(self):
         """Can we access a submission time for scripts."""
-        script = self.getScript(sample_message)
+        queue = self.getQueue()
+        script = self.getScript(queue, sample_message)
         self.assertEqual(script.getSubmissionTime(), 54)
 
     def testProjects(self):
         # A script may affect multiple branches, so we can ask the script
         # for its projects, and then for the commands for a project.
-        script = self.getScript(sample_message)
+        queue = self.getQueue()
+        script = self.getScript(queue, sample_message)
         self.assertEqual(set(['project']), script.getProjects())
 
     def test_log_status(self):
         # make an initial status file
-        status = file(self.queue.queuedir + '/pqm/status', 'wt')
+        queue = self.getQueue()
+        status = file(queue.queuedir + '/pqm/status', 'wt')
         status.write('bar\n')
         status.close()
-        script = self.getScript(sample_message)
+        script = self.getScript(queue, sample_message)
         command = Command(script,
                           script._branch_spec_handler,
                           script._configp)
         logger = MockLogger()
         command.log_with_status(logger, 'foo')
-        content = file(self.queue.queuedir + '/pqm/status').read()
+        content = file(queue.queuedir + '/pqm/status').read()
         self.assertEqual('bar\nfoo\n', content)
 
 

=== modified file 'pqm/ui/tests/test_twisted.py'
--- a/pqm/ui/tests/test_twisted.py	2008-07-16 15:44:48 +0000
+++ b/pqm/ui/tests/test_twisted.py	2008-07-17 10:23:29 +0000
@@ -1,37 +1,29 @@
-
 from twisted.trial import unittest
 from twisted.web.resource import getChildForRequest
 from twisted.web.test.test_web import DummyRequest
 import logging
 
 import pqm
+from pqm.tests import TestCaseWithQueue
 from pqm.PQMConfigParser import ConfigParser
-from pqm.tests.test_pqm import QueueSetup
-
-class TestTwistedUI(unittest.TestCase):
+
+
+class TestTwistedUI(TestCaseWithQueue):
 
     def testImports(self):
         import pqm.ui.twistd
 
-    def setUp(self):
-        unittest.TestCase.setUp(self)
-        self.queueSetup = QueueSetup()
-        self.queueSetup.setUp()
-
-    def tearDown(self):
-        unittest.TestCase.tearDown(self)
-        self.queueSetup.tearDown()
-
     def testQueue(self):
         from pqm.ui.twistd import FakeOptions
+        queue = self.getQueue()
         configp = ConfigParser()
-        configp.read([self.queueSetup.configFileName])
+        configp.read([queue.configFileName])
         handler = pqm.BranchSpecOptionHandler(configp)
         queuedir = pqm.get_queuedir(configp, logging, [])
         patches = pqm.find_patches(
             queuedir, logging, handler, configp, FakeOptions())
         self.assertEqual(3, len(patches))
-        self.assertEqual(patches[0].filename, self.queueSetup.messageFileName)
+        self.assertEqual(patches[0].filename, queue.messageFileName)
         self.assertEqual(set(['project']),
                          patches[0].getCommands()[0].getProjects())
         self.assertRaises(KeyError,
@@ -41,10 +33,11 @@
 
     def getResource(self):
         from pqm.ui.twistd import PQMInfo, QueueResource
-        statusfile = file(self.queueSetup.queuedir + '/pqm/status', 'wt')
+        queue = self.getQueue()
+        statusfile = file(queue.queuedir + '/pqm/status', 'wt')
         statusfile.write("<foo\nbar\nbaz\nquux\ntheta\n")
         statusfile.close()
-        pqminfo = PQMInfo([self.queueSetup.configFileName])
+        pqminfo = PQMInfo([queue.configFileName])
         resource = QueueResource(pqminfo)
         pqminfo.refresh()
         return resource



More information about the bazaar-commits mailing list