allpy
changeset 863:ddf85d0a8924
'make tests' now also searches for doctests and runs them.
- Added --with-doctest flag to nosetests.
- Fixed usecase examples so they don't break from nose searching for doctests
- Fixed test_usecase, so it works with the current usecases
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Thu, 21 Jul 2011 18:34:27 +0400 |
parents | 927085d03977 |
children | cfcbd13f6761 |
files | Makefile test/test_usecases.py test/usecase1.py test/usecase2.py test/usecase3.py |
diffstat | 5 files changed, 43 insertions(+), 25 deletions(-) [+] |
line diff
1.1 --- a/Makefile Thu Jul 21 18:29:42 2011 +0400 1.2 +++ b/Makefile Thu Jul 21 18:34:27 2011 +0400 1.3 @@ -1,7 +1,8 @@ 1.4 all: tests doc codes blocks3d-wt blocks3d-www pair-cores-www 1.5 1.6 tests: 1.7 - PYTHONPATH=$(PWD) nosetests --with-coverage 1.8 + PYTHONPATH=$(PWD) nosetests --with-doctest \ 1.9 + --with-coverage --cover-package=allpy 1.10 1.11 doc: 1.12 sphinx-autopackage --suffix=rst --dest-dir=docs/source/allpy/ allpy
2.1 --- a/test/test_usecases.py Thu Jul 21 18:29:42 2011 +0400 2.2 +++ b/test/test_usecases.py Thu Jul 21 18:34:27 2011 +0400 2.3 @@ -1,16 +1,19 @@ 2.4 -def capture_stdout(module_name, stdin=None): 2.5 +import os 2.6 +from subprocess import Popen, PIPE 2.7 + 2.8 +def capture_stdout(module_name, stdin=None, argv=()): 2.9 """Helper: import module by name, return it's stdout ouput as string.""" 2.10 - import sys 2.11 - from StringIO import StringIO 2.12 - stdout_bak = sys.stdout 2.13 - sys.stdout = result = StringIO() 2.14 - sys.stdout.name = 'stdout' 2.15 - if stdin is not None: 2.16 - sys.stdin = StringIO(stdin) 2.17 - sys.stdin.name = 'stdin' 2.18 - __import__(module_name) 2.19 - sys.stdout = stdout_bak 2.20 - return result.getvalue() 2.21 + file = os.path.join(os.path.dirname(__file__), module_name + '.py') 2.22 + command = [file] + list(argv) 2.23 + print command, stdin 2.24 + if stdin: 2.25 + p = Popen(command, stdin=PIPE, stdout=PIPE) 2.26 + p.stdin.write(str(stdin)) 2.27 + p.stdin.close() 2.28 + else: 2.29 + p = Popen(command, stdout=PIPE) 2.30 + assert p.wait() == 0 2.31 + return p.stdout.read() 2.32 2.33 def test_usecase1(): 2.34 """Run usecase1, assert it produced the expected results.""" 2.35 @@ -56,7 +59,7 @@ 2.36 'AATI---KPD-VK--D--SKEYFKN----------------------------\n' 2.37 '' 2.38 ) 2.39 - output = capture_stdout("usecase3", input) 2.40 + output = capture_stdout("usecase3", input, ['0:5,7:12', '-', '-']) 2.41 assert output == expect, "Usecase1:\nexpect\t%r\noutput\t%r" % (expect, output) 2.42 2.43 # vim: set et ts=4 sts=4 sw=4:
3.1 --- a/test/usecase1.py Thu Jul 21 18:29:42 2011 +0400 3.2 +++ b/test/usecase1.py Thu Jul 21 18:34:27 2011 +0400 3.3 @@ -1,3 +1,4 @@ 3.4 +#!/usr/bin/python 3.5 import sys 3.6 from allpy import protein 3.7 from allpy import processors
4.1 --- a/test/usecase2.py Thu Jul 21 18:29:42 2011 +0400 4.2 +++ b/test/usecase2.py Thu Jul 21 18:34:27 2011 +0400 4.3 @@ -1,11 +1,16 @@ 4.4 +#!/usr/bin/python 4.5 import sys 4.6 +from collections import deque 4.7 from allpy import dna 4.8 from allpy.processors import Needle, Left 4.9 from allpy.fileio import FastaFile 4.10 -from collections import deque 4.11 +from allpy.util import open 4.12 4.13 width = 15 4.14 threshold = 10 4.15 +if __name__ == "__main__": 4.16 + infile = open(sys.argv[1]) 4.17 + outfile = open(sys.argv[2]) 4.18 4.19 def has_identity(column): 4.20 as_list = column.values() 4.21 @@ -38,7 +43,7 @@ 4.22 return "".join(column.in_block for column in alignment.columns) 4.23 4.24 def main(): 4.25 - alignment = dna.Alignment().append_file(sys.stdin) 4.26 + alignment = dna.Alignment().append_file(infile) 4.27 assert len(alignment.sequences) == 2, "Input must have TWO sequences!" 4.28 alignment.realign(Left()) 4.29 alignment.realign(Needle()) 4.30 @@ -47,8 +52,8 @@ 4.31 for n, block in enumerate(blocks, 1): 4.32 block.to_file(open("block_%02d.fasta" % n, "w")) 4.33 4.34 - alignment.to_file(sys.stdout) 4.35 - FastaFile(sys.stdout).write_string( 4.36 + alignment.to_file(outfile) 4.37 + FastaFile(outfile).write_string( 4.38 blocks_markup(alignment, blocks), 4.39 "markup", 4.40 "In run with window %s and threshold %s" % (width, threshold)
5.1 --- a/test/usecase3.py Thu Jul 21 18:29:42 2011 +0400 5.2 +++ b/test/usecase3.py Thu Jul 21 18:34:27 2011 +0400 5.3 @@ -1,14 +1,22 @@ 5.4 +#!/usr/bin/python 5.5 from allpy import protein 5.6 from allpy.processors import Left 5.7 +from allpy.util import open 5.8 import sys 5.9 5.10 -ranges = [(0,5), (7,12)] 5.11 +if __name__ == "__main__": 5.12 + ranges = sys.argv[1] 5.13 + infile = open(sys.argv[2]) 5.14 + outfile = open(sys.argv[3]) 5.15 5.16 -alignment = protein.Alignment().append_file(sys.stdin) 5.17 -for begin, end in ranges: 5.18 - columns = alignment.columns[begin:end] 5.19 - protein.Block.from_alignment(alignment, columns=columns).realign(Left()) 5.20 -alignment.remove_gap_columns() 5.21 -alignment.to_file(sys.stdout) 5.22 + # This accepts ranges in form "0:5,7:12,1:-1" 5.23 + ranges = [map(int, range.split(':')) for range in ranges.split(',')] 5.24 + 5.25 + alignment = protein.Alignment().append_file(sys.stdin) 5.26 + for begin, end in ranges: 5.27 + columns = alignment.columns[begin:end] 5.28 + protein.Block.from_alignment(alignment, columns=columns).realign(Left()) 5.29 + alignment.remove_gap_columns() 5.30 + alignment.to_file(sys.stdout) 5.31 5.32 # vim: set et ts=4 sts=4 sw=4: