mirror of
https://github.com/JackHopkins/factorio-learning-environment.git
synced 2025-09-06 13:23:58 +00:00

Some checks failed
Lint and Format / lint (push) Has been cancelled
* sessions based * try out caching + no sleep * update fixture usage * better reset usge * state less on tech, probably breaking change * better fixtures + decouple resets * use pytest-xdist w 2 servers * using diff grouping for dep * formatting * formatting * caching for image * formatting * formatting * use uv * use uv caching * remove docker caching (its slower) * how about 4 workers? * no redundant resets * parameterize * change names * update all_technologies_researched usage change log: - used uv and cache dependencies - used 2 factorio headless server instances - added pytest-xdist & used 2 pytest workers - parametrized the slowest test -- `test_sleep.py` so as to balance it across workers - clarified resets in `instance.py` so separate instances arent needed for research testing - better fixture usage, with autouse reset - added configure_game callback for per test file setup of inventories & research state. - updated task abc all_technologies_researched usage, its now a param for reset - using 4 workers instead of 2, can probably double it again lol - pytest parameterized a slow test - fixed redundant reset in conftest final speedup: 9m 4s -> 1m, ≈9.07× faster
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
import pytest
|
|
|
|
from fle.env.entities import Position, Direction, Prototype, Resource
|
|
|
|
|
|
@pytest.fixture()
|
|
def game(instance):
|
|
instance.initial_inventory = {
|
|
**instance.initial_inventory,
|
|
"coal": 5,
|
|
"iron-chest": 1,
|
|
"iron-plate": 5,
|
|
"iron-ore": 10,
|
|
}
|
|
yield instance.namespace
|
|
|
|
|
|
def test_inspect_entities(game):
|
|
inventory = game.inspect_inventory()
|
|
coal_count = inventory[Prototype.Coal]
|
|
assert coal_count != 0
|
|
chest = game.place_entity(Prototype.IronChest, position=Position(x=0, y=0))
|
|
game.insert_item(Prototype.Coal, chest, quantity=5)
|
|
|
|
inspected = game.inspect_entities(
|
|
radius=5, position=Position(x=chest.position.x, y=chest.position.y)
|
|
)
|
|
|
|
assert len(inspected.entities) == 2
|
|
|
|
|
|
def test_inspect_inserters(game):
|
|
"""Test to ensure that inspected inserters are facing in the correct direction"""
|
|
|
|
game.place_entity(
|
|
Prototype.BurnerInserter, Direction.RIGHT, position=Position(x=0, y=0)
|
|
)
|
|
|
|
entities = game.inspect_entities(radius=5)
|
|
|
|
for entity in entities.entities:
|
|
if entity.name == "burner-inserter":
|
|
assert entity.direction == Direction.RIGHT.value
|
|
|
|
|
|
def test_inspect_burner_inventory(game):
|
|
# Check initial inventory
|
|
iron_position = game.nearest(Resource.Stone)
|
|
game.move_to(iron_position)
|
|
print(f"Moved to iron patch at {iron_position}")
|
|
game.harvest_resource(iron_position, 20)
|
|
|
|
game.craft_item(Prototype.StoneFurnace, 3)
|
|
|
|
# 1. Place a stone furnace
|
|
stone_furnace = game.place_entity(
|
|
Prototype.StoneFurnace, Direction.UP, iron_position
|
|
)
|
|
assert stone_furnace is not None, "Failed to place stone furnace"
|
|
|
|
game.insert_item(Prototype.Coal, stone_furnace, 5)
|
|
game.insert_item(Prototype.IronOre, stone_furnace, 5)
|
|
|
|
inspection_result = game.inspect_entities()
|
|
|
|
furnace = inspection_result.get_entities(Prototype.StoneFurnace)
|
|
print(furnace)
|