def test_should_show_new_version_notice(self): # Skip the check with mock.patch("streamlit.version.get_latest_streamlit_version" ) as get_latest: version.CHECK_PYPI_PROBABILITY = 0 self.assertFalse(should_show_new_version_notice()) get_latest.assert_not_called() # Check - outdated with mock.patch("streamlit.version.get_latest_streamlit_version" ) as get_latest, mock.patch( "streamlit.version.get_installed_streamlit_version" ) as get_installed: version.CHECK_PYPI_PROBABILITY = 1 get_installed.side_effect = ["1.0.0"] get_latest.side_effect = ["1.2.3"] self.assertTrue(should_show_new_version_notice()) get_installed.assert_called_once() get_latest.assert_called_once() # Check - up-to-date with mock.patch("streamlit.version.get_latest_streamlit_version" ) as get_latest, mock.patch( "streamlit.version.get_installed_streamlit_version" ) as get_installed: version.CHECK_PYPI_PROBABILITY = 1 get_installed.side_effect = ["1.2.3"] get_latest.side_effect = ["1.2.3"] self.assertFalse(should_show_new_version_notice()) get_installed.assert_called_once() get_latest.assert_called_once() # Check - error with mock.patch("streamlit.version.get_latest_streamlit_version" ) as get_latest, mock.patch( "streamlit.version.get_installed_streamlit_version" ) as get_installed: version.CHECK_PYPI_PROBABILITY = 1 get_installed.side_effect = ["1.2.3"] get_latest.side_effect = RuntimeError("apocalypse!") self.assertFalse(should_show_new_version_notice()) get_installed.assert_called_once() get_latest.assert_called_once()
def test_should_show_new_version_notice_skip(self): with mock.patch( "streamlit.version._get_latest_streamlit_version" ) as get_latest: version.CHECK_PYPI_PROBABILITY = 0 self.assertFalse(should_show_new_version_notice()) get_latest.assert_not_called()
def _main_run(file, args=[]): command_line = _get_command_line_as_string() # Set a global flag indicating that we're "within" streamlit. streamlit._is_running_with_streamlit = True # Check credentials. check_credentials() # Notify if streamlit is out of date. if version.should_show_new_version_notice(): click.echo(NEW_VERSION_TEXT) bootstrap.run(file, command_line, args)
def test_should_show_new_version_notice_error(self): with mock.patch( "streamlit.version._get_latest_streamlit_version" ) as get_latest, mock.patch( "streamlit.version._get_installed_streamlit_version" ) as get_installed: version.CHECK_PYPI_PROBABILITY = 1 get_installed.side_effect = [PkgVersion("1.2.3")] get_latest.side_effect = RuntimeError("apocalypse!") self.assertFalse(should_show_new_version_notice()) get_installed.assert_called_once() get_latest.assert_called_once()
def test_should_show_new_version_notice_outdated(self): with mock.patch( "streamlit.version._get_latest_streamlit_version" ) as get_latest, mock.patch( "streamlit.version._get_installed_streamlit_version" ) as get_installed: version.CHECK_PYPI_PROBABILITY = 1 get_installed.side_effect = [PkgVersion("1.0.0")] get_latest.side_effect = [PkgVersion("1.2.3")] self.assertTrue(should_show_new_version_notice()) get_installed.assert_called_once() get_latest.assert_called_once()
def test_should_show_new_version_notice_prerelease(self): with mock.patch( "streamlit.version._get_latest_streamlit_version" ) as get_latest, mock.patch( "streamlit.version._get_installed_streamlit_version" ) as get_installed: version.CHECK_PYPI_PROBABILITY = 1 get_installed.side_effect = [(1, 2, 3)] get_latest.side_effect = [(1, 0, 0)] self.assertFalse(should_show_new_version_notice()) get_installed.assert_called_once() get_latest.assert_called_once()
def _main_run(file, args=None, flag_options=None): if args is None: args = [] if flag_options is None: flag_options = {} command_line = _get_command_line_as_string() # Set a global flag indicating that we're "within" streamlit. streamlit._is_running_with_streamlit = True check_credentials() if version.should_show_new_version_notice(): click.echo(NEW_VERSION_TEXT) bootstrap.run(file, command_line, args, flag_options)
def _main_run(file, args=None): if args is None: args = [] # Set a global flag indicating that we're "within" streamlit. streamlit._is_running_with_streamlit = True # Check credentials. Credentials.get_current().check_activated(auto_resolve=True) # Notify if streamlit is out of date. if version.should_show_new_version_notice(): click.echo(NEW_VERSION_TEXT) # We don't use args ourselves. We just allow people to pass them so their # script can handle them via sys.argv or whatever. # IMPORTANT: This means we should treat argv carefully inside our code! import sys sys.argv = [file] + list(args) bootstrap.run(file)
def _print_new_version_message() -> None: if version.should_show_new_version_notice(): click.secho(NEW_VERSION_TEXT)