コード例 #1
0
ファイル: __init__.py プロジェクト: TheUncleKai/bbutils
    def exception(self, e: Exception):
        content = "An exception of type {0} occurred.".format(type(e).__name__)
        _message = Message(content=content, level="EXCEPTION")
        self.append(_message)

        content = "Arguments:\n{0!r}".format(e.args)
        _message = Message(content=content, level="EXCEPTION")
        self.append(_message)
        return
コード例 #2
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
コード例 #3
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
コード例 #4
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
コード例 #5
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
コード例 #6
0
ファイル: __init__.py プロジェクト: TheUncleKai/bbutils
    def traceback(self):

        ttype, value, tb = sys.exc_info()
        self.error("Uncaught exception")
        self.error("Type:  " + str(ttype))
        self.error("Value: " + str(value))

        lines = traceback.format_tb(tb)
        for line in lines:
            _message = Message(content=line, raw=True)
            self.append(_message)
        return
コード例 #7
0
    def test_constructor_01(self):
        message = Message()

        self.assertIsNotNone(message)
        self.assertIsNotNone(message.time)
        self.assertEqual(message.app, "")
        self.assertEqual(message.tag, "")
        self.assertEqual(message.content, "")
        self.assertEqual(message.level, "")
        self.assertEqual(message.raw, False)
        self.assertIsNone(message.progress)
        return
コード例 #8
0
ファイル: __init__.py プロジェクト: TheUncleKai/bbutils
    def append(self, item: Message):
        if self._level not in self._index:
            return

        level_list = self._index[self._level]

        if (item.level not in level_list) and (item.raw is False):
            return

        item.app = self._app

        # select output method: if threaded use buffer for output, if not print directly
        if self.state.use_thread is True:
            self._buffer.append(item)
        else:
            self._process(item)
        return
コード例 #9
0
    def test_constructor_02(self):
        progress = Progress(100, 0, None)
        message = Message(app="TOSS",
                          tag="TAGIT",
                          content="LILO",
                          level="HUH",
                          raw=True,
                          progress=progress)

        self.assertIsNotNone(message)
        self.assertIsNotNone(message.time)
        self.assertEqual(message.app, "TOSS")
        self.assertEqual(message.tag, "TAGIT")
        self.assertEqual(message.content, "LILO")
        self.assertEqual(message.level, "HUH")
        self.assertEqual(message.raw, True)
        self.assertIsNotNone(message.progress)
        self.assertEqual(message.progress, progress)
        return
コード例 #10
0
ファイル: console.py プロジェクト: TheUncleKai/bbutils
    def test_write_03(self):

        message = Message(app="TEST", level="INFORM", content="This is a test!")

        item = ConsoleWriter()
        item.open()
        item.stdout = SysWrite()

        item.write(message)

        write_called = item.stdout.write.called
        call = item.stdout.write.call_args_list[0]
        (args, kwargs) = call
        data = args[0]

        self.assertTrue(write_called)
        self.assertIn(message.app, data)
        self.assertIn(message.content, data)
        return
コード例 #11
0
ファイル: console.py プロジェクト: TheUncleKai/bbutils
    def test_clear_01(self):

        message = Message(app="TEST", content="This is a test!", raw=True)

        item = ConsoleWriter()
        item.open()
        item.stdout = SysWrite()

        item.write(message)
        item.clear()

        count = item.stdout.write.call_count
        write_called = item.stdout.write.called
        call = item.stdout.write.call_args_list[1]
        (args, kwargs) = call
        data = args[0]

        self.assertTrue(write_called)
        self.assertIn('\r', data)
        self.assertEqual(count, 2)
        return
コード例 #12
0
ファイル: console.py プロジェクト: TheUncleKai/bbutils
    def test_clear_02(self):

        message = Message(app="TEST", content="This is a test!", level="ERROR")

        item = ConsoleWriter()
        item.setup(error_index=["ERROR"])
        item.open()
        item.stderr = SysWrite()

        item.write(message)
        item.clear()

        count = item.stderr.write.call_count
        write_called = item.stderr.write.called
        call = item.stderr.write.call_args_list[1]
        (args, kwargs) = call
        data = args[0]

        self.assertTrue(write_called)
        self.assertIn('\r', data)
        self.assertEqual(count, 2)
        return
コード例 #13
0
ファイル: console.py プロジェクト: TheUncleKai/bbutils
    def test_write_04(self):

        message = Message(app="TEST", level="ERROR", content="This is a test!")

        item = ConsoleWriter()
        item.setup(error_index=["ERROR"])
        item.open()
        item.stderr = SysWrite()

        item.write(message)

        write_called = item.stderr.write.called
        call = item.stderr.write.call_args_list[0]
        (args, kwargs) = call
        data = args[0]

        print(data)

        self.assertTrue(write_called)
        self.assertIn(message.app, data)
        self.assertIn(message.content, data)
        return
コード例 #14
0
ファイル: __init__.py プロジェクト: TheUncleKai/bbutils
 def raw(self, content: str):
     _message = Message(content=content, raw=True)
     self.append(_message)
     return
コード例 #15
0
ファイル: __init__.py プロジェクト: TheUncleKai/bbutils
 def error(self, content: str):
     _message = Message(content=content, level="ERROR")
     self.append(_message)
     return
コード例 #16
0
ファイル: __init__.py プロジェクト: TheUncleKai/bbutils
 def debug3(self, tag: str, content: str):
     _message = Message(tag=tag, content=content, level="DEBUG3")
     self.append(_message)
     return
コード例 #17
0
ファイル: __init__.py プロジェクト: TheUncleKai/bbutils
 def warn(self, tag: str, content: str):
     _message = Message(tag=tag, content=content, level="WARN")
     self.append(_message)
     return
コード例 #18
0
ファイル: __init__.py プロジェクト: TheUncleKai/bbutils
 def inform(self, tag: str, content: str):
     _message = Message(tag=tag, content=content, level="INFORM")
     self.append(_message)
     return