def test_check_theme_completeness_with_theme_fully_set(self): theme_options = config.get_options_for_section("theme") for opt in REQUIRED_THEME_OPTIONS: theme_options[opt] = "Test" self.assertEqual( theme.check_theme_completeness(theme_options), theme.ThemeCompleteness.FULLY_DEFINED, )
def test_check_theme_completeness_with_partial_config(self): theme_options = config.get_options_for_section("theme") theme_options[REQUIRED_THEME_OPTIONS[0]] = "Test" self.assertEqual( theme.check_theme_completeness(theme_options), theme.ThemeCompleteness.PARTIALLY_DEFINED, )
def _validate_theme() -> None: # Import logger locally to prevent circular references from streamlit.logger import get_logger LOGGER = get_logger(__name__) theme_opts = get_options_for_section("theme") if ( theme.check_theme_completeness(theme_opts) == theme.ThemeCompleteness.PARTIALLY_DEFINED ): LOGGER.warning( "Theme options only partially defined. To specify a theme, please" " set all required options." )
def _populate_theme_msg(msg: CustomThemeConfig) -> None: theme_opts = config.get_options_for_section("theme") if (theme.check_theme_completeness(theme_opts) != theme.ThemeCompleteness.FULLY_DEFINED): return for option_name, option_val in theme_opts.items(): # We don't set the "font" option here as it needs to be converted # from string -> enum. if option_name != "font" and option_val is not None: setattr(msg, to_snake_case(option_name), option_val) font_map = { "sans serif": msg.FontFamily.SANS_SERIF, "serif": msg.FontFamily.SERIF, "monospace": msg.FontFamily.MONOSPACE, } msg.font = font_map.get( config.get_option("theme.font"), msg.FontFamily.SANS_SERIF, )