-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
ATO-554 add BlockingIOError handler, tests and portalocker #12271
ATO-554 add BlockingIOError handler, tests and portalocker #12271
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍🏻
Left some suggestions in the comments.
changelog/12271.bugfix.md
Outdated
@@ -0,0 +1 @@ | |||
Fix `BlockingIOError` when running `rasa cli` on utterances with more than 5KB of text. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be more specific about which CLI command causes this issue (I think it's rasa shell
, could also be rasa interactive
), please double-check with @trammell.
tests/shared/utils/test_io.py
Outdated
|
||
mock = Mock() | ||
monkeypatch.setattr(builtins, "print", mock_print) | ||
monkeypatch.setattr(rasa.shared.utils.io, "handle_print_blocking", mock) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're mocking the function we want to test, we're not actually testing it, but I'd suggest to at least assert that mock was called with the desired output (in addition to the call_count
assertion).
Also pytest has a good fixture for capturing stdout: capsys
(https://docs.pytest.org/en/7.1.x/how-to/capture-stdout-stderr.html), have you tried with that too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried with capsys
but it captures only the text output to stdout/stderr and not the system calls to lock/unlock stdout. After trying with capsys
and capfd
I decided to mock it but there was no good way (that I know of) to assert that lock/unlock happened so I was left with this...
|
||
# Can't manipulate the STDOUT file descriptor | ||
# in pytest (it's a io.StringIO instance not a file) | ||
def test_handle_print_blocking(monkeypatch: MonkeyPatch): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a test of handle_print_blocking
but rather of the function which is calling it. Please move this test to the proper module and rename it to match the test case of parent caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the tests to -> test_cli.py and renamed appropriately
@@ -626,3 +625,21 @@ def is_subdirectory(path: Text, potential_parent_directory: Text) -> bool: | |||
def random_string(length: int) -> Text: | |||
"""Returns a random string of given length.""" | |||
return "".join(random.choices(string.ascii_uppercase + string.digits, k=length)) | |||
|
|||
|
|||
def handle_print_blocking(output: Text) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must add unit test for this function to make sure that:
- portalocker.Lock is called properly - mock
Lock
function - AnsiToWin32 is called properly if
sys.platform == "win32"
- print is called with proper
output
,file
andflush
parameters
One Note: |
@radovanZRasa I was not able to reproduce it 100% of the time It happens mostly on MacOS |
…large-1-k-utterance-length
…large-1-k-utterance-length
…large-1-k-utterance-length
🚀 A preview of the docs have been deployed at the following URL: https://12271--rasahq-docs-rasa-v2.netlify.app/docs/rasa |
Proposed changes:
Status (please check what you already did):
black
(please check Readme for instructions)