class TestListeners(unittest.TestCase): listener_name = 'test_listeners.ListenAll' stat_message = 'stat message' def setUp(self): self.listeners = Listeners([self.listener_name]) self.capturer = OutputCapturer() def test_start_suite(self): self.listeners.start_suite(SuiteMock()) self._assert_output("SUITE START: suitemock 'somedoc'") def test_start_test(self): self.listeners.start_test(TestMock()) self._assert_output("TEST START: testmock 'cod' foo, bar") def test_start_keyword(self): self.listeners.start_keyword(KwMock()) self._assert_output("KW START: kwmock ['a1', 'a2']") def test_end_keyword(self): self.listeners.end_keyword(KwMock()) self._assert_output("KW END: PASS") def test_end_test(self): self.listeners.end_test(TestMock()) self._assert_output('TEST END: FAIL Expected failure') def test_end_suite(self): self.listeners.end_suite(SuiteMock()) self._assert_output('SUITE END: PASS ' + self.stat_message) def test_output_file(self): self.listeners.output_file('output', 'path/to/output') self._assert_output('Output: path/to/output') def test_log_file(self): self.listeners.output_file('log', 'path/to/log') self._assert_output('Log: path/to/log') def test_report_file(self): self.listeners.output_file('report', 'path/to/report') self._assert_output('Report: path/to/report') def test_debug_file(self): self.listeners.output_file('debug', 'path/to/debug') self._assert_output('Debug: path/to/debug') def test_xunit_file(self): self.listeners.output_file('XUnit', 'path/to/xunit') self._assert_output('XUnit: path/to/xunit') def test_close(self): self.listeners.close() self._assert_output('Closing...') def _assert_output(self, expected): stdout, stderr = self.capturer._release() assert_equal(stderr, '') assert_equal(stdout.rstrip(), expected)
class _BaseListenerTest: def setUp(self): self.listeners = Listeners([(self.listener_name, [])]) self.listener = self.listeners._listeners[0] self.capturer = OutputCapturer() def test_start_suite(self): self.listeners.start_suite(SuiteMock()) self._assert_output("SUITE START: suitemock 'somedoc'") def test_start_test(self): self.listeners.start_test(TestMock()) self._assert_output("TEST START: testmock 'cod' foo, bar") def test_start_keyword(self): self.listeners.start_keyword(KwMock()) self._assert_output("KW START: kwmock ['a1', 'a2']") def test_end_keyword(self): self.listeners.end_keyword(KwMock()) self._assert_output("KW END: PASS") def test_end_test(self): self.listeners.end_test(TestMock()) self._assert_output('TEST END: FAIL Expected failure') def test_end_suite(self): self.listeners.end_suite(SuiteMock()) self._assert_output('SUITE END: PASS full message') def test_output_file(self): self.listeners.output_file('output', 'path/to/output') self._assert_output('Output: path/to/output') def test_log_file(self): self.listeners.output_file('log', 'path/to/log') self._assert_output('Log: path/to/log') def test_report_file(self): self.listeners.output_file('report', 'path/to/report') self._assert_output('Report: path/to/report') def test_summary_file(self): self.listeners.output_file('summary', 'path/to/summary') self._assert_output('Summary: path/to/summary') def test_debug_file(self): self.listeners.output_file('debug', 'path/to/debug') self._assert_output('Debug: path/to/debug') def test_close(self): self.listeners.close() self._assert_output('Closing...') def _assert_output(self, expected): stdout, stderr = self.capturer.release() assert_equals(stderr, '') assert_equals(stdout.rstrip(), expected)