Esempio n. 1
0
class ExactlyOneFullPage(unittest.TestCase):

    def setUp(self):
        self.area = ScrollArea(20, 20, 3)
        self.area.refuse = refuse_raise

    def testInit(self):
        expected = (20, 0, 20, 0, 20, 0, range(3,23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollDown(self):
        self.assertRaises(DoneScrolling, self.area.scroll, 20)

    def testScrollUp(self):
        self.assertRaises(DoneScrolling, self.area.scroll, -1)

    def testPageDown(self):
        self.assertRaises(DoneScrolling, self.area.page_down)

    def testPageUp(self):
        self.assertRaises(DoneScrolling, self.area.page_up)

    def testHome(self):
        self.assertRaises(DoneScrolling, self.area.home)

    def testEnd(self):
        self.area.end()
        self.assertRaises(DoneScrolling, self.area.end)
Esempio n. 2
0
 def resize(self):
     try:
         self.lines = format_tb(self.W - 1, self.traceback_)
         self.area = ScrollArea(self.H, len(self.lines), 0)
         self.draw()
     except:
         logger.critical(traceback.format_exc())
Esempio n. 3
0
class ExactlyOneFullPage(unittest.TestCase):
    def setUp(self):
        self.area = ScrollArea(20, 20, 3)
        self.area.refuse = refuse_raise

    def testInit(self):
        expected = (20, 0, 20, 0, 20, 0, range(3, 23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollDown(self):
        self.assertRaises(DoneScrolling, self.area.scroll, 20)

    def testScrollUp(self):
        self.assertRaises(DoneScrolling, self.area.scroll, -1)

    def testPageDown(self):
        self.assertRaises(DoneScrolling, self.area.page_down)

    def testPageUp(self):
        self.assertRaises(DoneScrolling, self.area.page_up)

    def testHome(self):
        self.assertRaises(DoneScrolling, self.area.home)

    def testEnd(self):
        self.area.end()
        self.assertRaises(DoneScrolling, self.area.end)
Esempio n. 4
0
 def resize(self):
     try:
         self.lines = format_tb(self.W-1, self.traceback_)
         self.area = ScrollArea(self.H, len(self.lines), 0)
         self.draw()
     except:
         logger.critical(traceback.format_exc())
Esempio n. 5
0
 def populate_result(self):
     """[Re]create just the result ScrollArea.
     """
     if self.selected == '':
         curresult = ()
     else:
         traceback_ = self.detail.data[self.selected][1]
         self.curresult = format_tb(self.c2[1], traceback_)
     self.result = ScrollArea( self.c1[0]+1
                             , len(self.curresult)
                             , self.toprows
                              )
Esempio n. 6
0
    def populate(self):
        """[Re]create the scroll area if needed.

        In order to retain the current page and selection, we only recreate the
        pane if its size parameters have changed.

        """

        args = {
            'numrows': self.c1[0] + 1,
            'numitems': len(self.summary),
            'toprow': self.toprows
        }

        if not self.listing:
            self.listing = ScrollArea(**args)
        else:
            for k, v in args.items():
                if getattr(self.listing, k) != v:
                    self.listing = ScrollArea(**args)
                    break
Esempio n. 7
0
    def populate(self):
        """[Re]create both ScrollAreas.

        In order to retain the current page and selection, we only recreate
        the tests pane if the parameters of this area have changed.

        """

        args = { 'numrows': self.c1[0]+1
               , 'numitems':len(self.detail)
               , 'toprow': self.toprows
                }

        if not self.tests:
            self.tests = ScrollArea(**args)
        else:
            for k,v in args.items():
                if getattr(self.tests, k) != v:
                    self.tests = ScrollArea(**args)
                    break

        self.populate_result()
Esempio n. 8
0
class PageDownBorking:  #(unittest.TestCase):
    def setUp(self):
        self.area = ScrollArea(4, 5, 3)
        self.area.refuse = refuse_raise

    def testInit(self):
        expected = (4, 0, 5, 0, 4, 0)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPageDown(self):
        self.area.page_down()
        expected = (4, 0, 5, 4, 5, 4)
        actual = self.area.stat()
        self.assertEqual(expected, actual)
        self.assertRaises(DoneScrolling, self.area.page_down)

    def testPageDownThenScrollUp(self):
        self.area.page_down()
        self.area.scroll(-1)
        expected = (4, 0, 5, 3, 5, 3)
        actual = self.area.stat()
        self.assertEqual(expected, actual)
Esempio n. 9
0
class PageDownBorking:#(unittest.TestCase):

    def setUp(self):
        self.area = ScrollArea(4, 5, 3)
        self.area.refuse = refuse_raise

    def testInit(self):
        expected = (4, 0, 5, 0, 4, 0)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPageDown(self):
        self.area.page_down()
        expected = (4, 0, 5, 4, 5, 4)
        actual = self.area.stat()
        self.assertEqual(expected, actual)
        self.assertRaises(DoneScrolling, self.area.page_down)

    def testPageDownThenScrollUp(self):
        self.area.page_down()
        self.area.scroll(-1)
        expected = (4, 0, 5, 3, 5, 3)
        actual = self.area.stat()
        self.assertEqual(expected, actual)
Esempio n. 10
0
class TwoAndAHalfPageListing(unittest.TestCase):
    def setUp(self):
        #wheeee!
        self.area = ScrollArea(20, 50, 3)
        self.area.refuse = refuse_pass

    def testInit(self):
        expected = (20, 0, 50, 0, 20, 0, [3, 4, 5, 6, 7, 8, 9, 10, 11])
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    # scroll_one
    # ==========

    def testScrollOne(self):
        self.area.scroll_one()
        expected = (20, 1, 50, 0, 20, 1, range(3, 12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollDownThenUp(self):
        self.area.scroll_one()
        self.area.scroll_one(up=True)
        expected = (20, 0, 50, 0, 20, 0, range(3, 12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    # scroll
    # ======

    def testScroll(self):
        self.area.scroll(1)
        expected = (20, 1, 50, 0, 20, 1, range(3, 12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollToEdgeOfScreen(self):
        self.area.scroll(19)
        expected = (20, 19, 50, 0, 20, 19, range(3, 12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollJustPastEdgeOfScreen(self):
        self.area.scroll(20)
        expected = (20, 19, 50, 1, 21, 20, range(3, 12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollWellPastEdgeOfScreen(self):
        self.area.scroll(25)
        expected = (20, 19, 50, 6, 26, 25, range(5, 14))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollToEdgeOfList(self):
        self.area.scroll(50)
        expected = (20, 19, 50, 30, 50, 49, range(15, 23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollJustPastEdgeOfList(self):
        self.area.scroll(51)
        expected = (20, 19, 50, 30, 50, 49, range(15, 23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollWellPastEdgeOfList(self):
        self.area.scroll(1000)
        expected = (20, 19, 50, 30, 50, 49, range(15, 23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollTooFarDownTriggersRefusal(self):
        self.area.refuse = refuse_raise
        self.assertRaises(DoneScrolling, self.area.scroll, 1000)

    # scroll up

    def testScrollAllTheWayDownAndThenUpToEdgeOfList(self):
        self.area.scroll(50)
        expected = (20, 19, 50, 30, 50, 49, range(15, 23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

        self.area.scroll(-50)
        expected = (20, 0, 50, 0, 20, 0, range(3, 12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollAllTheWayDownAndThenUpJustPastEdgeOfList(self):
        self.area.scroll(50)
        expected = (20, 19, 50, 30, 50, 49, range(15, 23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

        self.area.scroll(-51)
        expected = (20, 0, 50, 0, 20, 0, range(3, 12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollAllTheWayDownAndThenUpWellPastEdgeOfList(self):
        self.area.scroll(50)
        expected = (20, 19, 50, 30, 50, 49, range(15, 23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

        self.area.scroll(-1000)
        expected = (20, 0, 50, 0, 20, 0, range(3, 12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollTooFarUpTriggersRefusal(self):
        self.area.refuse = refuse_raise
        self.assertRaises(DoneScrolling, self.area.scroll, -1000)

    # page_down
    # =========

    def testPageDown(self):
        self.area.page_down()
        expected = (20, 0, 50, 20, 40, 20, range(11, 20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPageDownFullThenPartial(self):
        self.area.page_down()
        self.area.page_down()
        expected = (20, 0, 50, 40, 50, 40, range(19, 23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPageDownFullThenPartialThenFinal(self):
        self.area.page_down()
        self.area.page_down()
        self.area.page_down()
        expected = (20, 0, 50, 49, 50, 49, range(22, 23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPageDownCursorStaysPut(self):
        self.area.cursor = 7
        self.area.page_down()
        expected = (20, 7, 50, 20, 40, 27, range(11, 20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    # page_up
    # =======
    # Each starts by scrolling all the way down.

    def testPageUp(self):
        self.area.scroll(50)
        self.area.page_up()
        expected = (20, 19, 50, 10, 30, 29, range(7, 16))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPageUpFullThenPartial(self):
        self.area.scroll(50)
        self.area.page_up()
        self.area.page_up()
        #expected = (20, 19, 50, 0, 20, 19, range(3,12))
        expected = (20, 0, 50, 0, 20, 0, range(3, 12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPageUpCursorStaysPut(self):
        self.area.scroll(50)
        self.area.cursor = 7
        self.area.page_up()
        expected = (20, 7, 50, 10, 30, 17, range(7, 16))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    # combined
    # ========

    def testPageDownIntoPartialThenUp(self):
        self.area.page_down()
        self.area.page_down()
        self.area.page_up()
        expected = (20, 0, 50, 20, 40, 20, range(11, 20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    # home/end
    # ========

    def testHome(self):
        self.area.scroll(50)
        self.area.home()
        expected = (20, 0, 50, 0, 20, 0, range(3, 12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testEnd(self):
        self.area.end()
        expected = (20, 19, 50, 30, 50, 49, range(15, 23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)
Esempio n. 11
0
class HalfPageListing(unittest.TestCase):

    def setUp(self):
        self.area = ScrollArea(20, 10, 3)
        self.area.refuse = refuse_pass

    def testInit(self):
        expected = (20, 0, 10, 0, 10, 0, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)


    # scroll_one
    # ==========

    def testScrollOne(self):
        self.area.scroll_one()
        expected = (20, 1, 10, 0, 10, 1, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollDownThenUp(self):
        self.area.scroll_one()
        self.area.scroll_one(up=True)
        expected = (20, 0, 10, 0, 10, 0, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)


    # scroll
    # ======

    def testScroll(self):
        self.area.scroll(1)
        expected = (20, 1, 10, 0, 10, 1, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollToEdgeOfScreen(self):
        self.area.scroll(19)
        expected = (20, 9, 10, 0, 10, 9, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollJustPastEdgeOfScreen(self):
        self.area.scroll(20)
        expected = (20, 9, 10, 0, 10, 9, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollWellPastEdgeOfScreen(self):
        self.area.scroll(25)
        expected = (20, 9, 10, 0, 10, 9, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollToEdgeOfList(self):
        self.area.scroll(9)
        expected = (20, 9, 10, 0, 10, 9, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollJustPastEdgeOfList(self):
        self.area.scroll(11)
        expected = (20, 9, 10, 0, 10, 9, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollWellPastEdgeOfList(self):
        self.area.scroll(1000)
        expected = (20, 9, 10, 0, 10, 9, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollTooFarDownTriggersRefusal(self):
        self.area.refuse = refuse_raise
        self.assertRaises(DoneScrolling, self.area.scroll, 1000)


    # scroll up

    def testScrollAllTheWayDownAndThenUpToEdgeOfList(self):
        self.area.scroll(9)
        self.area.scroll(-9)
        expected = (20, 0, 10, 0, 10, 0, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollAllTheWayDownAndThenUpJustPastEdgeOfList(self):
        self.area.scroll(9)
        self.area.scroll(-10)
        expected = (20, 0, 10, 0, 10, 0, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollAllTheWayDownAndThenUpWellPastEdgeOfList(self):
        self.area.scroll(9)
        self.area.scroll(-1000)
        expected = (20, 0, 10, 0, 10, 0, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollTooFarUpTriggersRefusal(self):
        self.area.refuse = refuse_raise
        self.assertRaises(DoneScrolling, self.area.scroll, -1000)
Esempio n. 12
0
 def setUp(self):
     self.area = ScrollArea(20, 10, 3)
     self.area.refuse = refuse_pass
Esempio n. 13
0
class TwoAndAHalfPageListing(unittest.TestCase):

    def setUp(self):
        #wheeee!
        self.area = ScrollArea(20, 50, 3)
        self.area.refuse = refuse_pass

    def testInit(self):
        expected = (20, 0, 50, 0, 20, 0, [3, 4, 5, 6, 7, 8, 9, 10, 11])
        actual = self.area.stat()
        self.assertEqual(expected, actual)


    # scroll_one
    # ==========

    def testScrollOne(self):
        self.area.scroll_one()
        expected = (20, 1, 50, 0, 20, 1, range(3,12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollDownThenUp(self):
        self.area.scroll_one()
        self.area.scroll_one(up=True)
        expected = (20, 0, 50, 0, 20, 0, range(3,12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)


    # scroll
    # ======

    def testScroll(self):
        self.area.scroll(1)
        expected = (20, 1, 50, 0, 20, 1, range(3,12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollToEdgeOfScreen(self):
        self.area.scroll(19)
        expected = (20, 19, 50, 0, 20, 19, range(3,12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollJustPastEdgeOfScreen(self):
        self.area.scroll(20)
        expected = (20, 19, 50, 1, 21, 20, range(3,12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollWellPastEdgeOfScreen(self):
        self.area.scroll(25)
        expected = (20, 19, 50, 6, 26, 25, range(5,14))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollToEdgeOfList(self):
        self.area.scroll(50)
        expected = (20, 19, 50, 30, 50, 49, range(15,23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollJustPastEdgeOfList(self):
        self.area.scroll(51)
        expected = (20, 19, 50, 30, 50, 49, range(15,23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollWellPastEdgeOfList(self):
        self.area.scroll(1000)
        expected = (20, 19, 50, 30, 50, 49, range(15,23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollTooFarDownTriggersRefusal(self):
        self.area.refuse = refuse_raise
        self.assertRaises(DoneScrolling, self.area.scroll, 1000)


    # scroll up

    def testScrollAllTheWayDownAndThenUpToEdgeOfList(self):
        self.area.scroll(50)
        expected = (20, 19, 50, 30, 50, 49, range(15,23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

        self.area.scroll(-50)
        expected = (20, 0, 50, 0, 20, 0, range(3,12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollAllTheWayDownAndThenUpJustPastEdgeOfList(self):
        self.area.scroll(50)
        expected = (20, 19, 50, 30, 50, 49, range(15,23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

        self.area.scroll(-51)
        expected = (20, 0, 50, 0, 20, 0, range(3,12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollAllTheWayDownAndThenUpWellPastEdgeOfList(self):
        self.area.scroll(50)
        expected = (20, 19, 50, 30, 50, 49, range(15,23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

        self.area.scroll(-1000)
        expected = (20, 0, 50, 0, 20, 0, range(3,12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollTooFarUpTriggersRefusal(self):
        self.area.refuse = refuse_raise
        self.assertRaises(DoneScrolling, self.area.scroll, -1000)


    # page_down
    # =========

    def testPageDown(self):
        self.area.page_down()
        expected = (20, 0, 50, 20, 40, 20, range(11,20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPageDownFullThenPartial(self):
        self.area.page_down()
        self.area.page_down()
        expected = (20, 0, 50, 40, 50, 40, range(19,23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPageDownFullThenPartialThenFinal(self):
        self.area.page_down()
        self.area.page_down()
        self.area.page_down()
        expected = (20, 0, 50, 49, 50, 49, range(22,23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPageDownCursorStaysPut(self):
        self.area.cursor = 7
        self.area.page_down()
        expected = (20, 7, 50, 20, 40, 27, range(11,20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)


    # page_up
    # =======
    # Each starts by scrolling all the way down.

    def testPageUp(self):
        self.area.scroll(50)
        self.area.page_up()
        expected = (20, 19, 50, 10, 30, 29, range(7,16))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPageUpFullThenPartial(self):
        self.area.scroll(50)
        self.area.page_up()
        self.area.page_up()
        #expected = (20, 19, 50, 0, 20, 19, range(3,12))
        expected = (20, 0, 50, 0, 20, 0, range(3,12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPageUpCursorStaysPut(self):
        self.area.scroll(50)
        self.area.cursor = 7
        self.area.page_up()
        expected = (20, 7, 50, 10, 30, 17, range(7,16))
        actual = self.area.stat()
        self.assertEqual(expected, actual)


    # combined
    # ========

    def testPageDownIntoPartialThenUp(self):
        self.area.page_down()
        self.area.page_down()
        self.area.page_up()
        expected = (20, 0, 50, 20, 40, 20, range(11,20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)


    # home/end
    # ========

    def testHome(self):
        self.area.scroll(50)
        self.area.home()
        expected = (20, 0, 50, 0, 20, 0, range(3,12))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testEnd(self):
        self.area.end()
        expected = (20, 19, 50, 30, 50, 49, range(15,23))
        actual = self.area.stat()
        self.assertEqual(expected, actual)
Esempio n. 14
0
 def setUp(self):
     #wheeee!
     self.area = ScrollArea(20, 50, 3)
     self.area.refuse = refuse_pass
Esempio n. 15
0
 def setUp(self):
     #wheeee!
     self.area = ScrollArea(20, 50, 3)
     self.area.refuse = refuse_pass
Esempio n. 16
0
class HalfPageListing(unittest.TestCase):
    def setUp(self):
        self.area = ScrollArea(20, 10, 3)
        self.area.refuse = refuse_pass

    def testInit(self):
        expected = (20, 0, 10, 0, 10, 0, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    # scroll_one
    # ==========

    def testScrollOne(self):
        self.area.scroll_one()
        expected = (20, 1, 10, 0, 10, 1, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollDownThenUp(self):
        self.area.scroll_one()
        self.area.scroll_one(up=True)
        expected = (20, 0, 10, 0, 10, 0, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    # scroll
    # ======

    def testScroll(self):
        self.area.scroll(1)
        expected = (20, 1, 10, 0, 10, 1, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollToEdgeOfScreen(self):
        self.area.scroll(19)
        expected = (20, 9, 10, 0, 10, 9, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollJustPastEdgeOfScreen(self):
        self.area.scroll(20)
        expected = (20, 9, 10, 0, 10, 9, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollWellPastEdgeOfScreen(self):
        self.area.scroll(25)
        expected = (20, 9, 10, 0, 10, 9, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollToEdgeOfList(self):
        self.area.scroll(9)
        expected = (20, 9, 10, 0, 10, 9, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollJustPastEdgeOfList(self):
        self.area.scroll(11)
        expected = (20, 9, 10, 0, 10, 9, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollWellPastEdgeOfList(self):
        self.area.scroll(1000)
        expected = (20, 9, 10, 0, 10, 9, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollTooFarDownTriggersRefusal(self):
        self.area.refuse = refuse_raise
        self.assertRaises(DoneScrolling, self.area.scroll, 1000)

    # scroll up

    def testScrollAllTheWayDownAndThenUpToEdgeOfList(self):
        self.area.scroll(9)
        self.area.scroll(-9)
        expected = (20, 0, 10, 0, 10, 0, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollAllTheWayDownAndThenUpJustPastEdgeOfList(self):
        self.area.scroll(9)
        self.area.scroll(-10)
        expected = (20, 0, 10, 0, 10, 0, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollAllTheWayDownAndThenUpWellPastEdgeOfList(self):
        self.area.scroll(9)
        self.area.scroll(-1000)
        expected = (20, 0, 10, 0, 10, 0, None)
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testScrollTooFarUpTriggersRefusal(self):
        self.area.refuse = refuse_raise
        self.assertRaises(DoneScrolling, self.area.scroll, -1000)
Esempio n. 17
0
 def setUp(self):
     self.area = ScrollArea(20, 50, 0)
     self.area.refuse = refuse_raise
Esempio n. 18
0
 def setUp(self):
     self.area = ScrollArea(4, 5, 3)
     self.area.refuse = refuse_raise
Esempio n. 19
0
 def setUp(self):
     self.area = ScrollArea(20, 10, 3)
     self.area.refuse = refuse_pass
Esempio n. 20
0
class PageDownMultiplePages(unittest.TestCase):

    def setUp(self):
        self.area = ScrollArea(20, 50, 0)
        self.area.refuse = refuse_raise


    # cursor == 0

    def testOneRowShowing(self):
        self.area.start = 49
        self.area.end_ = 50
        self.assertRaises(DoneScrolling, self.area.page_down)
        expected = (20, 0, 50, 49, 50, 49, range(19,20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testTwoRowsShowing(self):
        self.area.start = 48
        self.area.end_ = 50
        self.assertRaises(DoneScrolling, self.area.page_down)
        expected = (20, 0, 50, 49, 50, 49, range(19,20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPartialPageShowing(self):
        self.area.start = 30
        self.area.end_ = 50
        self.assertRaises(DoneScrolling, self.area.page_down)
        expected = (20, 0, 50, 49, 50, 49, range(19,20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testExactlyOnePageShowing(self):
        self.area.start = 30
        self.area.end_ = 50
        self.assertRaises(DoneScrolling, self.area.page_down)
        expected = (20, 0, 50, 49, 50, 49, range(19,20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testOneRowTillLastPage(self):
        self.area.start = 29
        self.area.end_ = 49
        self.area.page_down()
        expected = (20, 0, 50, 49, 50, 49, range(19,20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testSeveralRowsTillLastPage(self):
        self.area.start = 24
        self.area.end_ = 44
        self.area.page_down()
        expected = (20, 0, 50, 44, 50, 44, range(17,20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testExactlyOnePageTillLastPage(self):
        self.area.start = 10
        self.area.end_ = 30
        self.area.page_down()
        expected = (20, 0, 50, 30, 50, 30, range(12,20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)


    # cursor != 0

    def testCursorExactlyOnePageTillLastPage(self):
        self.area.cursor = 1
        self.area.start = 10
        self.area.end_ = 30
        self.area.page_down()
        expected = (20, 1, 50, 30, 50, 31, range(12,20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testExactlyOnePageShowingCursorAtBottom(self):
        self.area.cursor = 20
        self.area.start = 30
        self.area.end_ = 50
        self.assertRaises(DoneScrolling, self.area.page_down)
        expected = (20, 0, 50, 49, 50, 49, range(19,20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)
Esempio n. 21
0
 def setUp(self):
     self.area = ScrollArea(4, 5, 3)
     self.area.refuse = refuse_raise
Esempio n. 22
0
class ErrorScreen(BaseScreen):
    """Display a traceback within curses.
    """
    def __init__(self, screen, traceback_):
        """Takes the screen where the error occured and the traceback.
        """
        self.screen = screen
        self.colors = screen.colors
        self.blocks = screen.blocks
        self.traceback_ = traceback_
        self.win = self.screen.win
        self.win.clear()
        self.win.refresh()

    # BaseScreen contracts
    # ====================

    ui_chars = (ord('q'), curses.KEY_UP, curses.KEY_DOWN, curses.KEY_LEFT,
                curses.KEY_PPAGE, curses.KEY_NPAGE, curses.KEY_BACKSPACE)

    def resize(self):
        try:
            self.lines = format_tb(self.W - 1, self.traceback_)
            self.area = ScrollArea(self.H, len(self.lines), 0)
            self.draw()
        except:
            logger.critical(traceback.format_exc())

    def react(self, c):
        try:
            if c in (ord('q'), curses.KEY_BACKSPACE, ascii.BS, ascii.ESC,
                     curses.KEY_LEFT):
                return self.screen
            elif c == curses.KEY_UP:  # up
                self.area.move_cursor(0)
                self.area.scroll(-1)
            elif c == curses.KEY_DOWN:  # down
                self.area.move_cursor(self.area.numrows - 1)
                self.area.scroll(1)
            elif c == curses.KEY_PPAGE:  # page up
                self.area.page_up()
            elif c == curses.KEY_NPAGE:  # page down
                self.area.page_down()
            self.draw()
        except:
            logger.critical(traceback.format_exc())

    # Writes
    # ======

    def draw(self):

        # Clear the screen and then draw our rows.
        # ========================================

        self.win.clear()
        self.win.refresh()
        for index, rownum in self.area:
            self.win.addstr(rownum, 0, self.lines[index])

        # Continuation indicators
        # =======================

        color = self.colors.BLUE

        if self.area.start > 0:
            c = curses.ACS_UARROW
        else:
            c = ord(' ')
        self.win.addch(0, self.W, c, color)

        if self.area.end_ < self.area.numitems:
            c = curses.ACS_LANTERN
        else:
            c = ord(' ')
        self.win.addch(self.H - 1, self.W, c, color)

        # Commit
        # ======

        self.win.refresh()
Esempio n. 23
0
class PageDownMultiplePages(unittest.TestCase):
    def setUp(self):
        self.area = ScrollArea(20, 50, 0)
        self.area.refuse = refuse_raise

    # cursor == 0

    def testOneRowShowing(self):
        self.area.start = 49
        self.area.end_ = 50
        self.assertRaises(DoneScrolling, self.area.page_down)
        expected = (20, 0, 50, 49, 50, 49, range(19, 20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testTwoRowsShowing(self):
        self.area.start = 48
        self.area.end_ = 50
        self.assertRaises(DoneScrolling, self.area.page_down)
        expected = (20, 0, 50, 49, 50, 49, range(19, 20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testPartialPageShowing(self):
        self.area.start = 30
        self.area.end_ = 50
        self.assertRaises(DoneScrolling, self.area.page_down)
        expected = (20, 0, 50, 49, 50, 49, range(19, 20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testExactlyOnePageShowing(self):
        self.area.start = 30
        self.area.end_ = 50
        self.assertRaises(DoneScrolling, self.area.page_down)
        expected = (20, 0, 50, 49, 50, 49, range(19, 20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testOneRowTillLastPage(self):
        self.area.start = 29
        self.area.end_ = 49
        self.area.page_down()
        expected = (20, 0, 50, 49, 50, 49, range(19, 20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testSeveralRowsTillLastPage(self):
        self.area.start = 24
        self.area.end_ = 44
        self.area.page_down()
        expected = (20, 0, 50, 44, 50, 44, range(17, 20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testExactlyOnePageTillLastPage(self):
        self.area.start = 10
        self.area.end_ = 30
        self.area.page_down()
        expected = (20, 0, 50, 30, 50, 30, range(12, 20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    # cursor != 0

    def testCursorExactlyOnePageTillLastPage(self):
        self.area.cursor = 1
        self.area.start = 10
        self.area.end_ = 30
        self.area.page_down()
        expected = (20, 1, 50, 30, 50, 31, range(12, 20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)

    def testExactlyOnePageShowingCursorAtBottom(self):
        self.area.cursor = 20
        self.area.start = 30
        self.area.end_ = 50
        self.assertRaises(DoneScrolling, self.area.page_down)
        expected = (20, 0, 50, 49, 50, 49, range(19, 20))
        actual = self.area.stat()
        self.assertEqual(expected, actual)
Esempio n. 24
0
 def setUp(self):
     self.area = ScrollArea(20, 50, 0)
     self.area.refuse = refuse_raise
Esempio n. 25
0
class ErrorScreen(BaseScreen):
    """Display a traceback within curses.
    """

    def __init__(self, screen, traceback_):
        """Takes the screen where the error occured and the traceback.
        """
        self.screen = screen
        self.colors = screen.colors
        self.blocks = screen.blocks
        self.traceback_ = traceback_
        self.win = self.screen.win
        self.win.clear()
        self.win.refresh()


    # BaseScreen contracts
    # ====================

    ui_chars = ( ord('q')
               , curses.KEY_UP
               , curses.KEY_DOWN
               , curses.KEY_LEFT
               , curses.KEY_PPAGE
               , curses.KEY_NPAGE
               , curses.KEY_BACKSPACE
                )

    def resize(self):
        try:
            self.lines = format_tb(self.W-1, self.traceback_)
            self.area = ScrollArea(self.H, len(self.lines), 0)
            self.draw()
        except:
            logger.critical(traceback.format_exc())

    def react(self, c):
        try:
            if c in ( ord('q')
                    , curses.KEY_BACKSPACE
                    , ascii.BS
                    , ascii.ESC
                    , curses.KEY_LEFT
                     ):
                return self.screen
            elif c == curses.KEY_UP:    # up
                self.area.move_cursor(0)
                self.area.scroll(-1)
            elif c == curses.KEY_DOWN:  # down
                self.area.move_cursor(self.area.numrows-1)
                self.area.scroll(1)
            elif c == curses.KEY_PPAGE: # page up
                self.area.page_up()
            elif c == curses.KEY_NPAGE: # page down
                self.area.page_down()
            self.draw()
        except:
            logger.critical(traceback.format_exc())


    # Writes
    # ======

    def draw(self):

        # Clear the screen and then draw our rows.
        # ========================================

        self.win.clear()
        self.win.refresh()
        for index, rownum in self.area:
            self.win.addstr(rownum,0,self.lines[index])


        # Continuation indicators
        # =======================

        color = self.colors.BLUE

        if self.area.start > 0:
            c = curses.ACS_UARROW
        else:
            c = ord(' ')
        self.win.addch(0,self.W,c,color)

        if self.area.end_ < self.area.numitems:
            c = curses.ACS_LANTERN
        else:
            c = ord(' ')
        self.win.addch(self.H-1,self.W,c,color)


        # Commit
        # ======

        self.win.refresh()