Skip to content

Commit

Permalink
Improve Instrumented Python Testing Script
Browse files Browse the repository at this point in the history
For betting debugging and earlier stop in case of termination, like in
#5754 (comment)

closes #5755

No functional change
  • Loading branch information
Disservin committed Jan 12, 2025
1 parent d49fd90 commit ea71a08
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def __init__(self):
self.failed_test_suites = 0
self.passed_tests = 0
self.failed_tests = 0
self.stop_on_failure = True

def has_failed(self) -> bool:
return self.failed_test_suites > 0
Expand All @@ -167,6 +168,9 @@ def run(self, classes: List[type]) -> bool:
self.failed_test_suites += 1
else:
self.passed_test_suites += 1
except Exception as e:
self.failed_test_suites += 1
print(f"\n{RED_COLOR}Error: {e}{RESET_COLOR}")
finally:
os.chdir(original_cwd)

Expand Down Expand Up @@ -226,6 +230,10 @@ def __run_test_method(self, test_instance, method: str) -> int:
if isinstance(e, AssertionError):
self.__handle_assertion_error(t0, method)

if self.stop_on_failure:
self.__print_buffer_output(buffer)
raise e

fails += 1
finally:
self.__print_buffer_output(buffer)
Expand Down Expand Up @@ -286,6 +294,11 @@ def __init__(

self.start()

def _check_process_alive(self):
if not self.process or self.process.poll() is not None:
print("\n".join(self.output))
raise RuntimeError("Stockfish process has terminated")

def start(self):
if self.cli:
self.process = subprocess.run(
Expand Down Expand Up @@ -314,6 +327,8 @@ def send_command(self, command: str):
if not self.process:
raise RuntimeError("Stockfish process is not started")

self._check_process_alive()

self.process.stdin.write(command + "\n")
self.process.stdin.flush()

Expand Down Expand Up @@ -355,6 +370,7 @@ def readline(self):
raise RuntimeError("Stockfish process is not started")

while True:
self._check_process_alive()
line = self.process.stdout.readline().strip()
self.output.append(line)

Expand Down

0 comments on commit ea71a08

Please sign in to comment.