def test_attributes_reset(): screen = Screen(2, 2) assert screen == [[screen.default_char, screen.default_char]] * 2 screen.select_graphic_rendition(1) screen.draw("f") screen.draw("o") screen.draw("o") assert screen == [ [Char("f", bold=True), Char("o", bold=True)], [Char("o", bold=True), screen.default_char], ] screen.cursor_position() screen.select_graphic_rendition(0) # Reset screen.draw("f") assert screen == [ [Char("f"), Char("o", bold=True)], [Char("o", bold=True), screen.default_char], ]
def test_attributes_reset(): screen = Screen(2, 2) assert screen == [[screen.default_char, screen.default_char]] * 2 screen.select_graphic_rendition(1) screen.draw("f") screen.draw("o") screen.draw("o") assert screen == [ [Char("f", bold=True), Char("o", bold=True)], [Char("o", bold=True), screen.default_char ], ] screen.cursor_position() screen.select_graphic_rendition(0) # Reset screen.draw("f") assert screen == [ [Char("f"), Char("o", bold=True)], [Char("o", bold=True), screen.default_char ], ]
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", " ", " "]
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)