test_state.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # coding: utf-8
  2. import pytest
  3. from synergine2.config import Config
  4. from opencombat.exception import StateLoadError
  5. from opencombat.simulation.subject import ManSubject
  6. from opencombat.state import StateLoaderBuilder, StateLoader
  7. class MyStateLoader(StateLoader):
  8. pass
  9. @pytest.fixture
  10. def state_loader(config, simulation):
  11. return StateLoader(config, simulation)
  12. def test_state_loader_builder__ok__nominal_case(
  13. simulation,
  14. ):
  15. config = Config({
  16. 'global': {
  17. 'state_loader': 'tests.test_state.MyStateLoader',
  18. }
  19. })
  20. builder = StateLoaderBuilder(config, simulation)
  21. state_loader = builder.get_state_loader()
  22. assert type(state_loader) == MyStateLoader
  23. def test_state_loader__ok__load_state(
  24. state_loader,
  25. ):
  26. assert state_loader.get_state('tests/fixtures/state_ok.xml')
  27. def test_state_loader__error__state_empty(
  28. state_loader,
  29. ):
  30. with pytest.raises(StateLoadError):
  31. assert state_loader.get_state('tests/fixtures/state_empty.xml')
  32. def test_state_loader__error__state_invalid(
  33. state_loader,
  34. ):
  35. with pytest.raises(StateLoadError):
  36. assert state_loader.get_state(
  37. 'tests/fixtures/state_error_schema.xml',
  38. )
  39. def test_state__ok__subjects(
  40. state_loader,
  41. ):
  42. state = state_loader.get_state('tests/fixtures/state_ok.xml')
  43. assert 2 == len(state.subjects)
  44. assert isinstance(state.subjects[0], ManSubject)
  45. assert isinstance(state.subjects[1], ManSubject)
  46. assert (1, 1) == state.subjects[0].position
  47. assert (10, 10) == state.subjects[1].position
  48. assert 90.0 == state.subjects[0].direction
  49. assert 270.0 == state.subjects[1].direction