From 26f23ce5f91745178291c241c2a5a827f02790c9 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Fri, 27 Mar 2015 16:29:51 +0100 Subject: [PATCH] test: Add conditional coverage measurement --- taskwiki/taskwiki.py | 15 +++++++++++++++ tests/base.py | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/taskwiki/taskwiki.py b/taskwiki/taskwiki.py index 65a6e9d..63bd845 100644 --- a/taskwiki/taskwiki.py +++ b/taskwiki/taskwiki.py @@ -3,6 +3,21 @@ import itertools import sys import vim # pylint: disable=F0401 +# Start measuring coverage if in testing +if vim.vars.get('taskwiki_measure_coverage'): + import os + import atexit + import coverage + coverage_path = os.path.expanduser('~/taskwiki-coverage/.coverage.{0}'.format(os.getpid())) + cov = coverage.coverage(data_file=coverage_path) + cov.start() + + def save_coverage(): + cov.stop() + cov.save() + + atexit.register(save_coverage) + from tasklib.task import TaskWarrior, Task # Insert the taskwiki on the python path diff --git a/tests/base.py b/tests/base.py index a675fcb..131eb7f 100644 --- a/tests/base.py +++ b/tests/base.py @@ -39,9 +39,10 @@ class IntegrationTest(object): def setup(self): self.generate_data() self.client = server.start_gvim() + self.command('let g:taskwiki_measure_coverage="yes"') + self.command('let g:taskwiki_data_location="{0}"'.format(self.dir)) self.add_plugin('taskwiki') self.add_plugin('vimwiki') - self.command('let g:taskwiki_data_location="{0}"'.format(self.dir)) self.client.edit(os.path.join(self.dir, 'testwiki.txt')) self.command('set filetype=vimwiki', silent=False) # TODO: fix these vimwiki loading errors