Skip to content

Commit

Permalink
test: move zquest save classic_1st.qst test to python
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Aug 20, 2023
1 parent 7441956 commit 7c8a562
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,6 @@ jobs:
- if: ${{ matrix.shard_index == 1 && inputs.extra-args == '' && runner.os != 'Windows' && runner.os != 'Linux' && inputs.config != 'Coverage' }}
name: Test ZQuest File->New
run: bash ${{ github.workspace }}/.github/workflows/run_target.sh zquest -s -q 'modules/classic/default.qst'
# Resave classic_1st.qst and assert classic_1st.zplay, to make sure the loading/saving code is not introducing bugs.
- if: ${{ matrix.shard_index == 1 && inputs.extra-args == '' && runner.os != 'Windows' && inputs.config != 'Coverage' }}
name: Test saving qst
run: |
cd ${{ env.BUILD_FOLDER }}
set -ex
bash ${{ github.workspace }}/.github/workflows/run_target.sh zquest -headless -s -copy-qst modules/classic/classic_1st.qst tmp.qst
mv tmp.qst modules/classic/classic_1st.qst
bash ${{ github.workspace }}/.github/workflows/run_target.sh zplayer -headless -s -v0 -replay-exit-when-done -assert ${{ github.workspace }}/tests/replays/classic_1st.zplay

- name: Generate coverage json
if: inputs.config == 'Coverage'
Expand Down
46 changes: 32 additions & 14 deletions tests/test_zquest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

script_dir = Path(os.path.dirname(os.path.realpath(__file__)))
root_dir = script_dir.parent
tmp_dir = root_dir / '.tmp/test_zquest'
tmp_dir.mkdir(exist_ok=True, parents=True)

sys.path.append(str((root_dir / 'scripts').absolute()))
import run_target
Expand Down Expand Up @@ -45,7 +47,34 @@ def run_replay(self, output_dir, args):
raise Exception('could not find test_results.json')

test_results_json = json.loads(test_results_path.read_text('utf-8'))
return output.returncode, ReplayTestResults(**test_results_json)
results = ReplayTestResults(**test_results_json)

run = results.runs[0][0]
if not run.success:
failing_str = f'failure at frame {run.failing_frame}'
if run.unexpected_gfx_segments:
segments_str = [
f'{r[0]}-{r[1]}' for r in run.unexpected_gfx_segments]
failing_str += ': ' + ', '.join(segments_str)
self.fail(failing_str)
self.assertEqual(output.returncode, 0)

# Resave classic_1st.qst and assert classic_1st.zplay, to make sure the loading/saving code is not introducing bugs.
def test_zquest_save(self):
qst_path = tmp_dir / 'tmp.qst'
run_target.check_run('zquest', [
'-headless',
'-s',
'-copy-qst', 'modules/classic/classic_1st.qst', qst_path,
])

replay_content = (root_dir / 'tests/replays/classic_1st.zplay').read_text('utf-8')
replay_content.replace('modules/classic/classic_1st.qst', 'tmp.qst')
replay_path = tmp_dir / 'tmp.zplay'
replay_path.write_text(replay_content)

output_dir = tmp_dir / 'output' / replay_path.name
self.run_replay(output_dir, [replay_path])

def test_zquest_compile_and_quick_assign(self):
# TODO: set this via CLI
Expand All @@ -62,20 +91,9 @@ def test_zquest_compile_and_quick_assign(self):
# Ensure replays continue to pass.
for replay_path in (root_dir / 'tests/replays').glob('playground_*.zplay'):
with self.subTest(msg=f'{replay_path.name}'):
output_dir = root_dir / '.tmp/test_zquest/output' / replay_path.name
output_dir = tmp_dir / 'output' / replay_path.name
output_dir.mkdir(exist_ok=True, parents=True)
status, results = self.run_replay(
output_dir, ['--filter', replay_path.name])
run = results.runs[0][0]
if not run.success:
failing_str = f'failure at frame {run.failing_frame}'
if run.unexpected_gfx_segments:
segments_str = [
f'{r[0]}-{r[1]}' for r in run.unexpected_gfx_segments]
failing_str += ': ' + ', '.join(segments_str)
self.fail(failing_str)
self.assertEqual(status, 0)

self.run_replay(output_dir, [replay_path])

if __name__ == '__main__':
unittest.main()

0 comments on commit 7c8a562

Please sign in to comment.