Python EPI: Only print stdout on failures#239
Open
LeafyLi wants to merge 1 commit intoadnanaziz:masterfrom
Open
Python EPI: Only print stdout on failures#239LeafyLi wants to merge 1 commit intoadnanaziz:masterfrom
LeafyLi wants to merge 1 commit intoadnanaziz:masterfrom
Conversation
LeafyLi
commented
Nov 25, 2022
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) |
Author
There was a problem hiding this comment.
The only actual change is wrapping everything in a with redirect_stdout(stdout_capturer):. I think it's possible to just wrap
EPIJudge/epi_judge_python/test_framework/generic_test_handler.py
Lines 95 to 99 in da8aaae
but I think the current method is clearer. Open to other opinions though!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:

after:
