[Buildbot-commits] buildbot/buildbot/test test_changes.py,1.2,1.3

Brian Warner warner at users.sourceforge.net
Wed May 4 02:09:40 UTC 2005


Update of /cvsroot/buildbot/buildbot/buildbot/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31343/buildbot/test

Modified Files:
	test_changes.py 
Log Message:
Revision: arch at buildbot.sf.net--2004/buildbot--dev--0--patch-119
Creator:  Brian Warner <warner at monolith.lothar.com>

add 'buildbot sendchange' command

	* buildbot/scripts/runner.py (sendchange): new command to send a
	change to a buildbot.changes.pb.PBChangeSource receiver.
	* buildbot/test/test_changes.py (Sender): test it

	* buildbot/master.py (BuildMaster.startService): mark .readConfig
	after any reading of the config file, not just when we do it in
	startService. This makes some tests a bit cleaner.

	* buildbot/changes/pb.py: add some log messages


Index: test_changes.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_changes.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- test_changes.py	24 Apr 2005 21:30:25 -0000	1.2
+++ test_changes.py	4 May 2005 02:09:38 -0000	1.3
@@ -1,8 +1,13 @@
 # -*- test-case-name: buildbot.test.test_changes -*-
 
 from twisted.trial import unittest
+dr = unittest.deferredResult
+from twisted.internet import defer
+from twisted.python import log
 
+from buildbot import master
 from buildbot.changes import pb
+from buildbot.scripts import runner
 
 d1 = {'files': ["Project/foo.c", "Project/bar/boo.c"],
       'who': "marvin",
@@ -53,3 +58,92 @@
         self.failUnlessEqual(c3.comments, "mixed changes")
         self.failUnlessEqual(c3.who, "alice")
 
+config_sender = """
+from buildbot.changes import pb
+c = {}
+c['bots'] = []
+c['builders'] = []
+c['sources'] = [pb.PBChangeSource(port=None)]
+c['slavePortnum'] = 0
+BuildmasterConfig = c
+"""
+
+class Sender(unittest.TestCase):
+    def setUp(self):
+        self.master = master.BuildMaster(".")
+    def tearDown(self):
+        d = defer.maybeDeferred(self.master.stopService)
+        dr(d)
+
+    def testSender(self):
+        d = self.master.loadConfig(config_sender)
+        dr(d)
+        self.master.startService()
+        # TODO: BuildMaster.loadChanges replaces the change_svc object, so we
+        # have to load it twice. Clean this up.
+        d = self.master.loadConfig(config_sender)
+        dr(d)
+
+        cm = self.master.change_svc
+        s1 = list(cm)[0]
+        port = self.master.slavePort._port.getHost().port
+
+        options = {'username': "alice",
+                   'master': "localhost:%d" % port,
+                   'files': ["foo.c"],
+                   }
+
+        d = runner.sendchange(options)
+        dr(d)
+
+        # now check that the change was received
+        self.failUnlessEqual(len(cm.changes), 1)
+        c = cm.changes.pop()
+        self.failUnlessEqual(c.who, "alice")
+        self.failUnlessEqual(c.files, ["foo.c"])
+        self.failUnlessEqual(c.comments, "")
+        self.failUnlessEqual(c.revision, None)
+
+        options['revision'] = "r123"
+        options['comments'] = "test change"
+
+        d = runner.sendchange(options)
+        dr(d)
+        self.failUnlessEqual(len(cm.changes), 1)
+        c = cm.changes.pop()
+        self.failUnlessEqual(c.who, "alice")
+        self.failUnlessEqual(c.files, ["foo.c"])
+        self.failUnlessEqual(c.comments, "test change")
+        self.failUnlessEqual(c.revision, "r123")
+
+        # test options['logfile'] by creating a temporary file
+        logfile = self.mktemp()
+        f = open(logfile, "wt")
+        f.write("longer test change")
+        f.close()
+        options['comments'] = None
+        options['logfile'] = logfile
+
+        d = runner.sendchange(options)
+        dr(d)
+        self.failUnlessEqual(len(cm.changes), 1)
+        c = cm.changes.pop()
+        self.failUnlessEqual(c.who, "alice")
+        self.failUnlessEqual(c.files, ["foo.c"])
+        self.failUnlessEqual(c.comments, "longer test change")
+        self.failUnlessEqual(c.revision, "r123")
+
+        # make sure that numeric revisions work too
+        options['logfile'] = None
+        del options['revision']
+        options['revision_number'] = 42
+
+        d = runner.sendchange(options)
+        dr(d)
+        self.failUnlessEqual(len(cm.changes), 1)
+        c = cm.changes.pop()
+        self.failUnlessEqual(c.who, "alice")
+        self.failUnlessEqual(c.files, ["foo.c"])
+        self.failUnlessEqual(c.comments, "")
+        self.failUnlessEqual(c.revision, 42)
+





More information about the Commits mailing list