Exemplo n.º 1
0
 def test_search(self):
     screen = get_screen()
     y, x = screen.getmaxyx()
     lines = get_random_lines(300)
     lines1 = get_random_lines(3)
     prefix = lines[random.randint(y, 299)][:3]
     for i in range(3):
         lines.insert(random.randint(y, 299 + i), prefix + lines1[i][3:])
     indices = [ind for ind, line in enumerate(lines)
             if prefix in line]
     sl = ScrollableList(lines)
     ScreenManager.draw_all()
     commands.add([ord(c) for c in prefix])
     commands.add(ord('\n'))
     sl.handle_search()
     next_index = itertools.cycle(indices).next
     for i in range(10):
         index = next_index()
         self.assertEquals(sl.get_current_index(), index)
         self.assertTrue(lines[index] in map(screen.get_line, range(y)))
         sl.handle_keypress('n')
     sl.move_to_bottom()
     if prefix not in screen.get_line(-1):
         sl.handle_keypress('N')
     previous_index = itertools.cycle(reversed(indices)).next
     for i in range(10):
         index = previous_index()
         self.assertEquals(sl.get_current_index(), index)
         self.assertTrue(lines[index] in map(screen.get_line, range(y)))
         sl.handle_keypress('N')
Exemplo n.º 2
0
    def test_moving(self):
        lines = get_random_lines()
        sl = ScrollableList(lines)
        ScreenManager.draw_all()

        screen = get_screen()
        y, x = screen.getmaxyx()
        ind = sl.get_current_index

        self.assertEquals(ind(), 0)
        for i in range(y):
            self.assertEquals(screen.get_line(i), lines[i])
        sl.move_up()
        self.assertEquals(ind(), 0)

        sl.move_to_bottom()
        self.assertEquals(ind(), len(lines) - 1)
        sl.move_down()
        self.assertEquals(ind(), len(lines) - 1)
        self.assertEquals(screen.get_line(0), lines[-y])
        sl.move_to_top()
        self.assertEquals(ind(), 0)
        self.assertEquals(screen.get_line(-1), lines[y - 1])

        for i in range(len(lines)):
            sl.move_down()
        self.assertEquals(ind(), len(lines) - 1)
        self.assertEquals(screen.get_line(0), lines[-y])
        self.assertEquals(screen.get_line(-1), lines[-1])
        self._move_down_and_up(sl)
Exemplo n.º 3
0
    def test_title(self):
        screen = get_screen()
        y = 10
        screen.setmaxyx(y, 20)
        ta = TextArea()
        ta.minx = 10

        lines = [chr(i) for i in range(97, 96 + y)]
        ta.show_text('\n'.join(lines))
        self.assertEqual(screen.get_line(0), lines[0])
        title = ''
        while len(title) < 10:
            title += get_random_lines(1, 20)[0].replace(' ', '')
        title = title[:10]
        ta.set_title(title)
        ta.draw()
        self.assertEqual(screen.get_line(0), title)

        title *= 3
        ta.set_title(title)
        ta.draw()
        self.assertEqual(screen.get_line(0), '')

        screen.setmaxyx(y, 30)
        ScreenManager.resize()
        self.assertEqual(screen.get_line(0), title)
Exemplo n.º 4
0
    def test_scrolling(self):
        lines = get_random_lines()
        sl = ScrollableList(lines)
        ScreenManager.draw_all()
        screen = get_screen()
        y, x = screen.getmaxyx()

        ind = sl.get_current_index

        for i in range(len(lines) - y):
            sl.scroll_down()
            self.assertEquals(ind(), i + 1)
            self.assertEquals(screen.get_line(0), lines[i + 1])
        self.assertEquals(screen.get_line(-1), lines[-1])
        up = min(len(lines) - y, y)
        sl.scroll_screen_up()
        self.assertEquals(screen.get_line(-1), lines[-up-1])
Exemplo n.º 5
0
    def test_text(self):
        screen = get_screen()
        screen.setmaxyx(10, 20)
        ta = TextArea()
        ta.minx = 10

        lines = []
        # we need some lines longer than 10
        while not 0 < len([l for l in lines if len(l) > 10]) < 5:
            lines = get_random_lines(5, 15)

        def check():
            for index, line in enumerate(lines):
                self.assertEqual(screen.get_line(index), line)
        ta.show_text('\n'.join(lines))
        check()

        screen.setmaxyx(10, 10)
        ScreenManager.resize()
        nl = []
        for line in lines:
            nl += wrap(line, 10)
        lines = nl
        check()

        assert len(lines) < 10
        screen.setmaxyx(len(lines), 10)
        ScreenManager.resize()
        check()

        screen.setmaxyx(len(lines) - 1, 10)
        ScreenManager.resize()
        old, lines = lines, [''] * (len(lines) - 1)
        check()

        lines = old
        screen.setmaxyx(len(lines), 10)
        ScreenManager.resize()
        check()

        screen.setmaxyx(10, 9)
        ScreenManager.resize()
        lines = [''] * len(lines)
        check()
Exemplo n.º 6
0
    def test_resize(self):
        lines = get_random_lines()
        sl = ScrollableList(lines)
        ScreenManager.draw_all()

        screen = get_screen()
        y, x = maxyx = screen.getmaxyx()
        j = 0
        def resize():
            screen.setmaxyx(y, x)
            ScreenManager.resize()
            if not sl.hidden:
                self._move_down_and_up(sl)
                self._scroll_down_and_up(sl)
                if j % 2 == 0:
                    sl.move_to_bottom()
        while y > 1:
            y -= random.randint(1, 20)
            if y < 1:
                y = 1
            j += 1
            resize()
        while y < maxyx[0]:
            y += random.randint(1, 20)
            if y > maxyx[0]:
                y = maxyx[0]
            j -= 1
            resize()
        while x > 1:
            x -= random.randint(1, 20)
            if x < 1:
                x = 1
            j += 1
            resize()
        while x > maxyx[1]:
            x += random.randint(1, 20)
            if x > maxyx[1]:
                x = maxyx[1]
            j += 1
            resize()