Beispiel #1
0
def scrollingTest(screen):
    users = [
        User("NatOsaka", Role("Contributor")),
        User("mitch", Role("Dev")),
        User("E5ten", Role("User"))
    ]

    maxyx = screen.getmaxyx()
    screen.box()
    screen.refresh()
    win = curses.newwin(maxyx[0] - 2, maxyx[1] - 2, 1, 1)
    win.keypad(True)
    win_maxyx = win.getmaxyx()
    ft = FormattedText(win_maxyx[1], 100)

    with open("tests/loremSample.txt", 'r') as f:
        for line in f:
            ft.addMessage(Message(random.choice(users), line.rstrip()))
        ft.addMessage(Message(users[0], "Last message"))
        lines = ft.getLines()
        line_offset = 0
        if len(lines) > win_maxyx[0]:
            line_offset = len(lines) - win_maxyx[0]
        while True:
            win.clear()
            text_offset = 0
            for idx, line in enumerate(lines[line_offset:line_offset +
                                             win_maxyx[0]]):
                if line.isFirst:
                    win.addstr(idx, 0, line.user + ": ", curses.A_BOLD)
                    text_offset = len(line.user) + 2
                win.move(idx, text_offset)
                for idx, token in enumerate(line.words):
                    try:
                        if len(line.words
                               ) - 1 != idx and token.attrs == line.words[
                                   idx + 1].attrs:
                            win.addstr(token.content + " ", token.attrs)
                        else:
                            win.addstr(token.content, token.attrs)
                    except:
                        logging.info(token.content)
                        sys.exit(0)
                win.refresh()
            ch = win.getch()
            if chr(ch) == 'q':
                break
            elif ch == curses.KEY_UP:
                line_offset -= 1
            elif ch == curses.KEY_DOWN:
                line_offset += 1
            elif ch == curses.KEY_PPAGE:
                line_offset -= 5
            elif ch == curses.KEY_NPAGE:
                line_offset += 5
            if line_offset < 0:
                line_offset = 0
            elif line_offset > (len(lines) - win_maxyx[0]):
                line_offset = len(lines) - win_maxyx[0]
Beispiel #2
0
    async def test_get_one(self):
        expected = BrokerHandlerEntry(1, "fooReply", 0,
                                      FakeModel("test1").avro_bytes)
        await self._insert_one(
            Message("fooReply", 0,
                    FakeModel("test1").avro_bytes))
        await self._insert_one(
            Message("fooReply", 0,
                    FakeModel("test2").avro_bytes))

        observed = await self.handler.get_one()

        self._assert_equal_entries(expected, observed)
Beispiel #3
0
 async def _fn():
     await self._insert_one(
         Message("fooReply", 0,
                 FakeModel("test1").avro_bytes))
     await self._insert_one(
         Message("fooReply", 0,
                 FakeModel("test2").avro_bytes))
     await sleep(0.5)
     await self._insert_one(
         Message("fooReply", 0,
                 FakeModel("test3").avro_bytes))
     await self._insert_one(
         Message("fooReply", 0,
                 FakeModel("test4").avro_bytes))
    async def test_handle_single_message(self):
        mock = MagicMock(side_effect=self.consumer.enqueue)

        self.consumer.enqueue = mock
        await self.consumer.handle_single_message(
            Message(topic="AddOrder", partition=0, value=b"test"))

        self.assertEqual(1, mock.call_count)
        self.assertEqual(call("AddOrder", 0, b"test"), mock.call_args)
    def setUp(self) -> None:
        super().setUp()

        self.client = _ConsumerClient(
            [Message(topic="AddOrder", partition=0, value=b"test")])
        # noinspection PyTypeChecker
        self.consumer = BrokerConsumer(
            topics={f"{self.config.service.name}Reply"},
            broker=self.config.broker,
            client=self.client,
            **self.config.broker.queue._asdict(),
        )
def formattingTest(screen):
    curses.cbreak()
    curses.noecho()
    screen.keypad(True)

    ui = CursesUI()
    ui.run(screen)
    user = User("mitch", Role("moderator"))
    maxyx = screen.getmaxyx()
    win = curses.newwin(maxyx[0] - 2, maxyx[1] - 2, 1, 1)
    win.keypad(True)
    win_maxyx = win.getmaxyx()
    for f in [open("tests/test.txt", 'r'), open("tests/test2.txt", 'r')]:
        ft = FormattedText(win_maxyx[1], colors=ui.colors)
        win.clear()
        text_offset = 0
        contents = f.read()
        ft.addMessage(Message(user, contents))
        lines = ft.getLines()
        line_offset = 0
        if len(lines) > win_maxyx[0]:
            line_offset = len(lines) - win_maxyx[0]
        for idx, line in enumerate(lines[line_offset:line_offset +
                                         win_maxyx[0]]):
            if line.isFirst:
                win.addstr(idx, 0, line.user + ": ")
                text_offset = len(line.user) + 2
            win.move(idx, text_offset)
            for idy, word in enumerate(line.words):
                if len(line.words) - 1 != idy and word.attrs == line.words[
                        idy + 1].attrs:
                    win.addstr(word.content + " ", word.attrs)
                else:
                    win.addstr(word.content, word.attrs)
                    win.addstr(" ", curses.A_NORMAL)
            win.refresh()
            line_offset = 0
            if len(lines) > win_maxyx[0]:
                line_offset = len(lines) - win_maxyx[0]
        win.getch()
 def __init__(self, messages=None):
     if messages is None:
         messages = [
             Message(topic="TicketAdded", partition=0, value=bytes())
         ]
     self.messages = messages