2006-04-17 00:06:29 +02:00
|
|
|
|
|
|
|
import unittest
|
|
|
|
import sys
|
2007-01-31 15:19:23 +01:00
|
|
|
sys.path.append('../../')
|
|
|
|
from fluents import annotations
|
2006-04-17 00:06:29 +02:00
|
|
|
|
2007-01-31 15:19:23 +01:00
|
|
|
class AnnotationsTest(unittest.TestCase):
|
2006-04-17 00:06:29 +02:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
pass
|
|
|
|
|
2006-04-17 01:30:01 +02:00
|
|
|
def testAddAnnotations(self):
|
2007-01-31 15:19:23 +01:00
|
|
|
h = annotations.DictAnnotationHandler()
|
|
|
|
annotations.set_dim_handler('go-terms', h)
|
|
|
|
assert annotations.get_dim_handler('go-terms') == h
|
|
|
|
assert annotations.get_dim_handler('foobar') == None
|
|
|
|
|
|
|
|
def testGetDimAnnotations(self):
|
|
|
|
h = annotations.DictAnnotationHandler()
|
|
|
|
annotations.set_dim_handler('go-terms', h)
|
|
|
|
d = {'GO:0': 'biological_process',
|
|
|
|
'GO:1': 'foo',
|
|
|
|
'GO:2': 'bar'}
|
|
|
|
h.add_annotations('name', d)
|
|
|
|
|
|
|
|
ann0 = annotations.get_dim_annotations('go-terms', 'name', [])
|
|
|
|
assert ann0 == []
|
|
|
|
|
|
|
|
ann1 = annotations.get_dim_annotations('go-terms', 'name', ['GO:0'])
|
|
|
|
assert len(ann1) == 1
|
|
|
|
assert ann1[0] == 'biological_process'
|
|
|
|
|
|
|
|
ann2 = annotations.get_dim_annotations('go-terms', 'name', ['GO:1', 'baz'])
|
|
|
|
assert len(ann2) == 2
|
|
|
|
assert ann2 == ['foo', None]
|
|
|
|
|
|
|
|
def testDictAnnotationHandler(self):
|
|
|
|
h = annotations.DictAnnotationHandler()
|
|
|
|
annotations.set_dim_handler('go-terms', h)
|
|
|
|
d = {'GO:0': 'biological_process',
|
|
|
|
'GO:1': 'foo',
|
|
|
|
'GO:2': 'bar'}
|
|
|
|
h.add_annotations('name', d)
|
|
|
|
|
|
|
|
ann0 = h.get_annotations('name', [])
|
|
|
|
assert ann0 == []
|
|
|
|
|
|
|
|
ann1 = h.get_annotations('name', ['unexisting'])
|
|
|
|
assert ann1 == [None]
|
|
|
|
|
|
|
|
ann2 = h.get_annotations('name', ['unexisting'], 42)
|
|
|
|
assert ann2 == [42]
|
|
|
|
|
|
|
|
assert h.get_annotation_names() == ['name']
|
2006-04-17 01:30:01 +02:00
|
|
|
|
2006-04-17 00:06:29 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|