Hugoifier

hugoifier / tests / test_analyze.py
Source Blame History 60 lines
6272677… lmata 1 """Tests for utils.analyze."""
6272677… lmata 2 import os
6272677… lmata 3 import tempfile
48176db… ragelink 4 import unittest
6272677… lmata 5
91515c0… lmata 6 from hugoifier.utils.analyze import _analyze_hugo_theme
6272677… lmata 7
6272677… lmata 8
6272677… lmata 9 class TestAnalyzeHugoTheme(unittest.TestCase):
6272677… lmata 10 def _make_theme_info(self, tmp, layouts=None, example_site=None):
6272677… lmata 11 theme_dir = os.path.join(tmp, "test-theme")
6272677… lmata 12 layouts_dir = os.path.join(theme_dir, "layouts", "_default")
6272677… lmata 13 os.makedirs(layouts_dir)
6272677… lmata 14 for name in (layouts or ["baseof.html", "single.html"]):
6272677… lmata 15 open(os.path.join(layouts_dir, name), "w").close()
6272677… lmata 16 return {
6272677… lmata 17 "theme_dir": theme_dir,
6272677… lmata 18 "theme_name": "test-theme",
6272677… lmata 19 "example_site": example_site,
6272677… lmata 20 "is_hugo_theme": True,
6272677… lmata 21 }
6272677… lmata 22
6272677… lmata 23 def test_reports_theme_name(self):
6272677… lmata 24 with tempfile.TemporaryDirectory() as tmp:
6272677… lmata 25 info = self._make_theme_info(tmp)
6272677… lmata 26 result = _analyze_hugo_theme(info)
6272677… lmata 27 self.assertIn("test-theme", result)
6272677… lmata 28
6272677… lmata 29 def test_lists_layout_files(self):
6272677… lmata 30 with tempfile.TemporaryDirectory() as tmp:
6272677… lmata 31 info = self._make_theme_info(tmp, layouts=["baseof.html", "single.html"])
6272677… lmata 32 result = _analyze_hugo_theme(info)
6272677… lmata 33 self.assertIn("baseof.html", result)
6272677… lmata 34 self.assertIn("single.html", result)
6272677… lmata 35
6272677… lmata 36 def test_reports_no_example_site(self):
6272677… lmata 37 with tempfile.TemporaryDirectory() as tmp:
6272677… lmata 38 info = self._make_theme_info(tmp, example_site=None)
6272677… lmata 39 result = _analyze_hugo_theme(info)
6272677… lmata 40 self.assertIn("none", result.lower())
6272677… lmata 41
6272677… lmata 42 def test_reports_content_types_from_example_site(self):
6272677… lmata 43 with tempfile.TemporaryDirectory() as tmp:
6272677… lmata 44 info = self._make_theme_info(tmp)
6272677… lmata 45 example = os.path.join(tmp, "exampleSite")
6272677… lmata 46 content = os.path.join(example, "content", "blog")
6272677… lmata 47 os.makedirs(content)
6272677… lmata 48 info["example_site"] = example
6272677… lmata 49 result = _analyze_hugo_theme(info)
6272677… lmata 50 self.assertIn("blog", result)
6272677… lmata 51
6272677… lmata 52 def test_suggests_complete_command(self):
6272677… lmata 53 with tempfile.TemporaryDirectory() as tmp:
6272677… lmata 54 info = self._make_theme_info(tmp)
6272677… lmata 55 result = _analyze_hugo_theme(info)
6272677… lmata 56 self.assertIn("complete", result)
6272677… lmata 57
6272677… lmata 58
6272677… lmata 59 if __name__ == "__main__":
6272677… lmata 60 unittest.main()

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button