CI: add Generate.py tests

* allows ModuleUpdate to be run outside of local_dir
* adds windows-latest to the unittest matrix
This commit is contained in:
black-sliver 2022-04-01 01:09:16 +02:00 committed by Fabian Dill
parent dca70a99ad
commit fe4a26d034
5 changed files with 84 additions and 5 deletions

View File

@ -7,17 +7,20 @@ on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
name: Test Python ${{ matrix.python.version }} ${{ matrix.os }}
runs-on: ubuntu-latest
name: Test Python ${{ matrix.python.version }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python:
- {version: '3.8'}
- {version: '3.9'}
#- {version: '3.10'}
include:
- python: {version: '3.9'}
os: windows-latest
steps:
- uses: actions/checkout@v2

View File

@ -3,7 +3,8 @@ import sys
import subprocess
import pkg_resources
requirements_files = {'requirements.txt'}
local_dir = os.path.dirname(__file__)
requirements_files = {os.path.join(local_dir, 'requirements.txt')}
if sys.version_info < (3, 8, 6):
raise RuntimeError("Incompatible Python Version. 3.8.7+ is supported.")
@ -11,7 +12,7 @@ if sys.version_info < (3, 8, 6):
update_ran = getattr(sys, "frozen", False) # don't run update if environment is frozen/compiled
if not update_ran:
for entry in os.scandir("worlds"):
for entry in os.scandir(os.path.join(local_dir, "worlds")):
if entry.is_dir():
req_file = os.path.join(entry.path, "requirements.txt")
if os.path.exists(req_file):

View File

@ -0,0 +1,66 @@
# Tests for Generate.py (ArchipelagoGenerate.exe)
import unittest
import sys
from pathlib import Path
from tempfile import TemporaryDirectory
import os.path
import os
import ModuleUpdate
ModuleUpdate.update_ran = True # don't upgrade
import Generate
import Utils
class TestGenerateMain(unittest.TestCase):
"""This tests Generate.py (ArchipelagoGenerate.exe) main"""
generate_dir = Path(Generate.__file__).parent
run_dir = generate_dir / 'test' # reproducible cwd that's neither __file__ nor Generate.__file__
abs_input_dir = Path(__file__).parent / 'data' / 'OnePlayer'
rel_input_dir = abs_input_dir.relative_to(run_dir) # directly supplied relative paths are relative to cwd
yaml_input_dir = abs_input_dir.relative_to(generate_dir) # yaml paths are relative to user_path
def assertOutput(self, output_dir: str):
output_path = Path(output_dir)
output_files = list(output_path.glob('*.zip'))
if len(output_files) == 1:
return True
self.fail(f"Expected {output_dir} to contain one zip, but has {len(output_files)}: "
f"{list(output_path.glob('*'))}")
def setUp(self):
Utils.local_path.cached_path = str(self.generate_dir)
os.chdir(self.run_dir)
self.output_tempdir = TemporaryDirectory(prefix='AP_out_')
def test_generate_absolute(self):
sys.argv = [sys.argv[0], '--seed', '0',
'--player_files_path', str(self.abs_input_dir),
'--outputpath', self.output_tempdir.name]
print(f'Testing Generate.py {sys.argv} in {os.getcwd()}')
Generate.main()
self.assertOutput(self.output_tempdir.name)
def test_generate_relative(self):
sys.argv = [sys.argv[0], '--seed', '0',
'--player_files_path', str(self.rel_input_dir),
'--outputpath', self.output_tempdir.name]
print(f'Testing Generate.py {sys.argv} in {os.getcwd()}')
Generate.main()
self.assertOutput(self.output_tempdir.name)
def test_generate_yaml(self):
# override host.yaml
defaults = Utils.get_options()["generator"]
defaults["player_files_path"] = str(self.yaml_input_dir)
defaults["players"] = 0
sys.argv = [sys.argv[0], '--seed', '0',
'--outputpath', self.output_tempdir.name]
print(f'Testing Generate.py {sys.argv} in {os.getcwd()}, player_files_path={self.yaml_input_dir}')
Generate.main()
self.assertOutput(self.output_tempdir.name)

View File

View File

@ -0,0 +1,9 @@
description: Almost blank test yaml
name: Player{NUMBER}
game:
Timespinner: 1 # what else
requires:
version: 0.2.6
Timespinner: {}