test_api.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import pathlib
  2. import shutil
  3. import subprocess
  4. import unittest.mock
  5. import pytest
  6. import tooncher
  7. def test_start_engine():
  8. process = tooncher.start_engine(
  9. engine_path=pathlib.Path(shutil.which("printenv")),
  10. gameserver="gameserver",
  11. playcookie="cookie",
  12. stdout=subprocess.PIPE,
  13. stderr=subprocess.PIPE,
  14. )
  15. assert isinstance(process, subprocess.Popen)
  16. stdout, stderr = process.communicate()
  17. assert not stderr
  18. env = stdout.strip().split(b"\n")
  19. assert b"TTR_GAMESERVER=gameserver" in env
  20. assert b"TTR_PLAYCOOKIE=cookie" in env
  21. def test_start_engine_mac():
  22. app_support_path = "/Users/fabianpeter/Library/Application Support"
  23. with unittest.mock.patch("subprocess.Popen") as popen_mock:
  24. with unittest.mock.patch("sys.platform", "darwin"):
  25. tooncher.start_engine(
  26. engine_path=pathlib.PosixPath(
  27. app_support_path + "/Toontown Rewritten/Toontown Rewritten"
  28. ),
  29. gameserver="gameserver",
  30. playcookie="cookie",
  31. check=True,
  32. )
  33. popen_mock.assert_called_once_with(
  34. args=[
  35. "/Users/fabianpeter/Library/Application Support/Toontown Rewritten/Toontown Rewritten"
  36. ],
  37. check=True,
  38. cwd=pathlib.PosixPath(
  39. "/Users/fabianpeter/Library/Application Support/Toontown Rewritten"
  40. ),
  41. env={
  42. "TTR_GAMESERVER": "gameserver",
  43. "TTR_PLAYCOOKIE": "cookie",
  44. "DYLD_LIBRARY_PATH": app_support_path
  45. + "/Toontown Rewritten/Libraries.bundle",
  46. "DYLD_FRAMEWORK_PATH": app_support_path + "/Toontown Rewritten/Frameworks",
  47. },
  48. )