def test_no_ut_refresh(self): '''Ensure deep_refresh is updating nested window screen location ''' scroll_win = ScrollWindow(WindowArea(60, 70, 0, 0, scrollable_columns=75), color_theme=ColorTheme(force_bw=True)) scroll_win.window = MockInnerWin() scroll_win.area.lower_right_y = 20 scroll_win.area.lower_right_x = 20 myscroll = ScrollWindow(WindowArea(10, 10, 0, 0, scrollable_columns=15), color_theme=ColorTheme(force_bw=True)) myscroll.window = MockInnerWin() myscroll.area.lower_right_y = 16 myscroll.area.lower_right_x = 18 scroll_win.objects.append(myscroll) scroll_win.area.y_loc = 3 scroll_win.area.x_loc = 5 abs_y = 12 abs_x = 15 scroll_win.latest_yx = (abs_y, abs_x) scroll_win.no_ut_refresh() self.assertEquals(myscroll.latest_yx[0], scroll_win.area.y_loc + abs_y) self.assertEquals(myscroll.latest_yx[1], scroll_win.area.x_loc + abs_x)
def test_horiz_scrollbar_created(self): '''Ensure horizontal scrollbar is created or not appropriately''' scroll_win = ScrollWindow(WindowArea(70, 70, 0, 0, scrollable_columns=75), color_theme=ColorTheme(force_bw=True)) self.assertTrue(scroll_win.get_use_horiz_scroll_bar()) scroll_win = ScrollWindow(WindowArea(70, 70, 0, 0, scrollable_columns=69), color_theme=ColorTheme(force_bw=True)) self.assertFalse(scroll_win.get_use_horiz_scroll_bar())
def test_vert_scrollbar_created(self): '''Ensure vertical scrollbar is created or not appropriately''' scroll_win = ScrollWindow(WindowArea(70, 70, 0, 0, scrollable_lines=75), color_theme=ColorTheme(force_bw=True)) self.assertTrue(scroll_win.get_use_vert_scroll_bar()) scroll_win = ScrollWindow(WindowArea(70, 70, 0, 0, scrollable_lines=70), color_theme=ColorTheme(force_bw=True)) self.assertFalse(scroll_win.get_use_vert_scroll_bar())
def __init__(self, initscr, screen_list, theme=None, force_bw=False): '''Set the theme, and call reset to initialize the terminal to prepare for the first screen. ''' if theme is not None: self.theme = theme else: self.theme = ColorTheme(force_bw=force_bw) self.screen_list = screen_list self.initscr = initscr self.default_cursor_pos = (initscr.getmaxyx()[0] - 1, 0) self.cursor_pos = self.default_cursor_pos self.footer = None self.header = None self._cur_header_text = None self.central_area = None self.popup_win = None self.error_line = None self._active_win = None self.continue_action = None self.back_action = None self.help_action = None self.quit_action = None self.actions = None self.reset()
def test_scroll_down_up_arrow(self): '''Test to scroll down and up with arrow key ''' lines = 4 extra_lines = 9 scroll_win = ScrollWindow(WindowArea(lines, 70, 0, 0, scrollable_lines=lines + extra_lines), color_theme=ColorTheme(force_bw=True)) scroll_win.active_object = None self.assertTrue(scroll_win.at_top()) key = scroll_win.on_arrow_key(curses.KEY_DOWN) self.assertEqual(key, None) self.assertFalse(scroll_win.at_top()) key = scroll_win.on_arrow_key(curses.KEY_UP) self.assertEqual(key, None) self.assertTrue(scroll_win.at_top()) key = scroll_win.on_arrow_key(curses.KEY_UP) self.assertEqual(key, curses.KEY_UP) self.assertTrue(scroll_win.at_top()) scroll_win.scroll(extra_lines-2) self.assertFalse(scroll_win.at_bottom()) scroll_win.on_arrow_key(curses.KEY_DOWN) self.assertTrue(scroll_win.at_bottom()) scroll_win.scroll(-(extra_lines-2)) self.assertFalse(scroll_win.at_top()) scroll_win.on_arrow_key(curses.KEY_UP) self.assertTrue(scroll_win.at_top())
def test_scroll_right_left_arrow(self): '''Test to scroll right and left with arrow key ''' cols = 3 extra_cols = 5 scroll_win = ScrollWindow(WindowArea(10, cols, 0, 0, scrollable_columns=cols+extra_cols), color_theme=ColorTheme(force_bw=True)) scroll_win.active_object = None self.assertTrue(scroll_win.at_left()) key = scroll_win.on_arrow_key(curses.KEY_RIGHT) self.assertEqual(key, None) self.assertFalse(scroll_win.at_left()) key = scroll_win.on_arrow_key(curses.KEY_LEFT) self.assertEqual(key, None) self.assertTrue(scroll_win.at_left()) key = scroll_win.on_arrow_key(curses.KEY_LEFT) self.assertEqual(key, curses.KEY_LEFT) self.assertTrue(scroll_win.at_left()) scroll_win.scroll(columns=extra_cols-2) self.assertFalse(scroll_win.at_left()) self.assertFalse(scroll_win.at_right()) scroll_win.on_arrow_key(curses.KEY_RIGHT) self.assertTrue(scroll_win.at_right()) scroll_win.scroll(columns=-(extra_cols-2)) self.assertFalse(scroll_win.at_left()) self.assertFalse(scroll_win.at_right()) scroll_win.on_arrow_key(curses.KEY_LEFT) self.assertTrue(scroll_win.at_left())
def test_active_object(self): '''Test that arrow key changes active object''' lines = 4 extra_lines = 9 scroll_win = ScrollWindow(WindowArea(lines, 70, 0, 0, scrollable_lines=lines + extra_lines), color_theme=ColorTheme(force_bw=True)) scroll_win.active_object = 0 myobj0 = MockEditField() myobj0.area = MockInnerWin() myobj0.area.y_loc = 1 myobj0.active = True myobj1 = MockEditField() myobj1.area = MockInnerWin() myobj1.area.y_loc = 3 myobj1.active = False scroll_win.objects.append(myobj0) scroll_win.objects.append(myobj1) key = scroll_win.on_arrow_key(curses.KEY_DOWN) self.assertEquals(key, None) self.assertEquals(scroll_win.active_object, 1)
def test_scroll_no_args(self): '''Test that scroll called with no args throws ValueError''' scroll_win = ScrollWindow(WindowArea(70, 70, 0, 0, scrollable_lines=75), color_theme=ColorTheme(force_bw=True)) self.assertTrue(scroll_win.get_use_vert_scroll_bar()) self.assertEquals(scroll_win.current_line[0], 0) self.assertRaises(ValueError, scroll_win.scroll)
def test_scroll_to_right(self): '''Test to scroll multiple columns to right of scrollarea''' cols = 70 extra_cols = 5 scroll_win = ScrollWindow(WindowArea(70, cols, 0, 0, scrollable_columns=cols+extra_cols), color_theme=ColorTheme(force_bw=True)) scroll_win.scroll(scroll_to_column=5) self.assertTrue(scroll_win.at_right())
def test_scroll_one_col(self): '''Test to scroll one column ''' scroll_win = ScrollWindow(WindowArea(70, 70, 0, 0, scrollable_columns=75), color_theme=ColorTheme(force_bw=True)) self.assertTrue(scroll_win.get_use_horiz_scroll_bar()) self.assertEquals(scroll_win.current_line[1], 0) scroll_win.scroll(columns=1) self.assertEquals(scroll_win.current_line[1], 1)
def test_scroll_to_bottom(self): '''Test to scroll multiple lines to bottom of scrollarea''' lines = 70 extra_lines = 5 scroll_win = ScrollWindow(WindowArea(lines, 70, 0, 0, scrollable_lines=lines + extra_lines), color_theme=ColorTheme(force_bw=True)) scroll_win.scroll(scroll_to_line=5) self.assertTrue(scroll_win.at_bottom())
def test_scroll_past_left(self): '''Test to scroll past left, should end up at left ''' cols = 70 extra_cols = 5 scroll_win = ScrollWindow(WindowArea(70, cols, 0, 0, scrollable_columns=cols+extra_cols), color_theme=ColorTheme(force_bw=True)) self.assertTrue(scroll_win.at_left()) scroll_win.scroll(columns=-3) self.assertTrue(scroll_win.at_left())
def test_scroll_past_top(self): '''Test to scroll past top, should end up at top ''' lines = 70 extra_lines = 5 scroll_win = ScrollWindow(WindowArea(lines, 70, 0, 0, scrollable_lines=lines + extra_lines), color_theme=ColorTheme(force_bw=True)) self.assertTrue(scroll_win.at_top()) scroll_win.scroll(lines=-3) self.assertTrue(scroll_win.at_top())
def test_act_obj_indexerr_not_edge(self): '''Test arrow key, active object, IndexError, not at edge''' lines = 4 extra_lines = 9 scroll_win = ScrollWindow(WindowArea(lines, 70, 0, 0, scrollable_lines=lines + extra_lines), color_theme=ColorTheme(force_bw=True)) scroll_win.active_object = 0 scroll_win.objects.append(object()) key = scroll_win.on_arrow_key(curses.KEY_DOWN) self.assertEquals(scroll_win.current_line[0], 1) self.assertEquals(key, None)
def setUp(self): '''unit test set up Sets several functions to call do_nothing to allow test execution in non-curses environment. Original functions are saved so they can be later restored in tearDown. ''' self.inner_window_init_win = InnerWindow._init_win self.disk_window_init_win = DiskWindow._init_win self.inner_window_set_color = InnerWindow.set_color InnerWindow._init_win = do_nothing InnerWindow.set_color = do_nothing DiskWindow._init_win = do_nothing self.disk_win = DiskWindow(WindowArea(70, 70, 0, 0), DiskInfo(), color_theme=ColorTheme(force_bw=True), window=MockAll()) self.edit_field = MockEditField() self.part_field = MockPartField() self.part_info = MockPartInfo() self.inner_win = MockInnerWin() self.disk_win.objects = [] self.part_field.objects = []