def test_cursor_position(): screen = Screen(10, 10) # a) testing that we expect 1-indexed values screen.cursor_position(5, 10) assert (screen.cursor.y, screen.cursor.x) == (4, 9) # b) but (0, 0) is also accepted and should be the same as (1, 1) screen.cursor_position(0, 10) assert (screen.cursor.y, screen.cursor.x) == (0, 9) # c) moving outside the margins constrains to within the screen # bounds screen.cursor_position(100, 5) assert (screen.cursor.y, screen.cursor.x) == (9, 4) screen.cursor_position(5, 100) assert (screen.cursor.y, screen.cursor.x) == (4, 9) # d) DECOM on screen.set_margins(5, 9) screen.set_mode(mo.DECOM) screen.cursor_position() assert (screen.cursor.y, screen.cursor.x) == (4, 0) screen.cursor_position(2, 0) assert (screen.cursor.y, screen.cursor.x) == (5, 0) # Note that cursor position doesn't change. screen.cursor_position(10, 0) assert (screen.cursor.y, screen.cursor.x) == (5, 0)
def test_restore_cursor_with_none_saved(): screen = Screen(10, 10) screen.set_mode(mo.DECOM) screen.cursor.x, screen.cursor.y = 5, 5 screen.restore_cursor() assert (screen.cursor.y, screen.cursor.x) == (0, 0) assert mo.DECOM not in screen.mode
def test_resize(): screen = Screen(2, 2) screen.set_mode(mo.DECOM) screen.set_margins(0, 1) assert screen.size == (2, 2) assert len(screen) == 2 assert len(screen[0]) == 2 assert screen == [[screen.default_char, screen.default_char]] * 2 screen.resize(3, 3) assert screen.size == (3, 3) assert len(screen) == 3 assert len(screen[0]) == 3 assert screen == [[screen.default_char, screen.default_char, screen.default_char]] * 3 assert mo.DECOM not in screen.mode assert screen.margins == (0, 2) screen.resize(2, 2) assert screen.size == (2, 2) assert len(screen) == 2 assert len(screen[0]) == 2 assert screen == [[screen.default_char, screen.default_char]] * 2 # quirks: # a) if the current display is thinner than the requested size, # new columns should be added to the right. screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(2, 3) assert screen.display == ["bo ", "sh "] # b) if the current display is wider than the requested size, # columns should be removed from the right... screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(2, 1) assert screen.display == ["b", "s"] # c) if the current display is shorter than the requested # size, new rows should be added on the bottom. screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(3, 2) assert screen.display == ["bo", "sh", " "] # d) if the current display is taller than the requested # size, rows should be removed from the top. screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(1, 2) assert screen.display == ["sh"]
def test_resize(): screen = Screen(2, 2) screen.set_mode(mo.DECOM) screen.set_margins(0, 1) assert screen.size == (2, 2) assert len(screen) == 2 assert len(screen[0]) == 2 assert screen == [[screen.default_char, screen.default_char]] * 2 screen.resize(3, 3) assert screen.size == (3, 3) assert len(screen) == 3 assert len(screen[0]) == 3 assert screen == [[ screen.default_char, screen.default_char, screen.default_char ]] * 3 assert mo.DECOM not in screen.mode assert screen.margins == (0, 2) screen.resize(2, 2) assert screen.size == (2, 2) assert len(screen) == 2 assert len(screen[0]) == 2 assert screen == [[screen.default_char, screen.default_char]] * 2 # quirks: # a) if the current display is thinner than the requested size, # new columns should be added to the right. screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(2, 3) assert screen.display == ["bo ", "sh "] # b) if the current display is wider than the requested size, # columns should be removed from the right... screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(2, 1) assert screen.display == ["b", "s"] # c) if the current display is shorter than the requested # size, new rows should be added on the bottom. screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(3, 2) assert screen.display == ["bo", "sh", " "] # d) if the current display is taller than the requested # size, rows should be removed from the top. screen = update(Screen(2, 2), ["bo", "sh"], [None, None]) screen.resize(1, 2) assert screen.display == ["sh"]
def test_save_cursor(): # a) cursor position screen = Screen(10, 10) screen.save_cursor() screen.cursor.x, screen.cursor.y = 3, 5 screen.save_cursor() screen.cursor.x, screen.cursor.y = 4, 4 screen.restore_cursor() assert screen.cursor.x == 3 assert screen.cursor.y == 5 screen.restore_cursor() assert screen.cursor.x == 0 assert screen.cursor.y == 0 # b) modes screen = Screen(10, 10) screen.set_mode(mo.DECAWM, mo.DECOM) screen.save_cursor() screen.reset_mode(mo.DECAWM) screen.restore_cursor() assert mo.DECAWM in screen.mode assert mo.DECOM in screen.mode # c) attributes screen = Screen(10, 10) screen.select_graphic_rendition(4) screen.save_cursor() screen.select_graphic_rendition(24) assert screen.cursor.attrs == screen.default_char screen.restore_cursor() assert screen.cursor.attrs != screen.default_char assert screen.cursor.attrs == Char(" ", underscore=True)
def test_restore_cursor_out_of_bounds(): screen = Screen(10, 10) # a) origin mode off. screen.cursor_position(5, 5) screen.save_cursor() screen.resize(3, 3) screen.reset() screen.restore_cursor() assert (screen.cursor.y, screen.cursor.x) == (2, 2) # b) origin mode is on. screen.resize(10, 10) screen.cursor_position(8, 8) screen.save_cursor() screen.resize(5, 5) screen.reset() screen.set_mode(mo.DECOM) screen.set_margins(2, 3) screen.restore_cursor() assert (screen.cursor.y, screen.cursor.x) == (2, 4)
def test_draw(): # ``DECAWM`` on (default). screen = Screen(3, 3) assert mo.DECAWM in screen.mode map(screen.draw, "abc") assert screen.display == ["abc", " ", " "] assert (screen.cursor.y, screen.cursor.x) == (0, 3) # ... one` more character -- now we got a linefeed! screen.draw("a") assert (screen.cursor.y, screen.cursor.x) == (1, 1) # ``DECAWM`` is off. screen = Screen(3, 3) screen.reset_mode(mo.DECAWM) map(screen.draw, "abc") assert screen.display == ["abc", " ", " "] assert (screen.cursor.y, screen.cursor.x) == (0, 3) # No linefeed is issued on the end of the line ... screen.draw("a") assert screen.display == ["aba", " ", " "] assert (screen.cursor.y, screen.cursor.x) == (0, 3) # ``IRM`` mode is on, expecting new characters to move the old ones # instead of replacing them. screen.set_mode(mo.IRM) screen.cursor_position() screen.draw("x") assert screen.display == ["xab", " ", " "] screen.cursor_position() screen.draw("y") assert screen.display == ["yxa", " ", " "]