Skip to content
Browse files

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
  • Loading branch information...
djmitche committed Dec 4, 2010
1 parent 9df8259 commit c325859efc1d33644e0c7954e41af25cb95c1078
@@ -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 import Properties
from buildbot.util import collections
@@ -55,10 +56,26 @@ def worst_status(a, b):
ChunkTypes = ["stdout", "stderr", "header"]

class NullAddress(object):
"an address for NullTransport"

class NullTransport(object):
"a do-nothing transport to make NetstringReceiver happy"
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

def stringReceived(self, line):
channel = int(line[0])
@@ -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

1 comment on commit c325859


This comment has been minimized.

Copy link
Member Author

commented on c325859 Dec 13, 2010

we're glad to help, dreamfly912. You can also try the buildbot-devel list for problems like this.

Please sign in to comment.
You can’t perform that action at this time.