0ad/source/tools/rlclient/python/tests/test_evaluate.py
Dunedan e36c6a31fe
Enable additional ruff rules
In the ruff config file added in #6954 explicitly selecting the ruff
rules to check was missed, resulting in ruff only checking a very small
subset of its available rules. That hasn't been desired, so this is the
first of a series of commits enabling more rules. In this PR all rules
whose violations can be either automatically fixed by ruff or are
trivial to fix manually get enabled. For the follow up PRs it's intended
to focus on one area of rules per PR to gradually improve the Python
code quality.
2024-08-25 06:29:39 +02:00

52 lines
1.4 KiB
Python

from os import path
import zero_ad
game = zero_ad.ZeroAD("http://localhost:6000")
scriptdir = path.dirname(path.realpath(__file__))
with open(path.join(scriptdir, "..", "samples", "arcadia.json")) as f:
config = f.read()
with open(path.join(scriptdir, "fastactions.js")) as f:
fastactions = f.read()
def test_return_object():
game.reset(config)
result = game.evaluate('({"hello": "world"})')
assert type(result) is dict
assert result["hello"] == "world"
def test_return_null():
result = game.evaluate("null")
assert result is None
def test_return_string():
game.reset(config)
result = game.evaluate('"cat"')
assert result == "cat"
def test_fastactions():
state = game.reset(config)
game.evaluate(fastactions)
female_citizens = state.units(owner=1, type="female_citizen")
house_tpl = "structures/spart/house"
len(state.units(owner=1, type=house_tpl))
x = 680
z = 640
build_house = zero_ad.actions.construct(female_citizens, house_tpl, x, z, autocontinue=True)
# Check that they start building the house
state = game.step([build_house])
def new_house(_=None):
return state.units(owner=1, type=house_tpl)[0]
initial_health = new_house().health(ratio=True)
while new_house().health(ratio=True) == initial_health:
state = game.step()
assert new_house().health(ratio=True) >= 1.0