diff --git a/tests/base.py b/tests/base.py index 3e310ea..0c93b64 100644 --- a/tests/base.py +++ b/tests/base.py @@ -19,6 +19,7 @@ class IntegrationTest(object): viminput = None vimoutput = None tasks = [] + markup = None def add_plugin(self, name): plugin_base = os.path.expanduser('~/.vim/bundle/') @@ -71,6 +72,7 @@ class IntegrationTest(object): self.command('let g:taskwiki_taskrc_location="{0}"'.format(self.taskrc_path)) self.command("let g:vimwiki_list = [{'syntax': 'mediawiki', 'ext': '.txt','path': '%s'}]" % self.dir) self.command('let g:taskwiki_measure_coverage="yes"') + self.command('let g:taskwiki_markup_syntax="{0}"'.format(self.markup)) def setup(self): self.generate_data() @@ -198,6 +200,7 @@ class IntegrationTest(object): def test_execute(self): # First, run sanity checks success = False + self.markup = 'default' for i in range(5): if self.check_sanity(soft=True): @@ -229,6 +232,51 @@ class IntegrationTest(object): assert self.read_buffer() == lines +class MultiSyntaxIntegrationTest(IntegrationTest): + + + def test_execute(self, test_syntax): + + # Set markup syntax + markup, header_expand = test_syntax + self.markup = markup + + # First, run sanity checks + success = False + + for i in range(5): + if self.check_sanity(soft=True): + success = True + break + else: + self.teardown() + self.setup() + + if not success: + self.check_sanity(soft=False) + + # Then load the input + if self.viminput: + # Expand HEADER + self.viminput = header_expand(self.viminput) + # Unindent the lines + lines = [self.fill_uuid(l[4:]) + for l in self.viminput.strip('\n').splitlines()] + self.write_buffer(lines) + + # Do the stuff + self.execute() + + # Check expected output + if self.vimoutput: + self.vimoutput = header_expand(self.vimoutput) + lines = [ + self.fill_uuid(l[4:]) + for l in self.vimoutput.strip('\n').splitlines()[:-1] + ] + assert self.read_buffer() == lines + + class MultipleSourceTest(IntegrationTest): extra_tasks = [] @@ -347,6 +395,7 @@ class MockCache(object): self.vwtask = dict() self.task = dict() self.viewport = dict() + self.markup_syntax = 'default' def reset(self): self.warriors.clear() diff --git a/tests/test_preset.py b/tests/test_preset.py index 252a654..ccec011 100644 --- a/tests/test_preset.py +++ b/tests/test_preset.py @@ -1,16 +1,16 @@ -from tests.base import IntegrationTest +from tests.base import MultiSyntaxIntegrationTest from time import sleep -class TestPresetDefaults(IntegrationTest): +class TestPresetDefaults(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks || +work === + HEADER3(Work tasks || +work) * [ ] This is a test task """ vimoutput = """ - === Work tasks || +work === + HEADER3(Work tasks || +work) * [ ] This is a test task #{uuid} """ @@ -24,19 +24,19 @@ class TestPresetDefaults(IntegrationTest): assert task['tags'] == set(['work']) -class TestPresetHierarchy(IntegrationTest): +class TestPresetHierarchy(MultiSyntaxIntegrationTest): viminput = """ - == Work tasks || +work == - === Hard work tasks || +hard === - === Easy work tasks || +easy === + HEADER2(Work tasks || +work) + HEADER3(Hard work tasks || +hard) + HEADER3(Easy work tasks || +easy) * [ ] This is a test task """ vimoutput = """ - == Work tasks || +work == - === Hard work tasks || +hard === - === Easy work tasks || +easy === + HEADER2(Work tasks || +work) + HEADER3(Hard work tasks || +hard) + HEADER3(Easy work tasks || +easy) * [ ] This is a test task #{uuid} """ @@ -50,15 +50,15 @@ class TestPresetHierarchy(IntegrationTest): assert task['tags'] == set(['work', 'easy']) -class TestPresetSeparateDefaults(IntegrationTest): +class TestPresetSeparateDefaults(MultiSyntaxIntegrationTest): viminput = """ - = Work tasks || +work or +play || +work = + HEADER1(Work tasks || +work or +play || +work) * [ ] This is a test task """ vimoutput = """ - = Work tasks || +work or +play || +work = + HEADER1(Work tasks || +work or +play || +work) * [ ] This is a test task #{uuid} """ @@ -72,17 +72,17 @@ class TestPresetSeparateDefaults(IntegrationTest): assert task['tags'] == set(['work']) -class TestPresetNestedDefaults(IntegrationTest): +class TestPresetNestedDefaults(MultiSyntaxIntegrationTest): viminput = """ - == Work tasks || +work == - === Hard work || +hard === + HEADER2(Work tasks || +work) + HEADER3(Hard work || +hard) * [ ] This is a test task """ vimoutput = """ - == Work tasks || +work == - === Hard work || +hard === + HEADER2(Work tasks || +work) + HEADER3(Hard work || +hard) * [ ] This is a test task #{uuid} """ @@ -96,16 +96,16 @@ class TestPresetNestedDefaults(IntegrationTest): assert task['tags'] == set(['work', 'hard']) -class TestPresetViewport(IntegrationTest): +class TestPresetViewport(MultiSyntaxIntegrationTest): viminput = """ - == Work tasks || +work == - === Hard work | +hard === + HEADER2(Work tasks || +work) + HEADER3(Hard work | +hard) """ vimoutput = """ - == Work tasks || +work == - === Hard work | +hard === + HEADER2(Work tasks || +work) + HEADER3(Hard work | +hard) * [ ] tag hard work task #{uuid} """ @@ -120,17 +120,17 @@ class TestPresetViewport(IntegrationTest): self.command("w", regex="written$", lines=1) -class TestPresetIgnoreViewport(IntegrationTest): +class TestPresetIgnoreViewport(MultiSyntaxIntegrationTest): viminput = """ - == Work tasks | +work == - === Hard work || +hard === + HEADER2(Work tasks | +work) + HEADER3(Hard work || +hard) * [ ] This is a test task """ vimoutput = """ - == Work tasks | +work == - === Hard work || +hard === + HEADER2(Work tasks | +work) + HEADER3(Hard work || +hard) * [ ] This is a test task #{uuid} """ @@ -144,17 +144,17 @@ class TestPresetIgnoreViewport(IntegrationTest): assert task['tags'] == set(['hard']) -class TestPresetViewportDefaultsYesNo(IntegrationTest): +class TestPresetViewportDefaultsYesNo(MultiSyntaxIntegrationTest): viminput = """ - == Work tasks || project:Work or project:Play || project:Work == - === Hard work | +hard === + HEADER2(Work tasks || project:Work or project:Play || project:Work) + HEADER3(Hard work | +hard) * [ ] This is a test task """ vimoutput = """ - == Work tasks || project:Work or project:Play || project:Work == - === Hard work | +hard === + HEADER2(Work tasks || project:Work or project:Play || project:Work) + HEADER3(Hard work | +hard) * [ ] This is a test task #{uuid} """ @@ -169,17 +169,17 @@ class TestPresetViewportDefaultsYesNo(IntegrationTest): assert task['project'] == 'Work' -class TestPresetViewportDefaultsNoYes(IntegrationTest): +class TestPresetViewportDefaultsNoYes(MultiSyntaxIntegrationTest): viminput = """ - == Work tasks || project:Work == - === Hard work | +hard or +easy | +hard === + HEADER2(Work tasks || project:Work) + HEADER3(Hard work | +hard or +easy | +hard) * [ ] This is a test task """ vimoutput = """ - == Work tasks || project:Work == - === Hard work | +hard or +easy | +hard === + HEADER2(Work tasks || project:Work) + HEADER3(Hard work | +hard or +easy | +hard) * [ ] This is a test task #{uuid} """ @@ -194,17 +194,17 @@ class TestPresetViewportDefaultsNoYes(IntegrationTest): assert task['project'] == 'Work' -class TestPresetViewportDefaultsYesYes(IntegrationTest): +class TestPresetViewportDefaultsYesYes(MultiSyntaxIntegrationTest): viminput = """ - == Work tasks || project:Work or project:Play || project:Work == - === Hard work | +hard or +easy | +hard === + HEADER2(Work tasks || project:Work or project:Play || project:Work) + HEADER3(Hard work | +hard or +easy | +hard) * [ ] This is a test task """ vimoutput = """ - == Work tasks || project:Work or project:Play || project:Work == - === Hard work | +hard or +easy | +hard === + HEADER2(Work tasks || project:Work or project:Play || project:Work) + HEADER3(Hard work | +hard or +easy | +hard) * [ ] This is a test task #{uuid} """ @@ -219,17 +219,17 @@ class TestPresetViewportDefaultsYesYes(IntegrationTest): assert task['project'] == 'Work' -class TestPresetDefaultPreservesTags(IntegrationTest): +class TestPresetDefaultPreservesTags(MultiSyntaxIntegrationTest): viminput = """ - == Work tasks || +work == - === Work tasks | +hard === + HEADER2(Work tasks || +work) + HEADER3(Work tasks | +hard) * [ ] hard task """ vimoutput = """ - == Work tasks || +work == - === Work tasks | +hard === + HEADER2(Work tasks || +work) + HEADER3(Work tasks | +hard) * [ ] hard task #{uuid} """ diff --git a/tests/test_viewport.py b/tests/test_viewport.py index 9a3ac82..b6d7467 100644 --- a/tests/test_viewport.py +++ b/tests/test_viewport.py @@ -1,17 +1,17 @@ # -*- coding: utf-8 -*- from datetime import datetime -from tests.base import IntegrationTest +from tests.base import MultiSyntaxIntegrationTest from time import sleep -class TestViewportsTaskGeneration(IntegrationTest): +class TestViewportsTaskGeneration(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks | +work === + HEADER2(Work tasks | +work) """ vimoutput = """ - === Work tasks | +work === + HEADER2(Work tasks | +work) * [ ] tag work task #{uuid} """ @@ -23,14 +23,14 @@ class TestViewportsTaskGeneration(IntegrationTest): self.command("w", regex="written$", lines=1) -class TestViewportsTaskGenerationEmptyFilter(IntegrationTest): +class TestViewportsTaskGenerationEmptyFilter(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks | === + HEADER2(Work tasks |) """ vimoutput = """ - === Work tasks | === + HEADER2(Work tasks |) * [ ] some task #{uuid} """ @@ -42,15 +42,15 @@ class TestViewportsTaskGenerationEmptyFilter(IntegrationTest): self.command("w", regex="written$", lines=1) -class TestViewportsTaskRemoval(IntegrationTest): +class TestViewportsTaskRemoval(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks | -work === + HEADER2(Work tasks | -work) * [ ] tag work task #{uuid} """ vimoutput = """ - === Work tasks | -work === + HEADER2(Work tasks | -work) """ tasks = [ @@ -61,14 +61,14 @@ class TestViewportsTaskRemoval(IntegrationTest): self.command("w", regex="written$", lines=1) -class TestViewportsContextTaskGeneration(IntegrationTest): +class TestViewportsContextTaskGeneration(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks | @work === + HEADER2(Work tasks | @work) """ vimoutput = """ - === Work tasks | @work === + HEADER2(Work tasks | @work) * [ ] tag work task #{uuid} """ @@ -83,14 +83,14 @@ class TestViewportsContextTaskGeneration(IntegrationTest): self.command("w", regex="written$", lines=1) -class TestViewportsContextComplexFilterTaskGeneration(IntegrationTest): +class TestViewportsContextComplexFilterTaskGeneration(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks | @work or project:Home === + HEADER2(Work tasks | @work or project:Home) """ vimoutput = """ - === Work tasks | @work or project:Home === + HEADER2(Work tasks | @work or project:Home) * [ ] home project task #{uuid} * [ ] tag work task #{uuid} """ @@ -107,14 +107,14 @@ class TestViewportsContextComplexFilterTaskGeneration(IntegrationTest): self.command("w", regex="written$", lines=1) -class TestViewportsTwoContextTaskGeneration(IntegrationTest): +class TestViewportsTwoContextTaskGeneration(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks | @work or @home === + HEADER2(Work tasks | @work or @home) """ vimoutput = """ - === Work tasks | @work or @home === + HEADER2(Work tasks | @work or @home) * [ ] home project task #{uuid} * [ ] tag work task #{uuid} """ @@ -132,14 +132,14 @@ class TestViewportsTwoContextTaskGeneration(IntegrationTest): self.command("w", regex="written$", lines=1) -class TestViewportsContextInvalid(IntegrationTest): +class TestViewportsContextInvalid(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks | @doesnotexist === + HEADER2(Work tasks | @doesnotexist) """ vimoutput = """ - === Work tasks | @doesnotexist === + HEADER2(Work tasks | @doesnotexist) """ def execute(self): @@ -147,15 +147,15 @@ class TestViewportsContextInvalid(IntegrationTest): "could not be found.", lines=3) -class TestViewportDefaultsAssigment(IntegrationTest): +class TestViewportDefaultsAssigment(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks | +work === + HEADER2(Work tasks | +work) * [ ] tag work task """ vimoutput = """ - === Work tasks | +work === + HEADER2(Work tasks | +work) * [ ] tag work task #{uuid} """ @@ -169,15 +169,15 @@ class TestViewportDefaultsAssigment(IntegrationTest): assert task['tags'] == set(['work']) -class TestViewportDefaultsExplicit(IntegrationTest): +class TestViewportDefaultsExplicit(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks | project:Home +home | project:Chores === + HEADER2(Work tasks | project:Home +home | project:Chores) * [ ] home task """ vimoutput = """ - === Work tasks | project:Home +home | project:Chores === + HEADER2(Work tasks | project:Home +home | project:Chores) """ def execute(self): @@ -191,15 +191,15 @@ class TestViewportDefaultsExplicit(IntegrationTest): assert task['tags'] == set() -class TestViewportDefaultsExplicitEmpty(IntegrationTest): +class TestViewportDefaultsExplicitEmpty(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks | project:Home +home | project: === + HEADER2(Work tasks | project:Home +home | project:) * [ ] home task """ vimoutput = """ - === Work tasks | project:Home +home | project: === + HEADER2(Work tasks | project:Home +home | project:) """ def execute(self): @@ -213,21 +213,21 @@ class TestViewportDefaultsExplicitEmpty(IntegrationTest): assert task['tags'] == set() -class TestViewportDefaultsTerminatedByHeader(IntegrationTest): +class TestViewportDefaultsTerminatedByHeader(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks | +work === + HEADER2(Work tasks | +work) * [ ] tag work task - === Unrelated work tasks === + HEADER2(Unrelated work tasks) * [ ] not tagged work task """ vimoutput = """ - === Work tasks | +work === + HEADER2(Work tasks | +work) * [ ] tag work task #{uuid} - === Unrelated work tasks === + HEADER2(Unrelated work tasks) * [ ] not tagged work task #{uuid} """ @@ -246,10 +246,10 @@ class TestViewportDefaultsTerminatedByHeader(IntegrationTest): assert task['tags'] == set() -class TestViewportInspection(IntegrationTest): +class TestViewportInspection(MultiSyntaxIntegrationTest): viminput = """ - === Work tasks | +work === + HEADER2(Work tasks | +work) * [ ] tag work task #{uuid} """ @@ -279,13 +279,13 @@ class TestViewportInspection(IntegrationTest): assert self.py("print(vim.current.buffer)", regex="