summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/log_test.py189
-rw-r--r--tests/overview_test.py8
-rw-r--r--tests/page_test.py19
4 files changed, 216 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/log_test.py b/tests/log_test.py
new file mode 100644
index 0000000..1efe3bd
--- /dev/null
+++ b/tests/log_test.py
@@ -0,0 +1,189 @@
+from g2h.log_page import LogPage
+from unittest.mock import MagicMock
+
+def test_init():
+ page = LogPage('test/log', 'log test', None, None, None)
+ assert(page.name == 'log test')
+ assert(page.out_file_path == 'test/log/l.md')
+ assert(page.template.name == 'log.md')
+
+def test_context_no_commits():
+ page = LogPage('test/log', 'log test', None, None, None)
+ context = page.context()
+ assert(context['title'] == 'log test: Log')
+ assert(context['commits'] == [])
+
+def test_context_no_branches_and_tags():
+ commit = MagicMock()
+ commit.summary = 'mock commit'
+ commit.hexsha = 1234;
+ commit.committed_datetime = 0
+ page = LogPage('test/log', 'log test', [commit], None, None)
+ context = page.context()
+ assert(context['title'] == 'log test: Log')
+ assert(context['commits'] == [{'committed_datetime': 0, 'refs': [], 'summary': 'mock commit'}])
+
+def test_context_matching_branch_no_tags():
+ commit = MagicMock()
+ commit.summary = 'mock commit'
+ commit.hexsha = 1234;
+ commit.committed_datetime = 0
+ branch = MagicMock()
+ branch.commit.hexsha = commit.hexsha
+ branch.name = 'mock branch'
+ page = LogPage('test/log', 'log test', [commit], [branch], None)
+ context = page.context()
+ assert(context['title'] == 'log test: Log')
+ assert(context['commits'] == [{'committed_datetime': 0, 'refs': ['mock branch'], 'summary': 'mock commit'}])
+
+def test_context_unmatching_branch_no_tags():
+ commit = MagicMock()
+ commit.summary = 'mock commit'
+ commit.hexsha = 1234;
+ commit.committed_datetime = 0
+ branch = MagicMock()
+ branch.commit.hexsha = 4321
+ branch.name = 'mock branch'
+ page = LogPage('test/log', 'log test', [commit], [branch], None)
+ context = page.context()
+ assert(context['title'] == 'log test: Log')
+ assert(context['commits'] == [{'committed_datetime': 0, 'refs': [], 'summary': 'mock commit'}])
+
+def test_context_no_branch_matching_tag():
+ commit = MagicMock()
+ commit.summary = 'mock commit'
+ commit.hexsha = 1234;
+ commit.committed_datetime = 0
+ tag = MagicMock()
+ tag.commit.hexsha = commit.hexsha
+ tag.name = 'mock tag'
+ page = LogPage('test/log', 'log test', [commit], None, [tag])
+ context = page.context()
+ assert(context['title'] == 'log test: Log')
+ assert(context['commits'] == [{'committed_datetime': 0, 'refs': ['mock tag'], 'summary': 'mock commit'}])
+
+def test_context_no_branch_no_matching_tag():
+ commit = MagicMock()
+ commit.summary = 'mock commit'
+ commit.hexsha = 1234;
+ commit.committed_datetime = 0
+ tag = MagicMock()
+ tag.commit.hexsha = 4321
+ tag.name = 'mock tag'
+ page = LogPage('test/log', 'log test', [commit], None, [tag])
+ context = page.context()
+ assert(context['title'] == 'log test: Log')
+ assert(context['commits'] == [{'committed_datetime': 0, 'refs': [], 'summary': 'mock commit'}])
+
+def test_context_no_matching_branch_no_matching_tag():
+ commit = MagicMock()
+ commit.summary = 'mock commit'
+ commit.hexsha = 1234;
+ commit.committed_datetime = 0
+ branch = MagicMock()
+ branch.commit.hexsha = 321
+ branch.name = 'mock branch'
+ tag = MagicMock()
+ tag.commit.hexsha = 4321
+ tag.name = 'mock tag'
+ page = LogPage('test/log', 'log test', [commit], [branch], [tag])
+ context = page.context()
+ assert(context['title'] == 'log test: Log')
+ assert(context['commits'] == [{'committed_datetime': 0, 'refs': [], 'summary': 'mock commit'}])
+
+def test_context_matching_branch_matching_tag():
+ commit = MagicMock()
+ commit.summary = 'mock commit'
+ commit.hexsha = 1234;
+ commit.committed_datetime = 0
+ branch = MagicMock()
+ branch.commit.hexsha = commit.hexsha
+ branch.name = 'mock branch'
+ tag = MagicMock()
+ tag.commit.hexsha = commit.hexsha
+ tag.name = 'mock tag'
+ page = LogPage('test/log', 'log test', [commit], [branch], [tag])
+ context = page.context()
+ assert(context['title'] == 'log test: Log')
+ assert(context['commits'] == [{'committed_datetime': 0, 'refs': ['mock branch', 'mock tag'], 'summary': 'mock commit'}])
+
+def test_multiple_commits():
+ commit1 = MagicMock()
+ commit1.summary = 'mock commit 1'
+ commit1.hexsha = 1;
+ commit1.committed_datetime = 0
+ commit2 = MagicMock()
+ commit2.summary = 'mock commit 2'
+ commit2.hexsha = 2;
+ commit2.committed_datetime = 1
+ page = LogPage('test/log', 'log test', [commit1, commit2], None, None)
+ context = page.context()
+ assert(context['title'] == 'log test: Log')
+ assert(context['commits'] == [
+ {'committed_datetime': 0, 'refs': [], 'summary': 'mock commit 1'},
+ {'committed_datetime': 1, 'refs': [], 'summary': 'mock commit 2'}
+ ])
+
+def test_multiple_commits_branch():
+ commit1 = MagicMock()
+ commit1.summary = 'mock commit 1'
+ commit1.hexsha = 1;
+ commit1.committed_datetime = 0
+ commit2 = MagicMock()
+ commit2.summary = 'mock commit 2'
+ commit2.hexsha = 2;
+ commit2.committed_datetime = 1
+ branch = MagicMock()
+ branch.commit.hexsha = 1
+ branch.name = 'mock branch'
+ page = LogPage('test/log', 'log test', [commit1, commit2], [branch], None)
+ context = page.context()
+ assert(context['title'] == 'log test: Log')
+ assert(context['commits'] == [
+ {'committed_datetime': 0, 'refs': ['mock branch'], 'summary': 'mock commit 1'},
+ {'committed_datetime': 1, 'refs': [], 'summary': 'mock commit 2'}
+ ])
+
+def test_multiple_commits_tag():
+ commit1 = MagicMock()
+ commit1.summary = 'mock commit 1'
+ commit1.hexsha = 1;
+ commit1.committed_datetime = 0
+ commit2 = MagicMock()
+ commit2.summary = 'mock commit 2'
+ commit2.hexsha = 2;
+ commit2.committed_datetime = 1
+ tag = MagicMock()
+ tag.commit.hexsha = 1
+ tag.name = 'mock tag'
+ page = LogPage('test/log', 'log test', [commit1, commit2], None, [tag])
+ context = page.context()
+ assert(context['title'] == 'log test: Log')
+ assert(context['commits'] == [
+ {'committed_datetime': 0, 'refs': ['mock tag'], 'summary': 'mock commit 1'},
+ {'committed_datetime': 1, 'refs': [], 'summary': 'mock commit 2'}
+ ])
+
+def test_multiple_commits_branch_and_tag():
+ commit1 = MagicMock()
+ commit1.summary = 'mock commit 1'
+ commit1.hexsha = 1;
+ commit1.committed_datetime = 0
+ commit2 = MagicMock()
+ commit2.summary = 'mock commit 2'
+ commit2.hexsha = 2;
+ commit2.committed_datetime = 1
+ branch = MagicMock()
+ branch.commit.hexsha = 1
+ branch.name = 'mock branch'
+ tag = MagicMock()
+ tag.commit.hexsha = 2
+ tag.name = 'mock tag'
+ page = LogPage('test/log', 'log test', [commit1, commit2], [branch], [tag])
+ context = page.context()
+ assert(context['title'] == 'log test: Log')
+ assert(context['commits'] == [
+ {'committed_datetime': 0, 'refs': ['mock branch'], 'summary': 'mock commit 1'},
+ {'committed_datetime': 1, 'refs': ['mock tag'], 'summary': 'mock commit 2'}
+ ])
+
diff --git a/tests/overview_test.py b/tests/overview_test.py
new file mode 100644
index 0000000..fa51858
--- /dev/null
+++ b/tests/overview_test.py
@@ -0,0 +1,8 @@
+from g2h.overview_page import OverviewPage
+
+def test_init():
+ page = OverviewPage('test/overview', 'overview test', 'test branch', 'test tag')
+ context = page.context()
+ assert(context['title'] == 'overview test')
+ assert(context['branches'] == 'test branch')
+ assert(context['tags'] == 'test tag')
diff --git a/tests/page_test.py b/tests/page_test.py
new file mode 100644
index 0000000..1008a8d
--- /dev/null
+++ b/tests/page_test.py
@@ -0,0 +1,19 @@
+from g2h.page import Page
+from jinja2.exceptions import TemplateNotFound
+import pytest
+
+def test_init():
+ page = Page('overview.md', 'dir', 'file', 'name')
+ assert(page.name == 'name')
+ assert(page.out_file_path == 'dir/file')
+ assert(page.template.name == 'overview.md')
+
+def test_wrong_template():
+ with pytest.raises(TemplateNotFound):
+ Page('not existant.md', 'dir', 'file', 'name')
+
+def test_no_context():
+ page = Page('overview.md', 'dir', 'file', 'name')
+ with pytest.raises(NotImplementedError):
+ page.context()
+