def test_list_themes_path_nonexistent_raises(self): '''Test listing the available themes when the dir does not exist.''' themes_path = Path(self.theme_dir.name) / Path('dne') host_config = HostConfig(themes_path, None) templater = Templater(Path(self.link_dir.name), host_config) with self.assertRaises(FileNotFoundError): templater.list_themes()
def _pick_theme_interactive(templater: Templater, host_cfg: hostconfig.HostConfig, flag: str) -> str: '''Picks a theme and maybe prompts based on current state.''' return flag or templater.get_theme() or click.prompt( 'Select a theme', default=host_cfg.default_theme, type=click.Choice(templater.list_themes()))
def set_theme(name: str): '''Set the theme to NAME and redeploy.''' host_cfg = hostconfig.from_file(ACTIVE_HOST_PATH) templater = Templater(MODOT_PATH, host_cfg) if name not in templater.list_themes(): sys.exit(f'Could not find specified theme {name}') templater.set_theme(name) _check_and_deploy(host_cfg, templater, dryrun=False)
def test_list_themes(self): '''Test listing the available themes.''' themes_path = Path(self.theme_dir.name) (themes_path / Path('cooltheme.yaml')).touch() (themes_path / Path('radtheme.yaml')).touch() host_config = HostConfig(themes_path, None) templater = Templater(Path(self.link_dir.name), host_config) self.assertCountEqual(templater.list_themes(), ['cooltheme', 'radtheme'])
def test_list_themes_dir_empty(self): '''Test listing the themes with none available.''' themes_path = Path(self.theme_dir.name) host_config = HostConfig(themes_path, None) templater = Templater(Path(self.link_dir.name), host_config) self.assertCountEqual(templater.list_themes(), [])
def list_themes(): '''List all themes found in the themes directory.''' templater = Templater(MODOT_PATH, hostconfig.from_file(ACTIVE_HOST_PATH)) for name in templater.list_themes(): print(name)