Added annotations to identifiers, and converted the unused annotationtest.py to

test the new module.
This commit is contained in:
2007-01-31 14:19:23 +00:00
parent 1863bfc564
commit 74cb30428c
2 changed files with 104 additions and 19 deletions

View File

@@ -1,32 +1,57 @@
import unittest
import sys
sys.path.append('../../system')
from annotations import *
from sets import Set as set
sys.path.append('../../')
from fluents import annotations
class AnnotationTest(unittest.TestCase):
class AnnotationsTest(unittest.TestCase):
def setUp(self):
pass
def testCreation(self):
a = Annotations('x', 'y')
assert a.has_dimension('x')
assert a.has_dimension('y')
assert not a.has_dimension('z')
def testAddAnnotations(self):
ann = Annotations('genes', 'go')
go = set(['GO:0', 'GO:1'])
ann.add_annotations('genes', 'BadGene', 'go', go)
genes = set(['BadGene'])
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
assert ann.get_annotations('genes', 'BadGene', 'go') == go
assert ann.get_annotations('go', 'GO:0', 'genes') == genes
assert ann.get_annotations('go', 'GO:1', 'genes') == genes
assert ann.get_annotations('go', 'GO:2', 'genes') == set()
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']
if __name__ == '__main__':
unittest.main()