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

fix: test and fix error handling in open_browser #282

Merged
merged 10 commits into from
Oct 23, 2024
Merged

Conversation

bloodearnest
Copy link
Member

This fixes an ugly message for a user when something didn't work right.

There were two errors:

  • a missing default definition of response
  • the special formatting of exceptions was broken.

These were not covered by tests, as it was awkward to do. But its caused
breakage, so this PR grasps the nettle and adds coverage for:

  • rstudio command opening the browser
  • jupyter command getting metadata and opening the browser
  • open_browser error cases

This required some refactoring of the SubprocessRunFixture, and some other
clean ups.

As a result, test coverage went up by 6%.

  • Refactor SubprocessRunFixture to handle concurrent declarations
  • Explicitly mock open_browser call in test_rstudio.py
  • Fully mock/test jupyter browser calls
  • use requests rather than urllib, as its easier to use
  • fix: fix issue in exception rendering refactor
  • Refactor threaded debugging to work for testing
  • Test and fix the open_browser error handling
  • bump coverage minimum up 6 to 88

The original implementation requires that commands were executed in the
order they were declared, which has worked fine so far. However, when
testing some of our threaded behaviour, this was not a valid assumption.

This refactors the fixture to add support for setting `run.concurrent
= True`, which will match *any* specified command, rather than the next
one. The default behaviour is still to require them in order.

As an implementation detail, it meant switching away from deque to list
made sense, as we want to now be able to remove from anywhere in the
list.

Note that tests using this new functionality will be in next commit.
The call to `webbrowser.open` calls a subprocess, which will fail as
we've not called run.expect for it. However, this error was hidden as
test exits quickly enough that it doesn't appear, unless its slow for
some reason.

This change mocks the call to open_browser, and checks that it is
actually called.
We'd previously cheated by passing `--no-browser` to the jupyter call,
which avoided testing it.

However, this was lazy, and left that code path uncovered. So, here we
fully mock/test that flow as well, by:

 - mocking/testing utils.open_browser
 - using the new run.concurrent support to mock/assert that the relevant
   calls are happening.
Switch dyanmically at call time rather than at import time. This allows
us to more easily enable debug logs in tests.

Also, a small UX tweak - always print a message to the user if we cannot
open browser, rather than failing silently
This wasn't covered before, and had some issues. This adds coverate for
timeout and error scenarios, and fixes an error found by these tests.
@bloodearnest bloodearnest changed the title Test and fix error handling in open_browser fix: test and fix error handling in open_browser Oct 21, 2024
tests/test_jupyter.py Outdated Show resolved Hide resolved
We can't easily pass the cli args to threads, so we've used a DEBUG env
var for debugging threaded code. This simplifies all debug output behind
the --debug flag.
@bloodearnest bloodearnest merged commit 907413e into main Oct 23, 2024
12 checks passed
@bloodearnest bloodearnest deleted the fix-open-browser branch October 23, 2024 11:43
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.

3 participants