예제 #1
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)
예제 #2
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')