From c325859efc1d33644e0c7954e41af25cb95c1078 Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Fri, 3 Dec 2010 23:27:14 -0600 Subject: [PATCH] Use a NullTransport to fake out NetstringReceiver Twisted-10.2.0 expects a real transport for a NetstringReceiver, so give it something it can chew on. Fixes #1697 --- master/buildbot/status/builder.py | 17 ++++++++++ .../test_status_builder_LogFileProducer.py | 33 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 master/buildbot/test/unit/test_status_builder_LogFileProducer.py diff --git a/master/buildbot/status/builder.py b/master/buildbot/status/builder.py index f8c866fe7db..983b35ba21d 100644 --- a/master/buildbot/status/builder.py +++ b/master/buildbot/status/builder.py @@ -4,6 +4,7 @@ from twisted.python import log, runtime from twisted.persisted import styles from twisted.internet import reactor, defer, threads +import twisted.internet.interfaces from twisted.protocols import basic from buildbot.process.properties import Properties from buildbot.util import collections @@ -55,10 +56,26 @@ def worst_status(a, b): HEADER = interfaces.LOG_CHANNEL_HEADER ChunkTypes = ["stdout", "stderr", "header"] +class NullAddress(object): + "an address for NullTransport" + implements(twisted.internet.interfaces.IAddress) + +class NullTransport(object): + "a do-nothing transport to make NetstringReceiver happy" + implements(twisted.internet.interfaces.ITransport) + def write(self, data): raise NotImplementedError + def writeSequence(self, data): raise NotImplementedError + def loseConnection(self): pass + def getPeer(self): + return NullAddress + def getHost(self): + return NullAddress + class LogFileScanner(basic.NetstringReceiver): def __init__(self, chunk_cb, channels=[]): self.chunk_cb = chunk_cb self.channels = channels + self.makeConnection(NullTransport()) def stringReceived(self, line): channel = int(line[0]) diff --git a/master/buildbot/test/unit/test_status_builder_LogFileProducer.py b/master/buildbot/test/unit/test_status_builder_LogFileProducer.py new file mode 100644 index 00000000000..01d40b296fd --- /dev/null +++ b/master/buildbot/test/unit/test_status_builder_LogFileProducer.py @@ -0,0 +1,33 @@ +import mock +import cStringIO +from twisted.trial import unittest +from buildbot.status import builder + +from twisted.internet import defer, reactor +from twisted.python import log +from buildbot.test.util import changesource +from buildbot.changes import base + +class TestLogFileProducer(unittest.TestCase): + def make_static_logfile(self, contents): + "make a fake logfile with the given contents" + logfile = mock.Mock() + logfile.getFile = lambda : cStringIO.StringIO(contents) + logfile.waitUntilFinished = lambda : defer.succeed(None) # already finished + logfile.runEntries = [] + return logfile + + def test_getChunks_static_helloworld(self): + logfile = self.make_static_logfile("13:0hello world!,") + lfp = builder.LogFileProducer(logfile, mock.Mock()) + chunks = list(lfp.getChunks()) + self.assertEqual(chunks, [ (0, 'hello world!') ]) + + def test_getChunks_static_multichannel(self): + logfile = self.make_static_logfile("2:0a,3:1xx,2:0c,") + lfp = builder.LogFileProducer(logfile, mock.Mock()) + chunks = list(lfp.getChunks()) + self.assertEqual(chunks, [ (0, 'a'), (1, 'xx'), (0, 'c') ]) + + # Remainder of LogFileProduer has a wacky interface that's not + # well-defined, so it's not tested yet