Skip to content

Commit

Permalink
Test dark mode too.
Browse files Browse the repository at this point in the history
  • Loading branch information
porridge committed Jul 14, 2023
1 parent 05b1f9f commit 57dce47
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ jobs:
-s "-screen 0 1024x768x24 -fbdir $AUTOPKGTEST_TMP" \
./test_e2e.py
- name: Run GUI tests in dark mode
run: |
export AUTOPKGTEST_ARTIFACTS=`pwd`/artifacts/dark
mkdir -p $AUTOPKGTEST_ARTIFACTS
export AUTOPKGTEST_TMP=/tmp
export AUTOPKGTEST_BAMBAM_PROGRAM=./bambam.py
xvfb-run \
-e $AUTOPKGTEST_ARTIFACTS/xvfb-run.stderr \
-s "-screen 0 1024x768x24 -fbdir $AUTOPKGTEST_TMP" \
./test_e2e.py --expect-dark-mode -- --dark
- name: Run GUI tests with deterministic sounds
run: |
export AUTOPKGTEST_ARTIFACTS=`pwd`/artifacts/deterministic
Expand Down
23 changes: 15 additions & 8 deletions test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('--expect-audio-output', action=argparse.BooleanOptionalAction, default=True)
parser.add_argument('--expect-sounds', action=argparse.BooleanOptionalAction, default=True)
parser.add_argument('--expect-dark-mode', action=argparse.BooleanOptionalAction, default=True)
parser.add_argument('--sdl-audio-driver', default='disk')
parser.add_argument('bambam_args', nargs='*')
args = parser.parse_args()
Expand All @@ -65,8 +66,8 @@ def main():
await_welcome_screen()
send_keycodes('space') # any keypress should do
check_still_running(bambam)
await_blank_screen()
test_functionality(bambam, args.expect_sounds)
await_blank_screen(args.expect_dark_mode)
test_functionality(bambam, args.expect_sounds, args.expect_dark_mode)
shut_bambam_down(bambam)
logging.info('Waiting for game to exit cleanly.')
exit_code = bambam.wait(timeout=_EXIT_SECONDS)
Expand Down Expand Up @@ -109,21 +110,27 @@ def await_welcome_screen():
'after polling %d times every %f seconds.' % (attempt_count, sleep_delay))


def await_blank_screen():
logging.info('Polling to observe a mostly-white screen (which means that welcome screen was cleared).')
def await_blank_screen(expect_dark: bool):
attempt_count = 40
sleep_delay = 0.25
if expect_dark:
def check(c): return c < 2
comment = 'mostly black screen'
else:
def check(c): return c >= 248
comment = 'mostly white screen'
logging.info('Polling to observe a %s (which means that welcome screen was cleared).', comment)
for attempt in range(attempt_count):
current_average_color = get_average_color()
logging.info('On attempt %d the average screen color was %s.', attempt, current_average_color)
if all(color_component >= 248 for color_component in current_average_color):
logging.info('Found mostly white screen, looks like bambam cleared the welcome screen OK.')
if all(check(color_component) for color_component in current_average_color):
logging.info('Found %s, looks like bambam cleared the welcome screen OK.', comment)
take_screenshot('blank')
return
time.sleep(sleep_delay)
raise Exception(
'Failed to see bambam clear the startup screen and display mostly-white background, '
'after polling %d times every %f seconds.' % (attempt_count, sleep_delay))
'Failed to see bambam clear the startup screen and display %s, '
'after polling %d times every %f seconds.' % (comment, attempt_count, sleep_delay))


def check_still_running(bambam: subprocess.Popen):
Expand Down

0 comments on commit 57dce47

Please sign in to comment.