test_position_helper.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from textwrap import dedent
  2. import pytest
  3. from core.helper.position_helper import get_position_map
  4. @pytest.fixture
  5. def prepare_example_positions_yaml(tmp_path, monkeypatch) -> str:
  6. monkeypatch.chdir(tmp_path)
  7. tmp_path.joinpath("example_positions.yaml").write_text(dedent(
  8. """\
  9. - first
  10. - second
  11. # - commented
  12. - third
  13. - 9999999999999
  14. - forth
  15. """))
  16. return str(tmp_path)
  17. @pytest.fixture
  18. def prepare_empty_commented_positions_yaml(tmp_path, monkeypatch) -> str:
  19. monkeypatch.chdir(tmp_path)
  20. tmp_path.joinpath("example_positions_all_commented.yaml").write_text(dedent(
  21. """\
  22. # - commented1
  23. # - commented2
  24. -
  25. -
  26. """))
  27. return str(tmp_path)
  28. def test_position_helper(prepare_example_positions_yaml):
  29. position_map = get_position_map(
  30. folder_path=prepare_example_positions_yaml,
  31. file_name='example_positions.yaml')
  32. assert len(position_map) == 4
  33. assert position_map == {
  34. 'first': 0,
  35. 'second': 1,
  36. 'third': 2,
  37. 'forth': 3,
  38. }
  39. def test_position_helper_with_all_commented(prepare_empty_commented_positions_yaml):
  40. position_map = get_position_map(
  41. folder_path=prepare_empty_commented_positions_yaml,
  42. file_name='example_positions_all_commented.yaml')
  43. assert position_map == {}