diff --git a/.circleci/config.yml b/.circleci/config.yml index 52248c6..aca5b11 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,7 +28,7 @@ jobs: command: pip3 install . name: Install AVE - run: - command: python3 -m pytest test/ + command: export TERM=xterm && python3 -m pytest test/ name: Run tests windows-build-and-test: diff --git a/ave/display/curses_screen.py b/ave/display/curses_screen.py index 4f60f15..108a31a 100644 --- a/ave/display/curses_screen.py +++ b/ave/display/curses_screen.py @@ -13,7 +13,7 @@ class CursesScreen(Screen): """The Screen class that looks after curses.""" - def __init__(self): + def __init__(self, cbreak=True): """Make the screen.""" self.stdscr = curses.initscr() @@ -52,7 +52,8 @@ def __init__(self): curses.init_pair(10, -1, curses.COLOR_BLUE) curses.noecho() - curses.cbreak() + if cbreak: + curses.cbreak() curses.curs_set(0) self.stdscr.keypad(1) self.stdscr.refresh() @@ -70,13 +71,15 @@ def clear(self): pad = self.newpad() pad.refresh(0, 0, 0, 0, HEIGHT, WIDTH) - def close(self): + def close(self, cbreak=True): """Close the curses screen.""" - curses.nocbreak() + if cbreak: + curses.nocbreak() curses.curs_set(1) self.stdscr.keypad(0) curses.echo() - curses.endwin() + if cbreak: + curses.endwin() def newpad(self, y=HEIGHT, x=WIDTH): """Make a new pad to write to the screen.""" diff --git a/test/test_screen.py b/test/test_screen.py new file mode 100644 index 0000000..778591e --- /dev/null +++ b/test/test_screen.py @@ -0,0 +1,54 @@ +import pytest +import os +from ave.display.curses_screen import CursesScreen + +winskip = pytest.mark.skipif( + os.name == "nt", reason="CircleCI cannot run this test on windows") + + +@winskip +def make_screen(): + try: + return CursesScreen() + except: # noqa: E722 + return CursesScreen(False) + + +@winskip +def close_screen(s): + try: + s.close() + except: # noqa: E722 + s.close(False) + + +@winskip +def test_start_and_close(): + s = make_screen() + close_screen(s) + + +@winskip +def test_clear(): + s = make_screen() + s.clear() + close_screen(s) + + +@winskip +@pytest.mark.parametrize('file', ["credits", "title", "user"]) +def test_print_file(file): + s = make_screen() + s.print_file(file) + s.close(False) + + +@winskip +@pytest.mark.parametrize('inventory', [ + [], ["hat", "shoes"], ["a" * 100], ["a"] * 100]) +def test_show_inventory(inventory): + s = make_screen() + s.show_inventory([]) + s.show_inventory(["hat", "shoes"]) + s.show_inventory(["hat"] * 100) + close_screen(s)