def test_message_methods(self): class Message(object): level = 'INFO' for listeners in [Listeners([]), LibraryListeners()]: listeners.log_message(Message) listeners.message(Message)
def test_calling_listener_methods_fails(self): listenres = Listeners([('test_listeners.InvalidListenerOldStyle', [])]) for name, args in [('start_suite', [SuiteMock()]), ('end_suite', [SuiteMock()]), ('start_test', [TestMock()]), ('end_test', [TestMock()]), ('start_keyword', [KwMock()]), ('end_keyword', [KwMock()]), ('output_file', ['log', '/path']), ('close', [])]: getattr(listenres, name)(*args)
def test_start_and_end_methods(self): class ModelStub: IF_ELSE_ROOT = 'IF/ELSE ROOT' type = 'xxx' for listeners in [Listeners([]), LibraryListeners()]: for name in dir(listeners): if name.startswith(('start_', 'end_')): model = ModelStub() if name.endswith('keyword') else None method = getattr(listeners, name) method(model)
def test_some_methods_implemented(self): class MyListener(object): ROBOT_LISTENER_API_VERSION = 2 def end_suite(self, suite): pass libs = LibraryListeners() libs.new_suite_scope() libs.register([MyListener()], None) for listeners in [Listeners([MyListener()]), libs]: listeners.start_suite(None) assert_raises(AttributeError, listeners.end_suite, None)
def setUp(self): self.listeners = Listeners([self.listener_name]) self.capturer = OutputCapturer()
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)
def test_start_and_end_methods(self): for listeners in [Listeners([]), LibraryListeners()]: for name in dir(listeners): if name.startswith(('start_', 'end_')): method = getattr(listeners, name) method(None)
def setUp(self): self.listeners = Listeners([(self.listener_name, [])]) self.listener = self.listeners._listeners[0] self.capturer = OutputCapturer()
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)