Skip to content

Commit

Permalink
Merge pull request #106 from AVEgame/test_screen
Browse files Browse the repository at this point in the history
Test screen
  • Loading branch information
mscroggs authored Jul 4, 2020
2 parents f1eec11 + 0b62b97 commit 29c1a6f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 8 additions & 5 deletions ave/display/curses_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand All @@ -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."""
Expand Down
54 changes: 54 additions & 0 deletions test/test_screen.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 29c1a6f

Please sign in to comment.