Beispiel #1
0
 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()
Beispiel #2
0
 def test_get_module_paths_domain_dne_throws(self):
     '''Should error when a domain path does not exist.'''
     host_cfg = HostConfig(None, None)
     host_cfg.domains = [self.root / 'dne']
     host_cfg.modules = ['mod']
     mod_gen = get_module_paths(host_cfg)
     with self.assertRaises(FileNotFoundError):
         next(mod_gen)
Beispiel #3
0
 def test_set_theme(self):
     '''Test setting the active theme.'''
     host_config = HostConfig(Path(self.theme_dir.name), None)
     templater = Templater(Path(self.link_dir.name), host_config)
     templater.set_theme('cooltheme')
     active_theme_path = Path(self.link_dir.name) / 'theme.yaml'
     self.assertEqual(  # this is maybe questionable
         Path(os.readlink(active_theme_path)),
         Path(self.theme_dir.name) / 'cooltheme.yaml')
Beispiel #4
0
 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'])
Beispiel #5
0
 def test_list_colors(self):
     '''Test listing the available colors.'''
     colors_path = Path(self.color_dir.name)
     (colors_path / Path('coolcolor.yaml')).touch()
     (colors_path / Path('radcolor.yaml')).touch()
     host_config = HostConfig(None, colors_path)
     templater = Templater(Path(self.link_dir.name), host_config)
     self.assertCountEqual(templater.list_colors(),
                           ['coolcolor', 'radcolor'])
Beispiel #6
0
 def test_get_module_paths_module_dne_ignore(self):
     '''Should ignore a module path that does not exist.'''
     host_cfg = HostConfig(None, None)
     host_cfg.domains = [self.root / 'dom1']
     host_cfg.modules = ['mod']
     (self.root / 'dom1').mkdir()
     mod_gen = get_module_paths(host_cfg)
     with self.assertRaises(StopIteration):
         next(mod_gen)
Beispiel #7
0
 def test_get_module_paths_domain_is_file_throws(self):
     '''Should error when a domain path points to a file.'''
     host_cfg = HostConfig(None, None)
     host_cfg.domains = [self.root / 'is_file']
     host_cfg.modules = ['mod']
     (self.root / 'is_file').touch()
     mod_gen = get_module_paths(host_cfg)
     with self.assertRaises(NotADirectoryError):
         next(mod_gen)
Beispiel #8
0
 def test_set_color(self):
     '''Test setting the active color.'''
     host_config = HostConfig(Path(self.color_dir.name),
                              Path(self.color_dir.name))
     templater = Templater(Path(self.link_dir.name), host_config)
     templater.set_color('coolcolor')
     active_color_path = Path(self.link_dir.name) / 'color.yaml'
     self.assertEqual(  # this is maybe questionable
         Path(os.readlink(active_color_path)),
         Path(self.color_dir.name) / 'coolcolor.yaml')
Beispiel #9
0
 def test_template_conf_dne(self):
     '''Test templating a string.'''
     theme_path = self.theme_dir / 'main.yaml'
     color_path = self.color_dir / 'main.yaml'
     (self.link_dir / 'theme.yaml').symlink_to(theme_path)
     (self.link_dir / 'color.yaml').symlink_to(color_path)
     theme_path.write_text('theme: cooltheme')
     host_cfg = HostConfig(self.theme_dir, self.color_dir)
     templater = Templater(self.link_dir, host_cfg)
     with self.assertRaises(LinkMalformedError):
         templater.template('theme: {{theme}}\ncolor: {{color}}')
Beispiel #10
0
 def test_get_module_paths_duplicate_domain_throws(self):
     '''Should error when a domain path is duplicated.'''
     host_cfg = HostConfig(None, None)
     host_cfg.domains = [
         self.root / 'seeingdouble', self.root / 'seeingdouble'
     ]
     host_cfg.modules = ['mod']
     (self.root / 'seeingdouble').mkdir()
     mod_gen = get_module_paths(host_cfg)
     with self.assertRaises(DuplicateDomainError):
         next(mod_gen)
Beispiel #11
0
 def test_template(self):
     '''Test templating a string.'''
     theme_path = self.theme_dir / 'main.yaml'
     color_path = self.color_dir / 'main.yaml'
     (self.link_dir / 'theme.yaml').symlink_to(theme_path)
     (self.link_dir / 'color.yaml').symlink_to(color_path)
     theme_path.write_text('theme: cooltheme')
     color_path.write_text('color: coolcolor')
     host_cfg = HostConfig(self.theme_dir, self.color_dir)
     templater = Templater(self.link_dir, host_cfg)
     out_str = templater.template('theme: {{theme}}\ncolor: {{color}}')
     self.assertEqual(out_str, 'theme: cooltheme\ncolor: coolcolor')
Beispiel #12
0
 def test_template_after_set_color(self):
     '''Test that set_color changes the output even after first use.'''
     theme_path = self.theme_dir / 'main.yaml'
     color_path = self.color_dir / 'main.yaml'
     new_color_path = self.color_dir / 'new.yaml'
     (self.link_dir / 'theme.yaml').symlink_to(theme_path)
     (self.link_dir / 'color.yaml').symlink_to(color_path)
     theme_path.write_text('theme: cooltheme')
     color_path.write_text('color: coolcolor')
     new_color_path.write_text('color: newcolor')
     host_cfg = HostConfig(self.theme_dir, self.color_dir)
     templater = Templater(self.link_dir, host_cfg)
     templater.template('theme: {{theme}}\ncolor: {{color}}')
     templater.set_color('new')
     out_str = templater.template('theme: {{theme}}\ncolor: {{color}}')
     self.assertEqual(out_str, 'theme: cooltheme\ncolor: newcolor')
Beispiel #13
0
 def test_get_module_paths_correct_order(self):
     '''Should return module paths in order, skipping if dne.'''
     host_cfg = HostConfig(None, None)
     host_cfg.domains = [self.root / 'dom1', self.root / 'dom2']
     host_cfg.modules = ['mod1', 'mod2']
     (self.root / 'dom1').mkdir()
     (self.root / 'dom2').mkdir()
     (self.root / 'dom1' / 'mod1').mkdir()
     (self.root / 'dom1' / 'mod2').mkdir()
     (self.root / 'dom2' / 'mod2').mkdir()
     mod_gen = get_module_paths(host_cfg)
     self.assertEqual(
         [next(mod_gen), next(mod_gen),
          next(mod_gen)], [
              self.root / 'dom1' / 'mod1', self.root / 'dom1' / 'mod2',
              self.root / 'dom2' / 'mod2'
          ])
     with self.assertRaises(StopIteration):
         next(mod_gen)
Beispiel #14
0
 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(), [])
Beispiel #15
0
 def test_list_colors_dir_empty(self):
     '''Test listing the colors with none available.'''
     colors_path = Path(self.color_dir.name)
     host_config = HostConfig(None, colors_path)
     templater = Templater(Path(self.link_dir.name), host_config)
     self.assertCountEqual(templater.list_colors(), [])