-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.py
executable file
·60 lines (42 loc) · 1.43 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
# vim: syntax=python tabstop=4 expandtab
# coding: utf-8
"""
Executes test cases for all workflows that contain a "test" directory.
"""
__author__ = "Johannes Köster (http://johanneskoester.bitbucket.org)"
__license__ = "MIT"
import nose
import sys, os
from nose.plugins import Plugin
from unittest import TestCase
from snakemake import snakemake
class TestSnakefiles(Plugin):
enabled=True
def configure(self, options, conf):
pass
def wantDirectory(self, path):
return True
def wantFile(self, path):
head, tail = os.path.split(path)
if tail == "Snakefile":
if os.path.exists(os.path.join(head, "test")):
return True
return False
def loadTestsFromFile(self, snakefile):
testdir = os.path.join(os.path.dirname(snakefile), "test")
yield WorkflowTest(snakefile, testdir)
class WorkflowTest(TestCase):
def __init__(self, snakefile, testdir):
self.snakefile = snakefile
self.testdir = testdir
self._testMethodName = os.path.basename(os.path.dirname(snakefile))
def run(self, result):
result.startTest(self)
if snakemake(self.snakefile, dryrun=True, workdir=self.testdir):
result.addSuccess(self)
else:
result.addFailure(self, "")
result.stopTest(self)
if __name__ == "__main__":
nose.main(addplugins=[TestSnakefiles()])