Skip to content

bpo-31014: webbrowser._synthesize calls webbrowser.register with outdated signature #2689

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
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
19 changes: 19 additions & 0 deletions Lib/test/test_webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import subprocess
from unittest import mock
from test import support
from test.support import script_helper
import textwrap


URL = 'http://www.example.com'
Expand Down Expand Up @@ -265,6 +267,23 @@ def test_register_default(self):
def test_register_preferred(self):
self._check_registration(preferred=True)

def test_environment_variable_BROWSER_is_respected(self):
Copy link
Author

Choose a reason for hiding this comment

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

This test does accurately catch the regression as far as I can tell but it seems a little obscure. Thoughts?

script_helper.assert_python_ok("-c", textwrap.dedent("""
import shutil, unittest
from test import support, test_webbrowser

def mock_which(path):
return True

class Test(test_webbrowser.ImportTest):
Copy link
Contributor

Choose a reason for hiding this comment

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

I almost missed that this re-ran the ImportTest suite with BROWSER set.

I think that's OK as a test case, but it would be clearer as part of a dedicated BrowserOverrideTest class that's placed after ImportTest (and mentions in a class level comment that it re-runs the ImportTest cases in a subprocess with BROWSER set.


def setUp(self):
super().setUp()
support.patch(self, shutil, 'which', mock_which)

unittest.main()
"""), BROWSER='test_browser')


class ImportTest(unittest.TestCase):
def test_register(self):
Expand Down
6 changes: 3 additions & 3 deletions Lib/webbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def open_new_tab(url):
return open(url, 2)


def _synthesize(browser, update_tryorder=1):
def _synthesize(browser, update_tryorder=True):
"""Attempt to synthesize a controller base on existing controllers.

This is useful to create a controller when a user specifies a path to
Expand All @@ -113,7 +113,7 @@ def _synthesize(browser, update_tryorder=1):
controller = copy.copy(controller)
controller.name = browser
controller.basename = os.path.basename(browser)
register(browser, None, controller, update_tryorder)
register(browser, None, instance=controller, preferred=update_tryorder)
Copy link
Member

@serhiy-storchaka serhiy-storchaka Jul 24, 2017

Choose a reason for hiding this comment

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

update_tryorder is 1 or -1. preferred is a boolean parameter. 1 and -1 both are true in boolean context.

I think that the update_tryorder parameter of _synthesize() should be replaced with boolean preferred as in register() (see bpo-24241).

Copy link
Author

Choose a reason for hiding this comment

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

Update tryorder is now a boolean as requested.

return [None, controller]
return [None, None]

Expand Down Expand Up @@ -564,7 +564,7 @@ def register_standard_browsers():
# and prepend to _tryorder
for cmdline in userchoices:
if cmdline != '':
cmd = _synthesize(cmdline, -1)
cmd = _synthesize(cmdline, update_tryorder=False)
if cmd[1] is None:
register(cmdline, None, GenericBrowser(cmdline), preferred=True)

Expand Down