[Checkins] SVN: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/ add changes to test_zodb class to remove its method misuse and made metadata to work for a generic case

Charith Paranaliyanage paranaliyanage at gmail.com
Fri Jun 20 04:42:49 EDT 2008


Log message for revision 87588:
  add changes to test_zodb class to remove its method misuse and made metadata to work for a generic case

Changed:
  U   Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py
  U   Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_zope.py

-=-
Modified: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py	2008-06-20 08:17:34 UTC (rev 87587)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/database/metadata.py	2008-06-20 08:42:49 UTC (rev 87588)
@@ -1,3 +1,15 @@
+
+from zope.interface import implements
+from zope.component import adapts
+from zope.component.interface import searchInterfaceUtilities 
+from zope.component import getUtility
+from zope.component import getUtilitiesFor
+from zope.app.catalog.interfaces import ICatalog
+from zope.app.intid import IIntIds
+
+from ocql.interfaces import IDB
+from ocql.database.index import IAllIndex
+ 
 class MetaType:
     def get_property(self, name):
         """
@@ -21,8 +33,38 @@
         """Returns the size of the collection or class if known"""
 
 class Metadata:
+    implements(IDB)
+    adapts(None)
+    
+    db={}
+    classes = {}
+    
     def __init__(self):
-        pass
+        items = list(searchInterfaceUtilities(self))
+        catalogs = getUtilitiesFor(ICatalog)
+        intids = getUtility(IIntIds)
+        #import pydevd;pydevd.settrace()
+        for i in catalogs:
+            catalog = getUtility(ICatalog,name=i[0].__str__())
+            for index in catalog:
+                #is this the correct way to filter?
+                if index.split("_")[0] == 'all':
+                    results = catalog.apply({index:(1,1)})
+                    obj_list = []
+                    for result in results:
+                        obj = intids.getObject(result)
+                        obj_list.append(obj)
+                    self.db.__setitem__(index,obj_list)
+        
+        #seems the db is correct
+        print self.db
+        
+        #still this need to be corrected. I was unable to get index.interface property
+        for item in items:
+            class_name = item[0].rsplit('.',1)[1].__str__()
+            self.classes.__setitem__(class_name,class_name)
+        print self.classes
+           
 
     def get_class(self, classname):
         """Returns a MetaType instance for the class."""
\ No newline at end of file

Modified: Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_zope.py
===================================================================
--- Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_zope.py	2008-06-20 08:17:34 UTC (rev 87587)
+++ Sandbox/adamg/ocql/branches/dbprovider/src/ocql/tests/test_zope.py	2008-06-20 08:42:49 UTC (rev 87588)
@@ -1,24 +1,25 @@
 import unittest
 import doctest
-from zope.component.interface import searchInterfaceUtilities 
+
 from zope.interface import implements
 from zope.component import adapts, getUtility, provideAdapter
-from ocql.interfaces import IDB 
+from zope.interface import Interface
+
+from ocql.aoptimizer.aoptimizer import AlgebraOptimizer
+from ocql.compiler.compiler import AlgebraCompiler
 from ocql.database import metadata
-from zope.interface import Interface
-from zope.app.catalog.interfaces import ICatalog
+from ocql.database.metadata import Metadata
+from ocql.engine import OCQLEngine
+from ocql.interfaces import IDB
+from ocql.parser.queryparser import QueryParser, SymbolContainer 
+from ocql.qoptimizer.qoptimizer import QueryOptimizer
+from ocql.queryobject.queryobject import *
+from ocql.rewriter.rewriter import Rewriter
 from ocql.testing.utils import setupInterfaces, setupCatalog
-from zope.location import LocationProxy
-from zope.app.intid import IIntIds
-from ocql.parser.queryparser import QueryParser, SymbolContainer
 from ocql.tests.test_old import QueryNullParser
-from ocql.qoptimizer.qoptimizer import QueryOptimizer
-from ocql.rewriter.rewriter import Rewriter
-from ocql.aoptimizer.aoptimizer import AlgebraOptimizer
-from ocql.compiler.compiler import AlgebraCompiler
-from ocql.testing.gsocdatabase import GsocMetadata
 from ocql.testing.sample.student import Student
 
+
 db = {}
 
 classes = {}
@@ -31,44 +32,60 @@
         provideAdapter(Rewriter)
         provideAdapter(AlgebraOptimizer)
         provideAdapter(AlgebraCompiler)
+        provideAdapter(Metadata)
         
         setupInterfaces(self)
         setupCatalog(self)
-        #import pydevd;pydevd.settrace()
-        items = list(searchInterfaceUtilities(self))
-        catalog = getUtility(ICatalog,name='foo-catalog')
         
-        intids = getUtility(IIntIds)
-        #is there is a way to find all the indexes
-        results = catalog.apply({'student_name':('A','Z')})
+        self.engine = OCQLEngine()
         
-        student_list = []
-        for r in results:
-            obj = intids.getObject(r)
-            print obj.__class__.__name__          
-            student_list.append(obj)
+    #just copy following methods from test_old
+    def doone(self, query, qo, expected):
+        print "==============="
+        print "query:",query
 
-        db.__setitem__('student_name', student_list)
+        algebra_=qo.rewrite(algebra)
 
-        for item in items:
-            print item
-            class_name = item[0].rsplit('.',1)[1].__str__()
-            classes.__setitem__(class_name,class_name)
-           # print item[1].__class__
+        print "algebra:",algebra_
 
-        GsocMetadata()
-        provideAdapter(GsocMetadata)
+        code=algebra_.compile();
+        compile(code,'<string>','eval')
+        q = RunnableQuery(engine,algebra_,code)
+
+        print "code:",code
+        print "---------------"
+        print "got:     ", q.execute()
+        print "expected:", expected
+
+    def doit(self, query, qo, expected):
+        run = self.engine.compile(qo)
+        result = run.execute()
+
+        self.assertEqual(expected, result)
+
+       
+    def test_gsoc(self):
         
+        print "only a single query for testing"
+        metadata = Metadata()
+        symbols = SymbolContainer()
            
-    def test_gsoc(self):
-        print "loading..."
-        metadata = IDB(None)
-        symbols = SymbolContainer()
+        query = "[c in IStudent | c]"
+        qo = Query(
+                metadata, symbols,
+                set,
+                [
+                    In(
+                       metadata, symbols,
+                       Identifier(metadata,symbols,'c'),
+                       Identifier(metadata,symbols,'IStudent'))
+                ], Identifier(metadata,symbols,'c'))
         
+        #is not sure how to get s1, s2 and s3 here
+        self.doit(query, qo, set([s1,s2,s3]))
         
-    
-    
         
+        
 def test_suite():
     flags =  doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS
     return unittest.TestSuite((



More information about the Checkins mailing list