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
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
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
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
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
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
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
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
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
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
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
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
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
def raw(self, content: str): _message = Message(content=content, raw=True) self.append(_message) return
def error(self, content: str): _message = Message(content=content, level="ERROR") self.append(_message) return
def debug3(self, tag: str, content: str): _message = Message(tag=tag, content=content, level="DEBUG3") self.append(_message) return
def warn(self, tag: str, content: str): _message = Message(tag=tag, content=content, level="WARN") self.append(_message) return
def inform(self, tag: str, content: str): _message = Message(tag=tag, content=content, level="INFORM") self.append(_message) return