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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#!/usr/bin/env python
# test_dotur.py
from cogent.util.unit_test import TestCase, main
from cogent.parse.dotur import get_otu_lists, OtuListParser
__author__ = "Jeremy Widmann"
__copyright__ = "Copyright 2007-2012, The Cogent Project"
__credits__ = ["Jeremy Widmann"]
__license__ = "GPL"
__version__ = "1.5.3"
__maintainer__ = "Jeremy Widmann"
__email__ = "jeremy.widmann@colorado.edu"
__status__ = "Development"
class DoturParserTests(TestCase):
"""Tests for DoturParser.
"""
def setUp(self):
"""setup for DoturParserTests.
"""
self.otu_list_string = \
"""unique 3 a b c
0.00 3 a b c
0.59 2 a,c b
0.78 1 a,c,b
"""
self.otu_res_list = [
[0.0,3,[['a'],['b'],['c']]],\
[0.0,3,[['a'],['b'],['c']]],\
[float(0.59),2,[['a','c'],['b']]],\
[float(0.78),1,[['a','c','b']]],\
]
self.otu_lists_unparsed=[\
['a','b','c'],
['a','b','c'],
['a,c','b'],
['a,c,b']
]
self.otu_lists_parsed=[\
[['a'],['b'],['c']],
[['a'],['b'],['c']],
[['a','c'],['b']],
[['a','c','b']]
]
def test_get_otu_lists_no_data(self):
"""get_otu_lists should function as expected.
"""
self.assertEqual(get_otu_lists([]),[])
def test_get_otu_lists(self):
"""get_otu_lists should function as expected.
"""
for obs, exp in zip(self.otu_lists_unparsed,self.otu_lists_parsed):
self.assertEqual(get_otu_lists(obs),exp)
def test_otulistparser_no_data(self):
"""OtuListParser should return correct result given no data.
"""
res = OtuListParser([])
self.assertEqual(list(res),[])
def test_otulistparser_parser(self):
"""OtuListParser should return correct result given basic output.
"""
res = OtuListParser(self.otu_list_string.split('\n'))
self.assertEqual(res,self.otu_res_list)
if __name__ == '__main__':
main()
|