test_lua_runtime.py 730 B

1234567891011121314151617181920212223242526272829
  1. import pytest
  2. from cq2_sdk.lua_bridge.runtime import LuaRuntime, get_runtime, DEFAULT_LUA_PATH
  3. def test_lua_eval_arithmetic():
  4. rt = LuaRuntime()
  5. assert rt.eval("1 + 2") == 3
  6. def test_lua_call_global_function():
  7. rt = LuaRuntime()
  8. rt.execute("function double(x) return x * 2 end")
  9. assert rt.call("double", 21) == 42
  10. def test_get_runtime_returns_singleton():
  11. a = get_runtime()
  12. b = get_runtime()
  13. assert a is b
  14. def test_default_path_from_env(monkeypatch):
  15. monkeypatch.setenv("CQ2_LUA_PATH", "/custom/path")
  16. rt = LuaRuntime()
  17. assert rt.lua_path == "/custom/path"
  18. def test_default_path_constant():
  19. assert DEFAULT_LUA_PATH == r"D:\ProgramFiles\996box\GameBoxDownload\1\cq\assets"