def test_open_browser_linux_no_xdg(self): """Test opening the browser on Linux with no xdg installed""" from streamlit import env_util env_util.IS_LINUX_OR_BSD = True with patch("streamlit.env_util.is_executable_in_path", return_value=False): with patch("webbrowser.open") as webbrowser_open: with patch("subprocess.Popen") as subprocess_popen: util.open_browser("http://some-url") self.assertEqual(True, webbrowser_open.called) self.assertEqual(False, subprocess_popen.called)
def test_open_browser(self, os_type, webbrowser_expect, popen_expect): """Test web browser opening scenarios.""" from streamlit import env_util env_util.IS_WINDOWS = os_type == "Windows" env_util.IS_DARWIN = os_type == "Darwin" env_util.IS_LINUX_OR_BSD = os_type == "Linux" with patch("streamlit.env_util.is_executable_in_path", return_value=True): with patch("webbrowser.open") as webbrowser_open: with patch("subprocess.Popen") as subprocess_popen: util.open_browser("http://some-url") self.assertEqual(webbrowser_expect, webbrowser_open.called) self.assertEqual(popen_expect, subprocess_popen.called)
def maybe_open_browser(): if config.get_option("server.headless"): # Don't open browser when in headless mode. return if server.browser_is_connected: # Don't auto-open browser if there's already a browser connected. # This can happen if there's an old tab repeatedly trying to # connect, and it happens to success before we launch the browser. return if config.is_manually_set("browser.serverAddress"): addr = config.get_option("browser.serverAddress") else: addr = "localhost" util.open_browser(Report.get_url(addr))
def main_docs(): """Show help in browser.""" print("Showing help page in browser...") from streamlit import util util.open_browser("https://docs.streamlit.io")
def main_docs(): """Show help in browser.""" print('Showing help page in browser...') from streamlit import util util.open_browser('https://streamlit.io/secret/docs')