"""Lightweight stubs so App Runtime tests run without the full server venv."""
|
|
import os
|
import sys
|
from types import ModuleType
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
if ROOT not in sys.path:
|
sys.path.insert(0, ROOT)
|
|
|
class _SilentLogger:
|
def bind(self, **kwargs):
|
return self
|
|
def info(self, *args, **kwargs):
|
return None
|
|
def warning(self, *args, **kwargs):
|
return None
|
|
def error(self, *args, **kwargs):
|
return None
|
|
def debug(self, *args, **kwargs):
|
return None
|
|
|
_LOG = _SilentLogger()
|
|
|
def _install(name, module):
|
sys.modules.setdefault(name, module)
|
|
|
if "config.logger" not in sys.modules:
|
logger_mod = ModuleType("config.logger")
|
logger_mod.setup_logging = lambda *args, **kwargs: _LOG
|
logger_mod.build_module_string = lambda *args, **kwargs: "0" * 14
|
logger_mod.create_connection_logger = lambda *args, **kwargs: _LOG
|
logger_mod.logger = _LOG
|
_install("config.logger", logger_mod)
|
|
if "config.config_loader" not in sys.modules:
|
loader_mod = ModuleType("config.config_loader")
|
loader_mod.get_project_dir = lambda: ROOT.replace("\\", "/") + "/"
|
_install("config.config_loader", loader_mod)
|
|
|
def _remove_punctuation_and_length(text):
|
full_width = "!"#$%&'()*+,-。/:;<=>?@[\]^_`{|}~"
|
half_width = r'!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~'
|
result = "".join(
|
ch
|
for ch in (text or "")
|
if ch not in full_width and ch not in half_width and ch not in (" ", " ")
|
)
|
if result == "Yeah":
|
return 0, ""
|
return len(result), result
|
|
|
if "core.utils.util" not in sys.modules:
|
util_mod = ModuleType("core.utils.util")
|
util_mod.remove_punctuation_and_length = _remove_punctuation_and_length
|
_install("core.utils.util", util_mod)
|