def test_simple_render_status(): class Obj: name = 'toto' msg = StatusMessage("Coucou {name}", {'name': lambda: Obj.name}) assert msg.txt == "Coucou toto" Obj.name = 'titi' build_lines(msg, 100, True, 10)[0] assert msg.txt == "Coucou titi"
def build_new_message(self, message: BaseMessage, clean: bool = True, timestamp: bool = False, nick_size: int = 10) -> int: """ Take one message, build it and add it to the list Return the number of lines that are built for the given message. """ lines = build_lines( message, self.width, timestamp=timestamp, nick_size=nick_size ) if self.lock: self.lock_buffer.extend(lines) else: self.built_lines.extend(lines) if not lines or not lines[0]: return 0 if isinstance(message, Message) and message.highlight: self.highlights.append(lines[0]) self.nb_of_highlights_after_separator += 1 log.debug("Number of highlights after separator is now %s", self.nb_of_highlights_after_separator) if clean: while len(self.built_lines) > self.lines_nb_limit: self.built_lines.pop(0) return len(lines)
def modify_message(self, old_id, message) -> None: """ Find a message, and replace it with a new one (instead of rebuilding everything in order to correct a message) """ with_timestamps = config.get('show_timestamps') nick_size = config.get('max_nick_length') for i in range(len(self.built_lines) - 1, -1, -1): current = self.built_lines[i] if current is not None and current.msg.identifier == old_id: index = i while ( index >= 0 and current is not None and current.msg.identifier == old_id ): self.built_lines.pop(index) index -= 1 if index >= 0: current = self.built_lines[index] index += 1 lines = build_lines( message, self.width, timestamp=with_timestamps, nick_size=nick_size ) for line in lines: self.built_lines.insert(index, line) index += 1 break
def test_simple_build_basemsg(): msg = BaseMessage(txt='coucou') line = build_lines(msg, 100, True, 10)[0] assert (line.start_pos, line.end_pos) == (0, 6)
def test_simple_render_separator(): line = build_lines(None, 100, True, 10)[0] assert line is None
def test_simple_render_xmllog(): msg = XMLLog(txt='coucou', incoming=True) line = build_lines(msg, 100, True, 10)[0] assert (line.start_pos, line.end_pos) == (0, 6)
def test_simple_render_message(): msg = Message(txt='coucou', nickname='toto') line = build_lines(msg, 100, True, 10)[0] assert (line.start_pos, line.end_pos) == (0, 6)