コード例 #1
0
 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)
コード例 #2
0
 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)
コード例 #3
0
 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()
コード例 #4
0
 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()
コード例 #5
0
    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
コード例 #6
0
    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)
コード例 #7
0
    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)
コード例 #8
0
 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)
コード例 #9
0
 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)
コード例 #10
0
 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)