| | 1180 | def assertForwardsToSubunit(self, methodName, *args, **kwargs): |
| | 1181 | """ |
| | 1182 | Assert that 'methodName' on L{SubunitReporter} forwards to the |
| | 1183 | equivalent method on subunit. |
| | 1184 | |
| | 1185 | Checks that the return value from subunit is returned from the |
| | 1186 | L{SubunitReporter} and that the reporter writes the same data to its |
| | 1187 | stream as subunit does to its own. |
| | 1188 | |
| | 1189 | Assumes that the method on subunit has the same name as the method on |
| | 1190 | L{SubunitReporter}. |
| | 1191 | """ |
| | 1192 | stream = StringIO.StringIO() |
| | 1193 | subunitClient = reporter.TestProtocolClient(stream) |
| | 1194 | subunitReturn = getattr(subunitClient, methodName)(*args, **kwargs) |
| | 1195 | subunitOutput = stream.getvalue() |
| | 1196 | reporterReturn = getattr(self.result, methodName)(*args, **kwargs) |
| | 1197 | self.assertEqual(subunitReturn, reporterReturn) |
| | 1198 | self.assertEqual(subunitOutput, self.stream.getvalue()) |
| | 1199 | |
| | 1200 | |
| | 1244 | def test_doneDoesNothing(self): |
| | 1245 | """ |
| | 1246 | The subunit reporter doesn't need to print out a summary -- the stream |
| | 1247 | of results is everything. Thus, done() does nothing. |
| | 1248 | """ |
| | 1249 | self.result.done() |
| | 1250 | self.assertEqual('', self.stream.getvalue()) |
| | 1251 | |
| | 1252 | |
| | 1253 | def test_startTest_sends_subunit_startTest(self): |
| | 1254 | """ |
| | 1255 | SubunitReporter.startTest() sends the subunit 'startTest' message. |
| | 1256 | """ |
| | 1257 | self.assertForwardsToSubunit('startTest', self.test) |
| | 1258 | |
| | 1259 | |
| | 1260 | def test_stopTest_sends_subunit_stopTest(self): |
| | 1261 | """ |
| | 1262 | SubunitReporter.stopTest() sends the subunit 'stopTest' message. |
| | 1263 | """ |
| | 1264 | self.assertForwardsToSubunit('stopTest', self.test) |
| | 1265 | |
| | 1266 | |
| | 1267 | def test_addSuccess_sends_subunit_addSuccess(self): |
| | 1268 | """ |
| | 1269 | SubunitReporter.addSuccess() sends the subunit 'addSuccess' message. |
| | 1270 | """ |
| | 1271 | self.assertForwardsToSubunit('addSuccess', self.test) |
| | 1272 | |
| | 1273 | |
| | 1274 | def test_addSkip_sends_subunit_addSkip(self): |
| | 1275 | """ |
| | 1276 | SubunitReporter.addSkip() sends the subunit 'addSkip' message. |
| | 1277 | """ |
| | 1278 | self.assertForwardsToSubunit('addSkip', self.test, 'reason') |
| | 1279 | |
| | 1280 | |
| | 1281 | def test_addError_sends_subunit_addError(self): |
| | 1282 | """ |
| | 1283 | SubunitReporter.addError() sends the subunit 'addError' message. |
| | 1284 | """ |
| | 1285 | try: |
| | 1286 | 1 / 0 |
| | 1287 | except ZeroDivisionError: |
| | 1288 | error = sys.exc_info() |
| | 1289 | self.assertForwardsToSubunit('addError', self.test, error) |
| | 1290 | |
| | 1291 | |
| | 1292 | def test_addFailure_sends_subunit_addFailure(self): |
| | 1293 | """ |
| | 1294 | SubunitReporter.addFailure() sends the subunit 'addFailure' message. |
| | 1295 | """ |
| | 1296 | try: |
| | 1297 | self.fail('hello') |
| | 1298 | except self.failureException: |
| | 1299 | failure = sys.exc_info() |
| | 1300 | self.assertForwardsToSubunit('addFailure', self.test, failure) |
| | 1301 | |
| | 1302 | |
| | 1303 | def test_addUnexpectedSuccess_sends_subunit_addSuccess(self): |
| | 1304 | """ |
| | 1305 | SubunitReporter.addFailure() sends the subunit 'addSuccess' message, |
| | 1306 | since subunit doesn't model unexpected success. |
| | 1307 | """ |
| | 1308 | stream = StringIO.StringIO() |
| | 1309 | subunitClient = reporter.TestProtocolClient(stream) |
| | 1310 | subunitClient.addSuccess(self.test) |
| | 1311 | subunitOutput = stream.getvalue() |
| | 1312 | self.result.addUnexpectedSuccess(self.test, 'todo') |
| | 1313 | self.assertEqual(subunitOutput, self.stream.getvalue()) |
| | 1314 | |
| | 1315 | |
| | 1316 | |