fix: restore validation suite
This commit is contained in:
+13
-1
@@ -172,7 +172,19 @@ def search(
|
||||
match.valid = match.score >= threshold
|
||||
return match
|
||||
|
||||
# Multiple templates — parallel search
|
||||
# Multiple templates default to first valid match in input order.
|
||||
if not best_match:
|
||||
best = TemplateMatch()
|
||||
for template in templates:
|
||||
match = _single_template_match(template, inp_img, roi, color_match, use_grayscale)
|
||||
match.valid = match.score >= threshold
|
||||
if match.score > best.score:
|
||||
best = match
|
||||
if match.valid:
|
||||
return match
|
||||
return best
|
||||
|
||||
# Multiple templates with best_match=True return the highest score.
|
||||
matches = []
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
|
||||
futures = [
|
||||
|
||||
@@ -22,7 +22,7 @@ def _git_restore():
|
||||
|
||||
|
||||
def _run(args, expect_rc=0):
|
||||
r = subprocess.run(["python3", CLI] + args, cwd=PROJECT,
|
||||
r = subprocess.run([sys.executable, CLI] + args, cwd=PROJECT,
|
||||
capture_output=True, text=True)
|
||||
if expect_rc != 0 and r.returncode == 0:
|
||||
raise AssertionError(f"Expected failure but got success: {r.stdout}")
|
||||
@@ -32,7 +32,7 @@ def _run(args, expect_rc=0):
|
||||
|
||||
|
||||
def _compile_ok():
|
||||
r = subprocess.run(["python3", "-m", "py_compile", "src/bot.py"],
|
||||
r = subprocess.run([sys.executable, "-m", "py_compile", "src/bot.py"],
|
||||
cwd=PROJECT, capture_output=True, text=True)
|
||||
if r.returncode != 0:
|
||||
raise AssertionError(f"py_compile failed: {r.stderr}")
|
||||
|
||||
+4
-11
@@ -247,8 +247,7 @@ def insert_handler(bot_path, name, display):
|
||||
text = _read(bot_path)
|
||||
if "def on_run_" + name in text:
|
||||
return False
|
||||
short = display[:3] if display else name[:3]
|
||||
pat = r'( def on_run_[a-z_]+\(self\):.*?_ending_run_helper\(res\))'
|
||||
pat = r'( def on_run_[a-z_]+\(self\):\n(?: [^\n]*\n)+)'
|
||||
matches = list(re.finditer(pat, text, re.DOTALL))
|
||||
if not matches:
|
||||
raise ValueError("Cannot find existing handler pattern")
|
||||
@@ -256,14 +255,8 @@ def insert_handler(bot_path, name, display):
|
||||
h = [
|
||||
"",
|
||||
" def on_run_" + name + "(self):",
|
||||
" res = False",
|
||||
" self._do_runs[" + Q2 + "run_" + name + Q2 + "] = False",
|
||||
" self._game_stats.update_location(" + Q2 + short + Q2 + ")",
|
||||
" self._curr_loc = self._" + name + ".approach(self._curr_loc)",
|
||||
" if self._curr_loc:",
|
||||
" set_pause_state(False)",
|
||||
" res = self._" + name + ".battle(not self._pre_buffed)",
|
||||
" self._ending_run_helper(res)",
|
||||
" self._game_stats.update_location(" + Q2 + display + Q2 + ")",
|
||||
" self._run_wrapper(" + Q2 + "run_" + name + Q2 + ", self._" + name + ", (), (not self._pre_buffed,))",
|
||||
]
|
||||
handler = NL.join(h) + NL
|
||||
result = text[:last.end()] + handler + text[last.end():]
|
||||
@@ -274,7 +267,7 @@ def insert_handler(bot_path, name, display):
|
||||
def undo_handler(bot_path, name):
|
||||
text = _read(bot_path)
|
||||
pat = re.compile(
|
||||
r'\n\s*def on_run_' + re.escape(name) + r'\(self\):.*?_ending_run_helper\(res\)\n',
|
||||
r'\n\s*def on_run_' + re.escape(name) + r'\(self\):\n(?: [^\n]*\n)+',
|
||||
re.DOTALL
|
||||
)
|
||||
t = pat.sub("", text)
|
||||
|
||||
Reference in New Issue
Block a user