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

Python EPI: Only print stdout on failures #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LeafyLi
Copy link

@LeafyLi LeafyLi commented Nov 25, 2022

I recommended EPI(Judge) to a friend, and she's complained that successful testcases pollute stdout when debugging failed one. This fixes that.

E.g., using Dutch National Flag and failing on something random (asserting array != [1])

before:
image

after:
image

Comment on lines -77 to +105
expected_param_count = len(
self._param_traits) + (0 if self.expected_is_void() else 1)
if len(test_args) != expected_param_count:
raise RuntimeError(
'Invalid argument count: expected {}, actual {}'.format(
expected_param_count, len(test_args)))

parsed = [
param_trait.parse(json.loads(test_arg))
for param_trait, test_arg in zip(self._param_traits, test_args)
]

metrics = self.calculate_metrics(parsed)
metrics = metrics_override(metrics, *parsed)

executor = TimedExecutor(timeout_seconds)
if self._has_executor_hook:
result = self._func(executor, *parsed)
else:
result = executor.run(lambda: self._func(*parsed))

if not self.expected_is_void():
expected = self._ret_value_trait.parse(json.loads(test_args[-1]))
self._assert_results_equal(expected, result)

return TestOutput(executor.get_timer(), metrics)
with redirect_stdout(stdout_capturer):
expected_param_count = len(
self._param_traits) + (0 if self.expected_is_void() else 1)
if len(test_args) != expected_param_count:
raise RuntimeError(
'Invalid argument count: expected {}, actual {}'.format(
expected_param_count, len(test_args)))

parsed = [
param_trait.parse(json.loads(test_arg))
for param_trait, test_arg in zip(self._param_traits, test_args)
]

metrics = self.calculate_metrics(parsed)
metrics = metrics_override(metrics, *parsed)

executor = TimedExecutor(timeout_seconds)
if self._has_executor_hook:
result = self._func(executor, *parsed)
else:
result = executor.run(lambda: self._func(*parsed))

if not self.expected_is_void():
expected = self._ret_value_trait.parse(json.loads(test_args[-1]))
self._assert_results_equal(expected, result)

return TestOutput(executor.get_timer(), metrics)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only actual change is wrapping everything in a with redirect_stdout(stdout_capturer):. I think it's possible to just wrap

executor = TimedExecutor(timeout_seconds)
if self._has_executor_hook:
result = self._func(executor, *parsed)
else:
result = executor.run(lambda: self._func(*parsed))

but I think the current method is clearer. Open to other opinions though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant