# -*- coding: utf-8 -*- from datetime import datetime from tests.base import MultiSyntaxIntegrationTest from time import sleep class TestViewportsTaskGeneration(MultiSyntaxIntegrationTest): viminput = """ HEADER2(Work tasks | +work) """ vimoutput = """ HEADER2(Work tasks | +work) * [ ] tag work task #{uuid} """ tasks = [ dict(description="tag work task", tags=['work']), ] def execute(self): self.command("w", regex="written$", lines=1) class TestViewportsTaskGenerationEmptyFilter(MultiSyntaxIntegrationTest): viminput = """ HEADER2(Work tasks |) """ vimoutput = """ HEADER2(Work tasks |) * [ ] some task #{uuid} """ tasks = [ dict(description="some task"), ] def execute(self): self.command("w", regex="written$", lines=1) class TestViewportsTaskRemoval(MultiSyntaxIntegrationTest): viminput = """ HEADER2(Work tasks | -work) * [ ] tag work task #{uuid} """ vimoutput = """ HEADER2(Work tasks | -work) """ tasks = [ dict(description="tag work task", tags=['work']), ] def execute(self): self.command("w", regex="written$", lines=1) class TestViewportsContextTaskGeneration(MultiSyntaxIntegrationTest): viminput = """ HEADER2(Work tasks | @work) """ vimoutput = """ HEADER2(Work tasks | @work) * [ ] tag work task #{uuid} """ tasks = [ dict(description="tag work task", tags=['work']), ] def execute(self): with open(self.taskrc_path, 'a') as f: f.write('context.work=+work\n') self.command("w", regex="written$", lines=1) class TestViewportsContextComplexFilterTaskGeneration(MultiSyntaxIntegrationTest): viminput = """ HEADER2(Work tasks | @work or project:Home) """ vimoutput = """ HEADER2(Work tasks | @work or project:Home) * [ ] home project task #{uuid} * [ ] tag work task #{uuid} """ tasks = [ dict(description="tag work task", tags=['work']), dict(description="home project task", project='Home'), ] def execute(self): with open(self.taskrc_path, 'a') as f: f.write('context.work=+work\n') self.command("w", regex="written$", lines=1) class TestViewportsTwoContextTaskGeneration(MultiSyntaxIntegrationTest): viminput = """ HEADER2(Work tasks | @work or @home) """ vimoutput = """ HEADER2(Work tasks | @work or @home) * [ ] home project task #{uuid} * [ ] tag work task #{uuid} """ tasks = [ dict(description="tag work task", tags=['work']), dict(description="home project task", project='Home'), ] def execute(self): with open(self.taskrc_path, 'a') as f: f.write('context.work=+work\n') f.write('context.home=project:Home\n') self.command("w", regex="written$", lines=1) class TestViewportsContextInvalid(MultiSyntaxIntegrationTest): viminput = """ HEADER2(Work tasks | @doesnotexist) """ vimoutput = """ HEADER2(Work tasks | @doesnotexist) """ def execute(self): self.command("w", regex="Context definition for 'doesnotexist' " "could not be found.", lines=3) class TestViewportDefaultsAssigment(MultiSyntaxIntegrationTest): viminput = """ HEADER2(Work tasks | +work) * [ ] tag work task """ vimoutput = """ HEADER2(Work tasks | +work) * [ ] tag work task #{uuid} """ def execute(self): self.command("w", regex="written$", lines=1) assert len(self.tw.tasks.pending()) == 1 task = self.tw.tasks.pending()[0] assert task['description'] == 'tag work task' assert task['status'] == 'pending' assert task['tags'] == set(['work']) class TestViewportDefaultsExplicit(MultiSyntaxIntegrationTest): viminput = """ HEADER2(Work tasks | project:Home +home | project:Chores) * [ ] home task """ vimoutput = """ HEADER2(Work tasks | project:Home +home | project:Chores) """ def execute(self): self.command("w", regex="written$", lines=1) assert len(self.tw.tasks.pending()) == 1 task = self.tw.tasks.pending()[0] assert task['description'] == 'home task' assert task['status'] == 'pending' assert task['project'] == 'Chores' assert task['tags'] == set() class TestViewportDefaultsExplicitEmpty(MultiSyntaxIntegrationTest): viminput = """ HEADER2(Work tasks | project:Home +home | project:) * [ ] home task """ vimoutput = """ HEADER2(Work tasks | project:Home +home | project:) """ def execute(self): self.command("w", regex="written$", lines=1) assert len(self.tw.tasks.pending()) == 1 task = self.tw.tasks.pending()[0] assert task['description'] == 'home task' assert task['status'] == 'pending' assert task['project'] == None assert task['tags'] == set() class TestViewportDefaultsTerminatedByHeader(MultiSyntaxIntegrationTest): viminput = """ HEADER2(Work tasks | +work) * [ ] tag work task HEADER2(Unrelated work tasks) * [ ] not tagged work task """ vimoutput = """ HEADER2(Work tasks | +work) * [ ] tag work task #{uuid} HEADER2(Unrelated work tasks) * [ ] not tagged work task #{uuid} """ def execute(self): self.command("w", regex="written$", lines=1) assert len(self.tw.tasks.pending()) == 2 task = self.tw.tasks.filter('+work')[0] assert task['description'] == 'tag work task' assert task['status'] == 'pending' assert task['tags'] == set(['work']) task = self.tw.tasks.filter('-work')[0] assert task['description'] == 'not tagged work task' assert task['status'] == 'pending' assert task['tags'] == set() class TestViewportInspection(MultiSyntaxIntegrationTest): viminput = """ HEADER2(Work tasks | +work) * [ ] tag work task #{uuid} """ vimoutput = """ ViewPort inspection: -------------------- Name: Work tasks Filter used: -DELETED -PARENT ( +work ) Defaults used: tags:['work'] Ordering used: status+,end+,due+,pri-,project+ Matching taskwarrior tasks: 1 Displayed tasks: 1 Tasks to be added: Tasks to be deleted: """ tasks = [ dict(description="tag work task", tags=['work']), ] def execute(self): self.command("w", regex="written$", lines=1) self.client.feedkeys('1gg') self.client.feedkeys(r'\') sleep(0.5) assert self.py("print(vim.current.buffer)", regex="') sleep(0.5) assert self.py("print(vim.current.buffer)", regex="