Update GUI game debugging multiple-apps examples and eval
This commit is contained in:
@@ -123,7 +123,9 @@ from .vscode import (
|
||||
compare_answer,
|
||||
is_extension_installed,
|
||||
check_json_settings,
|
||||
check_json_keybindings
|
||||
check_json_keybindings,
|
||||
check_python_file_by_test_suite,
|
||||
check_python_file_by_gold_file
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import copy
|
||||
import importlib.util
|
||||
import json
|
||||
import sys
|
||||
from typing import Dict
|
||||
|
||||
|
||||
@@ -133,9 +135,29 @@ def is_extension_installed(actual: str, rules: Dict, **options):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def check_python_file_by_test_suite(actual_file, test_suites, **options) -> float:
|
||||
pass
|
||||
def check_python_file_by_test_suite(actual_files, test_file, **options) -> float:
|
||||
"""Check the python file by running the test suite in the given test file."""
|
||||
|
||||
test_function_name = options.get('test_function_name', 'test')
|
||||
# Create a unique module name, it can be arbitrary but must be unique in the current runtime environment
|
||||
module_name = 'dynamic_module'
|
||||
|
||||
# Load the module from the given file path
|
||||
spec = importlib.util.spec_from_file_location(module_name, test_file)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[module_name] = module # Add the loaded module to sys.modules
|
||||
spec.loader.exec_module(module) # Execute the module to make its content available
|
||||
|
||||
# Retrieve the function by name from the loaded module and execute it
|
||||
test_function = getattr(module, test_function_name)
|
||||
try:
|
||||
if test_function():
|
||||
return 1.0
|
||||
else:
|
||||
return 0.0
|
||||
except Exception as e:
|
||||
return 0.0
|
||||
|
||||
|
||||
def check_python_file_by_gold_file(actual_file, gold_file: str, **options) -> float:
|
||||
def check_python_file_by_gold_file(actual_files, gold_file: str, **options) -> float:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user