46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
"""Read the real Python script loader's contract without executing scripts.
|
|
|
|
Invoked by TestPythonLoaderParity when FENRIR_PYTHON_SOURCE names a checkout.
|
|
The JSON output is compared with Go discovery over the same fixture files.
|
|
"""
|
|
|
|
import json
|
|
import sys
|
|
from types import SimpleNamespace
|
|
from unittest.mock import Mock
|
|
|
|
sys.path.insert(0, sys.argv[1] + "/src")
|
|
|
|
from fenrirscreenreader.core import commandManager, inputData
|
|
|
|
|
|
class ScriptCommand:
|
|
def initialize(self, environment, path):
|
|
self.path = path
|
|
|
|
|
|
commandManager.module_utils.import_module = lambda *_: SimpleNamespace(command=ScriptCommand)
|
|
settings = Mock()
|
|
settings.get_user_script_path.return_value = sys.argv[2]
|
|
settings.get_setting.return_value = sys.argv[3]
|
|
manager = commandManager.CommandManager()
|
|
manager.env = {
|
|
"commands": {"commands": {}},
|
|
"bindings": {},
|
|
"rawBindings": {},
|
|
"runtime": {
|
|
"SettingsManager": settings,
|
|
"DebugManager": Mock(),
|
|
"InputManager": Mock(is_valid_key=lambda name: name in inputData.key_names),
|
|
},
|
|
}
|
|
loaded_names = set()
|
|
for path in manager.get_script_paths()[:2]:
|
|
manager.load_script_commands_from_path("commands", path, loaded_names)
|
|
result = []
|
|
for name, command in manager.env["commands"]["commands"].items():
|
|
chord = next(keys[1] for key, keys in manager.env["rawBindings"].items()
|
|
if manager.env["bindings"][key] == name)
|
|
result.append({"name": name, "path": command.path, "keys": chord})
|
|
print(json.dumps(result))
|