mirror of
https://github.com/tbabej/taskwiki.git
synced 2025-08-19 15:53:07 +02:00
tests: Rewrite tests to allow more declarative style
This commit is contained in:
parent
15bd93d8bd
commit
0a4d4f9be7
1 changed files with 40 additions and 20 deletions
|
@ -9,8 +9,8 @@ server = vimrunner.Server()
|
||||||
|
|
||||||
class IntegrationTest(object):
|
class IntegrationTest(object):
|
||||||
|
|
||||||
input = None
|
viminput = None
|
||||||
output = None
|
vimoutput = None
|
||||||
|
|
||||||
def add_plugin(self, name):
|
def add_plugin(self, name):
|
||||||
plugin_base = os.path.expanduser('~/.vim/bundle/')
|
plugin_base = os.path.expanduser('~/.vim/bundle/')
|
||||||
|
@ -110,15 +110,31 @@ class IntegrationTest(object):
|
||||||
self.check_sanity()
|
self.check_sanity()
|
||||||
|
|
||||||
# Then load the input
|
# Then load the input
|
||||||
if self.input:
|
if self.viminput:
|
||||||
self.write_buffer(input)
|
# Unindent the lines
|
||||||
|
lines = [l[4:] for l in self.viminput.strip('\n').splitlines()]
|
||||||
|
self.write_buffer(lines)
|
||||||
|
|
||||||
# Do the stuff
|
# Do the stuff
|
||||||
self.execute()
|
self.execute()
|
||||||
|
|
||||||
|
def fill_uuid(line):
|
||||||
|
# Tasks in testing can have only alphanumerical descriptions
|
||||||
|
match = re.match(r'\s*\* \[ \] (?P<desc>[a-zA-Z0-9 ]*)(?<!\s)', line)
|
||||||
|
if not match:
|
||||||
|
return line
|
||||||
|
|
||||||
|
# Find the task and fill in its uuid
|
||||||
|
tasks = self.tw.tasks.filter(description=match.group('desc'))
|
||||||
|
return line.format(uuid=tasks[0]['uuid']) if tasks else line
|
||||||
|
|
||||||
# Check expected output
|
# Check expected output
|
||||||
if self.output:
|
if self.vimoutput:
|
||||||
assert self.read_buffer() == self.output
|
lines = [fill_uuid(l[4:])
|
||||||
|
for l in self.vimoutput.strip('\n').splitlines()
|
||||||
|
if l[4:]]
|
||||||
|
assert self.read_buffer() == lines
|
||||||
|
|
||||||
|
|
||||||
class TestBurndown(IntegrationTest):
|
class TestBurndown(IntegrationTest):
|
||||||
|
|
||||||
|
@ -127,31 +143,35 @@ class TestBurndown(IntegrationTest):
|
||||||
assert self.command(":py print vim.current.buffer", silent=False).startswith("<buffer burndown.daily")
|
assert self.command(":py print vim.current.buffer", silent=False).startswith("<buffer burndown.daily")
|
||||||
assert "Daily Burndown" in self.read_buffer()[0]
|
assert "Daily Burndown" in self.read_buffer()[0]
|
||||||
|
|
||||||
|
|
||||||
class TestViewports(IntegrationTest):
|
class TestViewports(IntegrationTest):
|
||||||
|
|
||||||
|
viminput = """
|
||||||
|
=== Work tasks | +work ===
|
||||||
|
"""
|
||||||
|
|
||||||
|
vimoutput = """
|
||||||
|
=== Work tasks | +work ===
|
||||||
|
* [ ] tag work task 1 #{uuid}
|
||||||
|
"""
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
lines = ["=== Work tasks | +work ==="]
|
|
||||||
self.write_buffer(lines)
|
|
||||||
self.command("w", regex="written$", lines=1)
|
self.command("w", regex="written$", lines=1)
|
||||||
assert self.read_buffer() == [
|
|
||||||
"=== Work tasks | +work ===",
|
|
||||||
"* [ ] tag work task 1 #{0}".format(self.tasks[3]['uuid'])
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class TestSimpleTask(IntegrationTest):
|
class TestSimpleTask(IntegrationTest):
|
||||||
|
|
||||||
|
viminput = """
|
||||||
|
* [ ] This is a test task
|
||||||
|
"""
|
||||||
|
|
||||||
|
vimoutput = """
|
||||||
|
* [ ] This is a test task #{uuid}
|
||||||
|
"""
|
||||||
|
|
||||||
def execute(self):
|
def execute(self):
|
||||||
lines = ["* [ ] This is a test task"]
|
|
||||||
self.write_buffer(lines)
|
|
||||||
self.command("w", regex="written$", lines=1)
|
self.command("w", regex="written$", lines=1)
|
||||||
|
|
||||||
# Check that only one tasks with this description exists
|
# Check that only one tasks with this description exists
|
||||||
matching = self.tw.tasks.filter(description="This is a test task")
|
matching = self.tw.tasks.filter(description="This is a test task")
|
||||||
assert len(matching) == 1
|
assert len(matching) == 1
|
||||||
|
|
||||||
expected = [
|
|
||||||
"* [ ] This is a test task #{0}".format(matching[0]['uuid'])
|
|
||||||
]
|
|
||||||
|
|
||||||
assert expected == self.read_buffer()
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue