(refs #557, #559) use tarfile to upload multiple files from the master
[buildbot.git] / buildbot / test / test_twisted.py
blob7b4f9bfb67d56b18130d31f35df61ae8c14fb84f
1 # -*- test-case-name: buildbot.test.test_twisted -*-
3 from twisted.trial import unittest
5 from buildbot import interfaces
6 from buildbot.steps.python_twisted import countFailedTests
7 from buildbot.steps.python_twisted import Trial, TrialTestCaseCounter
8 from buildbot.status import builder
10 noisy = 0
11 if noisy:
12 from twisted.python.log import startLogging
13 import sys
14 startLogging(sys.stdout)
16 out1 = """
17 -------------------------------------------------------------------------------
18 Ran 13 tests in 1.047s
21 """
23 out2 = """
24 -------------------------------------------------------------------------------
25 Ran 12 tests in 1.040s
27 FAILED (failures=1)
28 """
30 out3 = """
31 NotImplementedError
32 -------------------------------------------------------------------------------
33 Ran 13 tests in 1.042s
35 FAILED (failures=1, errors=1)
36 """
38 out4 = """
39 unparseable
40 """
42 out5 = """
43 File "/usr/home/warner/stuff/python/twisted/Twisted-CVS/twisted/test/test_defer.py", line 79, in testTwoCallbacks
44 self.fail("just because")
45 File "/usr/home/warner/stuff/python/twisted/Twisted-CVS/twisted/trial/unittest.py", line 21, in fail
46 raise AssertionError, message
47 AssertionError: just because
48 unparseable
49 """
51 out6 = """
52 ===============================================================================
53 SKIPPED: testProtocolLocalhost (twisted.flow.test.test_flow.FlowTest)
54 -------------------------------------------------------------------------------
55 XXX freezes, fixme
56 ===============================================================================
57 SKIPPED: testIPv6 (twisted.names.test.test_names.HostsTestCase)
58 -------------------------------------------------------------------------------
59 IPv6 support is not in our hosts resolver yet
60 ===============================================================================
61 EXPECTED FAILURE: testSlots (twisted.test.test_rebuild.NewStyleTestCase)
62 -------------------------------------------------------------------------------
63 Traceback (most recent call last):
64 File "/Users/buildbot/Buildbot/twisted/OSX-full2.3/Twisted/twisted/trial/unittest.py", line 240, in _runPhase
65 stage(*args, **kwargs)
66 File "/Users/buildbot/Buildbot/twisted/OSX-full2.3/Twisted/twisted/trial/unittest.py", line 262, in _main
67 self.runner(self.method)
68 File "/Users/buildbot/Buildbot/twisted/OSX-full2.3/Twisted/twisted/trial/runner.py", line 95, in runTest
69 method()
70 File "/Users/buildbot/Buildbot/twisted/OSX-full2.3/Twisted/twisted/test/test_rebuild.py", line 130, in testSlots
71 rebuild.updateInstance(self.m.SlottedClass())
72 File "/Users/buildbot/Buildbot/twisted/OSX-full2.3/Twisted/twisted/python/rebuild.py", line 114, in updateInstance
73 self.__class__ = latestClass(self.__class__)
74 TypeError: __class__ assignment: 'SlottedClass' object layout differs from 'SlottedClass'
75 ===============================================================================
76 FAILURE: testBatchFile (twisted.conch.test.test_sftp.TestOurServerBatchFile)
77 -------------------------------------------------------------------------------
78 Traceback (most recent call last):
79 File "/Users/buildbot/Buildbot/twisted/OSX-full2.3/Twisted/twisted/trial/unittest.py", line 240, in _runPhase
80 stage(*args, **kwargs)
81 File "/Users/buildbot/Buildbot/twisted/OSX-full2.3/Twisted/twisted/trial/unittest.py", line 262, in _main
82 self.runner(self.method)
83 File "/Users/buildbot/Buildbot/twisted/OSX-full2.3/Twisted/twisted/trial/runner.py", line 95, in runTest
84 method()
85 File "/Users/buildbot/Buildbot/twisted/OSX-full2.3/Twisted/twisted/conch/test/test_sftp.py", line 450, in testBatchFile
86 self.failUnlessEqual(res[1:-2], ['testDirectory', 'testRemoveFile', 'testRenameFile', 'testfile1'])
87 File "/Users/buildbot/Buildbot/twisted/OSX-full2.3/Twisted/twisted/trial/unittest.py", line 115, in failUnlessEqual
88 raise FailTest, (msg or '%r != %r' % (first, second))
89 FailTest: [] != ['testDirectory', 'testRemoveFile', 'testRenameFile', 'testfile1']
90 -------------------------------------------------------------------------------
91 Ran 1454 tests in 911.579s
93 FAILED (failures=2, skips=49, expectedFailures=9)
94 Exception exceptions.AttributeError: "'NoneType' object has no attribute 'StringIO'" in <bound method RemoteReference.__del__ of <twisted.spread.pb.RemoteReference instance at 0x27036c0>> ignored
95 """
97 class MyTrial(Trial):
98 def addTestResult(self, testname, results, text, logs):
99 self.results.append((testname, results, text, logs))
100 def addCompleteLog(self, name, log):
101 pass
103 class MyLogFile:
104 def __init__(self, text):
105 self.text = text
106 def getText(self):
107 return self.text
110 class Count(unittest.TestCase):
112 def count(self, total, failures=0, errors=0,
113 expectedFailures=0, unexpectedSuccesses=0, skips=0):
114 d = {
115 'total': total,
116 'failures': failures,
117 'errors': errors,
118 'expectedFailures': expectedFailures,
119 'unexpectedSuccesses': unexpectedSuccesses,
120 'skips': skips,
122 return d
124 def testCountFailedTests(self):
125 count = countFailedTests(out1)
126 self.assertEquals(count, self.count(total=13))
127 count = countFailedTests(out2)
128 self.assertEquals(count, self.count(total=12, failures=1))
129 count = countFailedTests(out3)
130 self.assertEquals(count, self.count(total=13, failures=1, errors=1))
131 count = countFailedTests(out4)
132 self.assertEquals(count, self.count(total=None))
133 count = countFailedTests(out5)
134 self.assertEquals(count, self.count(total=None))
136 class Counter(unittest.TestCase):
138 def setProgress(self, metric, value):
139 self.progress = (metric, value)
141 def testCounter(self):
142 self.progress = (None,None)
143 c = TrialTestCaseCounter()
144 c.setStep(self)
145 STDOUT = interfaces.LOG_CHANNEL_STDOUT
146 def add(text):
147 c.logChunk(None, None, None, STDOUT, text)
148 add("\n\n")
149 self.failUnlessEqual(self.progress, (None,None))
150 add("bogus line\n")
151 self.failUnlessEqual(self.progress, (None,None))
152 add("buildbot.test.test_config.ConfigTest.testBots ... [OK]\n")
153 self.failUnlessEqual(self.progress, ("tests", 1))
154 add("buildbot.test.test_config.ConfigTest.tes")
155 self.failUnlessEqual(self.progress, ("tests", 1))
156 add("tBuilders ... [OK]\n")
157 self.failUnlessEqual(self.progress, ("tests", 2))
158 # confirm alternative delimiters work too.. ptys seem to emit
159 # something different
160 add("buildbot.test.test_config.ConfigTest.testIRC ... [OK]\r\n")
161 self.failUnlessEqual(self.progress, ("tests", 3))
162 add("===============================================================================\n")
163 self.failUnlessEqual(self.progress, ("tests", 3))
164 add("buildbot.test.test_config.IOnlyLookLikeA.testLine ... [OK]\n")
165 self.failUnlessEqual(self.progress, ("tests", 3))
169 class Parse(unittest.TestCase):
170 def failUnlessIn(self, substr, string):
171 self.failUnless(string.find(substr) != -1)
173 def testParse(self):
174 t = MyTrial(build=None, workdir=".", testpath=None, testChanges=True)
175 t.results = []
176 log = MyLogFile(out6)
177 t.createSummary(log)
179 self.failUnlessEqual(len(t.results), 4)
180 r1, r2, r3, r4 = t.results
181 testname, results, text, logs = r1
182 self.failUnlessEqual(testname,
183 ("twisted", "flow", "test", "test_flow",
184 "FlowTest", "testProtocolLocalhost"))
185 self.failUnlessEqual(results, builder.SKIPPED)
186 self.failUnlessEqual(text, ['skipped'])
187 self.failUnlessIn("XXX freezes, fixme", logs)
188 self.failUnless(logs.startswith("SKIPPED:"))
189 self.failUnless(logs.endswith("fixme\n"))
191 testname, results, text, logs = r2
192 self.failUnlessEqual(testname,
193 ("twisted", "names", "test", "test_names",
194 "HostsTestCase", "testIPv6"))
195 self.failUnlessEqual(results, builder.SKIPPED)
196 self.failUnlessEqual(text, ['skipped'])
197 self.failUnless(logs.startswith("SKIPPED: testIPv6"))
198 self.failUnless(logs.endswith("IPv6 support is not in our hosts resolver yet\n"))
200 testname, results, text, logs = r3
201 self.failUnlessEqual(testname,
202 ("twisted", "test", "test_rebuild",
203 "NewStyleTestCase", "testSlots"))
204 self.failUnlessEqual(results, builder.SUCCESS)
205 self.failUnlessEqual(text, ['expected', 'failure'])
206 self.failUnless(logs.startswith("EXPECTED FAILURE: "))
207 self.failUnlessIn("\nTraceback ", logs)
208 self.failUnless(logs.endswith("layout differs from 'SlottedClass'\n"))
210 testname, results, text, logs = r4
211 self.failUnlessEqual(testname,
212 ("twisted", "conch", "test", "test_sftp",
213 "TestOurServerBatchFile", "testBatchFile"))
214 self.failUnlessEqual(results, builder.FAILURE)
215 self.failUnlessEqual(text, ['failure'])
216 self.failUnless(logs.startswith("FAILURE: "))
217 self.failUnlessIn("Traceback ", logs)
218 self.failUnless(logs.endswith("'testRenameFile', 'testfile1']\n"))