Ejemplo n.º 1
0
    def test_write_07(self):

        item = FileWriter()
        item.setup(text_space=20)

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

        self.assertRaises(ValueError, item.write, m)
        return
Ejemplo n.º 2
0
    def test_open_03(self):
        item = FileWriter()
        item.setup(text_space=20, filename="tests.log", append_data=True)

        check = item.open()

        self.assertIsNone(item.file)
        self.assertFalse(check)
        return
Ejemplo n.º 3
0
    def test_setup_01(self):

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

        self.assertNotEqual(item.filename, "")
        self.assertEqual(item.text_space, 20)
        self.assertIsNone(item.file)
        self.assertTrue(item.append_data)
        return
Ejemplo n.º 4
0
    def test_write_03(self):

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

        m = Message(app="TEST",
                    tag="RUN",
                    level="INFORM",
                    content="This is a test!")
        self.assertRaises(ValueError, item.write, m)
        return
Ejemplo n.º 5
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
Ejemplo n.º 6
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
Ejemplo n.º 7
0
    def test_setup_02(self):

        item = FileWriter()
        item.setup(text_space=20,
                   logname="run-tests",
                   logpath=os.getcwd(),
                   append_datetime=True)
        print(item.filename)

        self.assertNotEqual(item.filename, "")
        self.assertEqual(item.text_space, 20)
        self.assertIsNone(item.file)
        self.assertFalse(item.append_data)
        return
Ejemplo n.º 8
0
    def test_constructor(self):

        item = FileWriter()
        self.assertEqual(item.filename, "")
        self.assertEqual(item.text_space, 15)
        self.assertIsNone(item.file)
        self.assertFalse(item.append_data)
        return
Ejemplo n.º 9
0
    def test_setup_03(self):

        args = {
            "text_space": 20,
            "logname": "",
            "logpath": os.getcwd(),
            "append_datetime": True
        }

        item = FileWriter()
        self.assertRaises(ValueError, item.setup, **args)
        return
Ejemplo n.º 10
0
    def test_close_01(self):

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

        check1 = item.open()
        check2 = item.close()

        self.assertTrue(check1)
        self.assertTrue(check2)
        return
Ejemplo n.º 11
0
    def test_open_04(self):
        item = FileWriter()
        item.setup(text_space=20)

        self.assertRaises(ValueError, item.open)
        return
Ejemplo n.º 12
0
    def test_clear(self):

        item = FileWriter()
        item.clear()
        return