Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Instrumented Python Testing Script #5755

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading