Exemplo n.º 1
0
    def test_write_no_newline(self):
        wb = logging.WriterBase('a-writer', 'a-handle')
        self.patch_object(wb, 'format', name='mock_wb_format')
        self.patch_object(wb,
                          '_write_to_handle',
                          name='mock_wb__write_to_handle')
        self.mock_wb_format.return_value = 'formatted'

        wb.write(a='1', this='that', newline=False)

        self.mock_wb_format.assert_called_once_with(a='1', this='that')
        self.mock_wb__write_to_handle.assert_called_once_with('formatted',
                                                              newline=False)
Exemplo n.º 2
0
    def test_write_already_timestamp(self):
        wb = logging.WriterBase('a-writer', 'a-handle')
        self.patch_object(wb, 'format', name='mock_wb_format')
        self.patch_object(wb,
                          '_write_to_handle',
                          name='mock_wb__write_to_handle')
        self.mock_wb_format.return_value = 'formatted'
        ts = datetime.datetime(2021, 1, 2, 10, 21, 50)

        wb.write(a='1', this='that', timestamp=ts)

        self.mock_wb_format.assert_called_once_with(
            a='1', this='that', timestamp='2021-01-02T10:21:50')
        self.mock_wb__write_to_handle.assert_called_once_with('formatted',
                                                              newline=True)
Exemplo n.º 3
0
 def test__write_to_handle_no_newline(self):
     mock_handle = mock.Mock()
     wb = logging.WriterBase('a-writer', mock_handle)
     wb._write_to_handle('a message', newline=False)
     mock_handle.write.assert_called_once_with('a message')
Exemplo n.º 4
0
 def test__write_to_handle(self):
     mock_handle = mock.Mock()
     wb = logging.WriterBase('a-writer', mock_handle)
     wb._write_to_handle('a message')
     mock_handle.write.assert_has_calls(
         (mock.call('a message'), mock.call("\n")))
Exemplo n.º 5
0
 def test_format(self):
     wb = logging.WriterBase('a-writer', 'a-handle')
     with self.assertRaises(NotImplementedError):
         wb.format(this='that')