def test_base_dynamic_memory_leak_check(): # Make sure calling this monitoring function doesn't cause a memory # leak on it own dynamic_mem = OS.get_dynamic_memory_usage() dynamic_mem2 = OS.get_dynamic_memory_usage() dynamic_leak = dynamic_mem2 - dynamic_mem assert dynamic_leak == 0
def test_base_static_memory_leak_check(): # Make sure calling this monitoring function doesn't cause a memory # leak on it own static_mem = OS.get_static_memory_usage() static_mem2 = OS.get_static_memory_usage() static_leak = static_mem2 - static_mem assert static_leak == 0
def _ready(self): # Retrieve command line arguments passed through --pytest=... prefix = '--pytest=' pytest_args = [] for arg in OS.get_cmdline_args(): if arg.startswith(prefix): pytest_args += arg[len(prefix):].split(',') # Run tests here if pytest.main(pytest_args): OS.set_exit_code(1) # Exit godot self.get_tree().quit()
def _ready(self): # Retrieve command line arguments passed through --pytest=... prefix = '--pytest=' # Filter to avoid scanning `plugins` and `lib` directories pytest_args = [x for x in os.listdir() if x.startswith('test_')] for arg in OS.get_cmdline_args(): if arg.startswith(prefix): pytest_args += arg[len(prefix):].split(',') # Run tests here if pytest.main(pytest_args): OS.set_exit_code(1) # Exit godot self.get_tree().quit()
def check_memory_leak(fn): dynamic_mem_start = OS.get_dynamic_memory_usage() static_mem_start = OS.get_static_memory_usage() fn() # TODO: force garbage collection on pypy static_mem_end = OS.get_static_memory_usage() dynamic_mem_end = OS.get_dynamic_memory_usage() static_leak = static_mem_end - static_mem_start dynamic_leak = dynamic_mem_end - dynamic_mem_start assert static_leak == 0 assert dynamic_leak == 0
def pybind_init(): # Make sure Python starts in the game directory os.chdir(ProjectSettings.globalize_path("res://")) # Pass argv arguments sys.argv = ["godot"] + OS.get_cmdline_args() # Update PYTHONPATH according to configuration pythonpath = _setup_config_entry("python_script/path", "res://;res://lib") for p in pythonpath.split(";"): p = ProjectSettings.globalize_path(p) sys.path.append(p) # Redirect stdout/stderr to have it in the Godot editor console if _setup_config_entry("python_script/io_streams_capture", True): enable_capture_io_streams() # Enable verbose output from pythonscript framework if _setup_config_entry("python_script/verbose", False): enable_pythonscript_verbose() # Finally display informative stuff ;-) if _setup_config_entry("python_script/print_startup_info", True): print("Pythonscript version: %s" % __version__) print("Pythonscript backend: %s %s" % (sys.implementation.name, sys.version.replace("\n", " "))) print("PYTHONPATH: %s" % sys.path) return ffi.NULL
def pybind_init(): from godot.bindings import ProjectSettings, OS # Make sure Python starts in the game directory os.chdir(ProjectSettings.globalize_path('res://')) # Setup default value pythonpath_config_field = "python_script/path" pythonpath_default_value = "res://;res://lib" if not ProjectSettings.has_setting(pythonpath_config_field): ProjectSettings.set_setting(pythonpath_config_field, pythonpath_default_value) ProjectSettings.set_initial_value(pythonpath_config_field, pythonpath_default_value) # TODO: `set_builtin_order` is not exposed by gdnative... but is it useful ? pythonpath = ProjectSettings.get_setting(pythonpath_config_field) sys.argv = ["godot"] + OS.get_cmdline_args() for p in pythonpath.split(';'): p = ProjectSettings.globalize_path(p) sys.path.append(p) print('Pythonscript version: %s' % __version__) print('Pythonscript backend: %s %s' % (sys.implementation.name, sys.version.replace('\n', ' '))) print('PYTHONPATH: %s' % sys.path) return ffi.NULL
def _ready(self): # os.listdir is not available, so list test modules by hand test_mods = ( 'test_vector2', 'test_vector3', 'test_dynamic_bindings', ) # Run tests here for mod in test_mods: print('\t=== Tests %s ===' % mod) try: unittest.main(mod) except Exception as exc: sys.print_exception(exc) OS.set_exit_code(1) # Exit godot self.get_tree().quit()
def _ready(self): set_current_node(self) # Retrieve command line arguments passed through --pytest=... prefix = "--pytest=" pytest_args = [] for gdarg in OS.get_cmdline_args(): arg = str(gdarg) if arg.startswith(prefix): pytest_args += arg[len(prefix):].split(",") if all(arg.startswith("-") for arg in pytest_args): # Filter to avoid scanning `plugins` and `lib` directories pytest_args += [x for x in os.listdir() if x.startswith("test_")] # Run tests here print(f"running `pytest {' '.join(pytest_args)}`") if pytest.main(pytest_args): OS.set_exit_code(1) # Exit godot self.get_tree().quit()
def run_tests(self): global root_node root_node = self # Retrieve command line arguments passed through --pytest=... prefix = "--pytest=" pytest_args = [] for arg in OS.get_cmdline_args(): if arg.startswith(prefix): pytest_args += arg[len(prefix):].split() # Run tests here return pytest.main(pytest_args)
def run_tests(self): global root_node root_node = self # Retrieve command line arguments passed through --pytest=... prefix = "--pytest=" # Filter to avoid scanning `plugins` and `lib` directories pytest_args = [x for x in os.listdir() if x.startswith("test_")] for arg in OS.get_cmdline_args(): if arg.startswith(prefix): pytest_args += arg[len(prefix):].split(",") # Run tests here return pytest.main(pytest_args)
def run_tests(self): global root_node root_node = self # Retrieve command line arguments passed through --pytest=... prefix = "--pytest=" pytest_args = [] for gdarg in OS.get_cmdline_args(): arg = str(gdarg) if arg.startswith(prefix): pytest_args += arg[len(prefix):].split(",") if all(arg.startswith("-") for arg in pytest_args): # Filter to avoid scanning `plugins` and `lib` directories pytest_args += [x for x in os.listdir() if x.startswith("test_")] # Run tests here print(f"running `pytest {' '.join(pytest_args)}`") return pytest.main(pytest_args)
def pybind_init_sys_path_and_argv(pythonpath, res_path, data_path): pythonpath = ffi.string(pythonpath) res_path = ffi.string(res_path) data_path = ffi.string(data_path) import sys from godot.bindings import OS sys.argv = ["godot"] + OS.get_cmdline_args() for p in pythonpath.split(';'): if p.startswith("res://"): p = p.replace("res:/", res_path, 1) elif p.startswith("user://"): p = p.replace("user:/", data_path, 1) sys.path.append(p) print('PYTHON_PATH: %s' % sys.path) return True
def _ready(self): # Exit godot OS.set_exit_code(0) self.get_tree().quit()