def test_connected_receiver_receives_text(self): recv = Receiver() writer = WriteToSignal() writer.sig_write_received.connect(recv.capture_text) txt = "I expect to see this" writer.write(txt) QCoreApplication.processEvents() self.assertEqual(txt, recv.captured_txt)
def test_connected_receiver_receives_text(self): recv = Receiver() writer = WriteToSignal(sys.stdout) writer.sig_write_received.connect(recv.capture_text) txt = "I expect to see this" writer.write(txt) QCoreApplication.processEvents() self.assertEqual(txt, recv.captured_txt)
def test_connected_receiver_receives_text(self): with patch("sys.stdout.fileno", return_value=1) as mock_fileno: recv = Receiver() writer = WriteToSignal(sys.stdout) writer.sig_write_received.connect(recv.capture_text) txt = "I expect to see this" writer.write(txt) QCoreApplication.processEvents() self.assertEqual(txt, recv.captured_txt) mock_fileno.assert_called_once_with()
def test_connected_receiver_receives_text(self): with patch("sys.stdout") as mock_stdout: mock_stdout.fileno.return_value = -1 recv = Receiver() writer = WriteToSignal(mock_stdout) writer.sig_write_received.connect(recv.capture_text) txt = "I expect to see this" writer.write(txt) QCoreApplication.processEvents() self.assertEqual(txt, recv.captured_txt) mock_stdout.fileno.assert_called_once_with()
def __init__(self, parent): super(LogMessageDisplay, self).__init__(parent) # layout self.display = MessageDisplay(parent) layout = QHBoxLayout() layout.addWidget(self.display) self.setLayout(layout) self.setWindowTitle(self.get_plugin_title()) # output capture stdout_capture, stderr_capture = WriteToSignal(), WriteToSignal() stdout_capture.sig_write_received.connect(self.display.appendNotice) stderr_capture.sig_write_received.connect(self.display.appendError) self.stdout, self.stderr = stdout_capture, stderr_capture
def __init__(self, parent): super(LogMessageDisplay, self).__init__(parent) # layout self.display = MessageDisplay(text_font(), parent) layout = QHBoxLayout() layout.addWidget(self.display) self.setLayout(layout) self.setWindowTitle(self.get_plugin_title()) # output capture self.stdout = WriteToSignal(ORIGINAL_STDOUT) self.stdout.sig_write_received.connect(self.display.append_script_notice) self.stderr = WriteToSignal(ORIGINAL_STDERR) self.stderr.sig_write_received.connect(self.display.append_script_error)
def test_with_fileno_throw_AttributeError(self): def raise_UnsupportedOperation(): raise UnsupportedOperation with patch('sys.stdout') as mock_stdout: mock_stdout.fileno.side_effect = raise_UnsupportedOperation writer = WriteToSignal(mock_stdout) self.assertEqual(writer._original_out, None)
def test_with_fileno_not_defined(self): with patch('sys.stdout') as mock_stdout: del mock_stdout.fileno writer = WriteToSignal(mock_stdout) self.assertEqual(writer._original_out, None)
def test_run_without_output_present(self): with patch("sys.stdout") as mock_stdout: mock_stdout.fileno.return_value = -1 writer = WriteToSignal(mock_stdout) mock_stdout.fileno.assert_called_once_with() self.assertEqual(writer._original_out, None)
def test_run_with_output_present(self): with patch("sys.stdout.fileno", return_value=10) as mock_fileno: writer = WriteToSignal(sys.stdout) mock_fileno.assert_called_once_with() self.assertEqual(writer._original_out, sys.stdout)