Exemple #1
0
    def test_write_06(self):

        item = FileWriter()
        item.setup(text_space=20, filename="tests.log", append_data=True)

        item.open()
        item.file.write.side_effect = OSError

        m = Message(content="This is a test!", raw=True)
        item.write(m)

        # noinspection PyUnresolvedReferences
        write_called = item.file.write.called

        # noinspection PyUnresolvedReferences
        flush_called = item.file.flush.called

        # noinspection PyUnresolvedReferences
        call = item.file.write.call_args_list[0]
        (args, kwargs) = call
        data = args[0].decode("utf-8")

        self.assertTrue(write_called)
        self.assertFalse(flush_called)
        self.assertEqual(m.content, data)
        return
Exemple #2
0
    def test_write_04(self):

        item = FileWriter()
        item.setup(text_space=20, filename="tests.log", append_data=True)

        item.open()

        item.file.write.side_effect = OSError

        m = Message(app="TEST",
                    tag="RUN",
                    level="INFORM",
                    content="This is a test!")
        item.write(m)

        # noinspection PyUnresolvedReferences
        write_called = item.file.write.called

        # noinspection PyUnresolvedReferences
        flush_called = item.file.flush.called

        # noinspection PyUnresolvedReferences
        call = item.file.write.call_args_list[0]
        (args, kwargs) = call
        data = str(args[0])

        self.assertTrue(write_called)
        self.assertFalse(flush_called)
        self.assertIn(m.app, data)
        self.assertIn(m.level, data)
        self.assertIn(m.content, data)
        return