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