[Buildbot-commits] buildbot/buildbot/test test_slavecommand.py,1.8,1.9

Brian Warner warner at users.sourceforge.net
Thu Apr 21 19:53:35 UTC 2005


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

Modified Files:
	test_slavecommand.py 
Log Message:
(Shell): test both with and without PTYs, and make sure that command output
is properly interleaved in the with-PTY case. I think the without-PTY test
should pass on windows, where we never use PTYs anyway.


Index: test_slavecommand.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/test/test_slavecommand.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- test_slavecommand.py	20 Apr 2005 19:32:46 -0000	1.8
+++ test_slavecommand.py	21 Apr 2005 19:53:32 -0000	1.9
@@ -2,7 +2,7 @@
 
 from twisted.trial import unittest
 from twisted.internet import reactor, defer
-from twisted.python import util
+from twisted.python import util, runtime
 
 noisy = False
 if noisy:
@@ -26,13 +26,13 @@
     pass
         
 class FakeSlaveBuilder:
-    usePTY = True # TODO: this probably won't work on non-posix
-
-    def __init__(self, d):
+    def __init__(self, d, usePTY):
         self.updates = []
         self.failure = None
         self.deferred = d
         self.basedir = findDir()
+        self.usePTY = usePTY
+
     def startBuild(self):
         self.build = FakeSlaveBuild()
     def commandComplete(self, dummy):
@@ -64,11 +64,12 @@
             signal.signal(signal.SIGCHLD, self.sigchldHandler)
 
 
-class SlaveCommandTestCase(SignalMixin, unittest.TestCase):
+class Shell(SignalMixin, unittest.TestCase):
+    usePTY = False
 
     def setUp(self):
         d = defer.Deferred()
-        self.builder = FakeSlaveBuilder(d)
+        self.builder = FakeSlaveBuilder(d, self.usePTY)
         d.addCallback(self.callback)
         self.failed = None
         self.results = None
@@ -101,10 +102,26 @@
                 got += r[which]
         return got
 
-    def checkStdout(self, expected):
-        expected = expected.replace("\n", "\r\n", 1000) # PTY does this
-        got = self.getfile('stdout')
-        self.assertEquals(got, expected)
+    def checkOutput(self, expected):
+        """
+        @type  expected: list of (streamname, contents) tuples
+        @param expected: the expected output
+        """
+        if self.usePTY:
+            # PTYs change the line ending. I'm not sure why.
+            expected = [(stream, contents.replace("\n", "\r\n", 1000))
+                        for (stream, contents) in expected]
+            # PTYs merge stdout+stderr into a single stream
+            expected = [('stdout', contents)
+                        for (stream, contents) in expected]
+        # now merge everything into one string per stream
+        streams = {}
+        for (stream, contents) in expected:
+            streams[stream] = streams.get(stream, "") + contents
+        for (stream, contents) in streams.items():
+            got = self.getfile(stream)
+            self.assertEquals(got, contents)
+
     def getrc(self):
         self.failUnless(self.results[-1].has_key('rc'))
         got = self.results[-1]['rc']
@@ -118,8 +135,8 @@
         args = {'command': cmd, 'workdir': '.', 'timeout': 5}
         failed = self.doTest(SlaveShellCommand, args)
         self.failIf(failed)
-        self.checkStdout("this is stdout\n"
-                         "this is stderr\n")
+        self.checkOutput([('stdout', "this is stdout\n"),
+                          ('stderr', "this is stderr\n")])
         self.checkrc(0)
 
     def testShell2(self):
@@ -127,8 +144,8 @@
         args = {'command': cmd, 'workdir': '.', 'timeout': 5}
         failed = self.doTest(SlaveShellCommand, args)
         self.failIf(failed)
-        self.checkStdout("this is stdout\n"
-                         "this is stderr\n")
+        self.checkOutput([('stdout', "this is stdout\n"),
+                          ('stderr', "this is stderr\n")])
         self.checkrc(1)
 
     def testShell3(self):
@@ -137,10 +154,10 @@
                 'env': {'EMIT_TEST': "envtest"}, 'timeout': 5}
         failed = self.doTest(SlaveShellCommand, args)
         self.failIf(failed)
-        self.checkStdout("this is stdout\n"
-                         "this is stderr\n"
-                         "EMIT_TEST: envtest\n"
-                         )
+        self.checkOutput([('stdout', "this is stdout\n"),
+                          ('stderr', "this is stderr\n"),
+                          ('stdout', "EMIT_TEST: envtest\n"),
+                          ])
         self.checkrc(0)
 
     def testShell4(self):
@@ -148,8 +165,8 @@
         args = {'command': cmd, 'workdir': "subdir", 'timeout': 5}
         failed = self.doTest(SlaveShellCommand, args)
         self.failIf(failed)
-        self.checkStdout("this is stdout in subdir\n"
-                         "this is stderr\n")
+        self.checkOutput([('stdout', "this is stdout in subdir\n"),
+                          ('stderr', "this is stderr\n")])
         self.checkrc(0)
 
     def testShellZ(self):
@@ -158,7 +175,7 @@
         failed = self.doTest(SlaveShellCommand, args)
         self.failIf(failed)
         self.failUnless(self.getrc() != 0)
-        got = self.getfile('stdout')
+        got = self.getfile('stdout') + self.getfile('stderr')
         self.failUnless(re.search(r'no such file', got, re.I) # unix
                         or re.search(r'cannot find the path specified',
                                      got, re.I) # win32
@@ -167,3 +184,9 @@
     # todo: interrupt(), kill process
 
     # todo: twisted-specific command tests
+
+
+if runtime.platformType == 'posix':
+    # test with PTYs also
+    class ShellPTY(Shell):
+        usePTY = True





More information about the Commits mailing list