summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_webbrowser.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2017-02-25 08:14:07 (GMT)
committerGitHub <noreply@github.com>2017-02-25 08:14:07 (GMT)
commit56a8eccc43c66ae51c5a6bfc89635b1998fd419e (patch)
tree49f32220467b76b901b72cb10ae7142c6ac482d4 /Lib/test/test_webbrowser.py
parente3ce69522ffd7c0354d6e70d18f42bce325ed97e (diff)
downloadcpython-56a8eccc43c66ae51c5a6bfc89635b1998fd419e.zip
cpython-56a8eccc43c66ae51c5a6bfc89635b1998fd419e.tar.gz
cpython-56a8eccc43c66ae51c5a6bfc89635b1998fd419e.tar.bz2
bpo-24241: Add dedicated webbrowser.register test case (#288)
Diffstat (limited to 'Lib/test/test_webbrowser.py')
-rw-r--r--Lib/test/test_webbrowser.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/Lib/test/test_webbrowser.py b/Lib/test/test_webbrowser.py
index e46b6fb..622c1cb 100644
--- a/Lib/test/test_webbrowser.py
+++ b/Lib/test/test_webbrowser.py
@@ -213,5 +213,58 @@ class ELinksCommandTest(CommandTestMixin, unittest.TestCase):
arguments=['openURL({},new-tab)'.format(URL)])
+class BrowserRegistrationTest(unittest.TestCase):
+
+ def setUp(self):
+ # Ensure we don't alter the real registered browser details
+ self._saved_tryorder = webbrowser._tryorder
+ webbrowser._tryorder = []
+ self._saved_browsers = webbrowser._browsers
+ webbrowser._browsers = {}
+
+ def tearDown(self):
+ webbrowser._tryorder = self._saved_tryorder
+ webbrowser._browsers = self._saved_browsers
+
+ def _check_registration(self, preferred):
+ class ExampleBrowser:
+ pass
+
+ expected_tryorder = []
+ expected_browsers = {}
+
+ self.assertEqual(webbrowser._tryorder, expected_tryorder)
+ self.assertEqual(webbrowser._browsers, expected_browsers)
+
+ webbrowser.register('Example1', ExampleBrowser)
+ expected_tryorder = ['Example1']
+ expected_browsers['example1'] = [ExampleBrowser, None]
+ self.assertEqual(webbrowser._tryorder, expected_tryorder)
+ self.assertEqual(webbrowser._browsers, expected_browsers)
+
+ instance = ExampleBrowser()
+ if preferred is not None:
+ webbrowser.register('example2', ExampleBrowser, instance,
+ preferred=preferred)
+ else:
+ webbrowser.register('example2', ExampleBrowser, instance)
+ if preferred:
+ expected_tryorder = ['example2', 'Example1']
+ else:
+ expected_tryorder = ['Example1', 'example2']
+ expected_browsers['example2'] = [ExampleBrowser, instance]
+ self.assertEqual(webbrowser._tryorder, expected_tryorder)
+ self.assertEqual(webbrowser._browsers, expected_browsers)
+
+ def test_register(self):
+ self._check_registration(preferred=False)
+
+ def test_register_default(self):
+ self._check_registration(preferred=None)
+
+ def test_register_preferred(self):
+ self._check_registration(preferred=True)
+
+
if __name__=='__main__':
unittest.main()