from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from waldo.go.models import Term
import waldo.go.load
import waldo.go.go

def test_is_cellular_component():
    engine = create_engine('sqlite://')
    metadata = waldo.go.models.Base.metadata
    metadata.bind = engine
    metadata.create_all()
    sessionmaker_ = sessionmaker(engine)

    nr_entries = waldo.go.load.load('tests/data/', sessionmaker_)
    expected = 976 - 79 # instances of "[Term]" - instances of is_obsolete
    assert nr_entries == expected

    session = sessionmaker_ ()
    assert session.query( waldo.go.models.Term).count() == nr_entries

    assert waldo.go.go.is_cellular_component('GO:0000015')
    assert waldo.go.go.is_cellular_component('GO:0000108')
    assert not waldo.go.go.is_cellular_component('GO:0000107')

    assert waldo.go.go.is_cellular_component('GO:0000015')
    assert waldo.go.go.is_cellular_component('GO:0000108')
    assert not waldo.go.go.is_cellular_component('GO:0000107')

def test_id_to_term():
    engine = create_engine('sqlite://')
    metadata = waldo.go.models.Base.metadata
    metadata.bind = engine
    metadata.create_all()
    sessionmaker_ = sessionmaker(engine)
    
    waldo.go.load.load('tests/data/', sessionmaker_)
    session = sessionmaker_()

    id = 'GO:0000015'
    term = 'phosphopyruvate hydratase complex'
    result = waldo.go.go.id_to_term(id)
    assert result is not None
    assert result == term

    id = 'GO:00099999skl'
    term = 'repairosome'
    result = waldo.go.go.id_to_term(id) 
    assert result == id

@@ -356,16 +356,47 @@
 (engine)
+%0A    session = sessionmaker_ ()
 %0A%0A    nr
@@ -569,39 +569,8 @@
 ed%0A%0A
-    session = sessionmaker_ ()%0A
     
@@ -590,17 +590,16 @@
 n.query(
- 
 waldo.go
@@ -1003,297 +1003,9 @@
 ')%0A%0A
-def test_id_to_term():%0A    engine = create_engine('sqlite://')%0A    metadata = waldo.go.models.Base.metadata%0A    metadata.bind = engine%0A    metadata.create_all()%0A    sessionmaker_ = sessionmaker(engine)%0A    %0A    waldo.go.load.load('tests/data/', sessionmaker_)%0A    session = sessionmaker_()
+%0A
 %0A%0A  
@@ -1109,16 +1109,25 @@
 _term(id
+, session
 )%0A    as
@@ -1266,18 +1266,26 @@
 _term(id
+, session
 )
- 
 %0A    ass
@@ -1301,8 +1301,9 @@
 t == id%0A
+%0A

Make GO test be all in memory