test_units.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # coding: utf-8
  2. import pytest
  3. from synergine2.config import Config
  4. from opencombat.exception import NotFoundException
  5. from opencombat.simulation.subject import ManSubject
  6. from opencombat.strategy.team.model import UnitModel
  7. from opencombat.strategy.unit.stash import UnitStash
  8. def test_units_stash__ok__instantiate(
  9. config: Config,
  10. ):
  11. UnitStash(
  12. config,
  13. 'opencombat/strategy/units.xml',
  14. )
  15. def test_units_stash__ok__get_units(
  16. config: Config,
  17. ):
  18. stash = UnitStash(
  19. config,
  20. 'tests/fixtures/units.xml',
  21. )
  22. assert stash.units
  23. assert 2 == len(stash.units)
  24. assert isinstance(stash.units[0], UnitModel)
  25. assert isinstance(stash.units[1], UnitModel)
  26. assert 'std_soldier' == stash.units[0].id
  27. assert 'Standard soldier' == stash.units[0].name
  28. assert 'URSS' == stash.units[0].country
  29. assert ManSubject == stash.units[0].class_
  30. assert 'std_soldier' == stash.units[1].id
  31. assert 'Standard soldier' == stash.units[1].name
  32. assert 'DE' == stash.units[1].country
  33. assert ManSubject == stash.units[1].class_
  34. def test_units_stash__ok__get_unit(
  35. config: Config,
  36. ):
  37. stash = UnitStash(
  38. config,
  39. 'tests/fixtures/units.xml',
  40. )
  41. assert stash.get_unit('std_soldier', 'URSS')
  42. def test_units_stash__error__get_unit_wrong_country(
  43. config: Config,
  44. ):
  45. stash = UnitStash(
  46. config,
  47. 'tests/fixtures/units.xml',
  48. )
  49. with pytest.raises(NotFoundException):
  50. stash.get_unit('std_soldier', 'UNKNOWN')
  51. def test_units_stash__error__get_unit_wrong_id(
  52. config: Config,
  53. ):
  54. stash = UnitStash(
  55. config,
  56. 'tests/fixtures/units.xml',
  57. )
  58. with pytest.raises(NotFoundException):
  59. stash.get_unit('unknown', 'URSS')