| 1 |
import datetime |
|---|
| 2 |
import getpass |
|---|
| 3 |
import new |
|---|
| 4 |
import os |
|---|
| 5 |
localDir = os.path.join(os.getcwd(), os.path.dirname(__file__)) |
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
def run(storename, olap=False, mediated=False): |
|---|
| 9 |
storefunc = globals()[storename] |
|---|
| 10 |
if olap: |
|---|
| 11 |
import clinic_fixture |
|---|
| 12 |
reload(clinic_fixture) |
|---|
| 13 |
print "OLAP Tests for %r" % storename |
|---|
| 14 |
storefunc(clinic_fixture, mediated) |
|---|
| 15 |
else: |
|---|
| 16 |
import zoo_fixture |
|---|
| 17 |
reload(zoo_fixture) |
|---|
| 18 |
print "OLTP Tests for %r" % storename |
|---|
| 19 |
storefunc(zoo_fixture, mediated) |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
logname = os.path.join(localDir, "djvtest.log") |
|---|
| 23 |
|
|---|
| 24 |
def _djvlog(self, message): |
|---|
| 25 |
"""Dejavu logger (writes to error.log).""" |
|---|
| 26 |
if isinstance(message, unicode): |
|---|
| 27 |
message = message.encode('utf8') |
|---|
| 28 |
sm = self.__class__.__name__.replace("StorageManager", "") |
|---|
| 29 |
s = "%s %s %s" % (datetime.datetime.now().isoformat(), sm, message) |
|---|
| 30 |
f = open(logname, 'ab') |
|---|
| 31 |
f.write(s + '\n') |
|---|
| 32 |
f.close() |
|---|
| 33 |
|
|---|
| 34 |
def hook_into_log(sm): |
|---|
| 35 |
sm.log = new.instancemethod(_djvlog, sm, sm.__class__) |
|---|
| 36 |
|
|---|
| 37 |
import dejavu |
|---|
| 38 |
sm.logflags = (dejavu.logflags.ERROR + dejavu.logflags.IO + |
|---|
| 39 |
dejavu.logflags.SQL + dejavu.logflags.STORE) |
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
def get_store(sm, opts): |
|---|
| 43 |
|
|---|
| 44 |
opts['Prefix'] = 'test' |
|---|
| 45 |
|
|---|
| 46 |
from dejavu import storage |
|---|
| 47 |
root = storage.resolve(sm, opts) |
|---|
| 48 |
hook_into_log(root) |
|---|
| 49 |
|
|---|
| 50 |
v = getattr(root, "version", None) |
|---|
| 51 |
if v: |
|---|
| 52 |
print v() |
|---|
| 53 |
|
|---|
| 54 |
return root |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
def caching(fixture, mediated): |
|---|
| 61 |
from dejavu import storage |
|---|
| 62 |
nextstore = storage.resolve('shelve', {u'Path': localDir}) |
|---|
| 63 |
hook_into_log(nextstore) |
|---|
| 64 |
sm = get_store("cache", {'Next Store': nextstore}) |
|---|
| 65 |
hook_into_log(sm.cache) |
|---|
| 66 |
fixture.run(sm, mediated) |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
def aged(fixture, mediated): |
|---|
| 70 |
from dejavu import storage |
|---|
| 71 |
nextstore = storage.resolve('shelve', {u'Path': localDir}) |
|---|
| 72 |
hook_into_log(nextstore) |
|---|
| 73 |
|
|---|
| 74 |
opts = {'Lifetime': '10 minutes', |
|---|
| 75 |
'Next Store': nextstore, |
|---|
| 76 |
} |
|---|
| 77 |
sm = get_store("aged", opts) |
|---|
| 78 |
hook_into_log(sm.cache) |
|---|
| 79 |
fixture.run(sm, mediated) |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
def burned(fixture, mediated): |
|---|
| 83 |
from dejavu import storage |
|---|
| 84 |
nextstore = storage.resolve('shelve', {u'Path': localDir}) |
|---|
| 85 |
hook_into_log(nextstore) |
|---|
| 86 |
sm = get_store("burned", {'Next Store': nextstore}) |
|---|
| 87 |
hook_into_log(sm.cache) |
|---|
| 88 |
fixture.run(sm, mediated) |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
def firebird(fixture, mediated): |
|---|
| 92 |
try: |
|---|
| 93 |
import kinterbasdb |
|---|
| 94 |
except ImportError: |
|---|
| 95 |
print ("The kinterbasdb module could not be imported. " |
|---|
| 96 |
"The Firebird test will not be run.") |
|---|
| 97 |
return |
|---|
| 98 |
|
|---|
| 99 |
user = "sysdba" |
|---|
| 100 |
passwd = getpass.getpass("Enter the password for the Firebird '%s' user: " % user) |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
opts = {'host': "localhost", |
|---|
| 106 |
'name': os.path.join(localDir, "testdb", r"test.fdb"), |
|---|
| 107 |
'user': user, |
|---|
| 108 |
'password': passwd, |
|---|
| 109 |
} |
|---|
| 110 |
fixture.run(get_store("firebird", opts), mediated) |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
def fs(fixture, mediated): |
|---|
| 114 |
opts = {'root': os.path.join(localDir, "testdb", "fsroot"), |
|---|
| 115 |
'Exhibit.Name': '.mp3', |
|---|
| 116 |
} |
|---|
| 117 |
fixture.run(get_store("folders", opts), mediated) |
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
def json(fixture, mediated): |
|---|
| 121 |
opts = {'root': os.path.join(localDir, "testdb", "jsonroot"), |
|---|
| 122 |
} |
|---|
| 123 |
fixture.run(get_store("json", opts), mediated) |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
def memcached(fixture, mediated): |
|---|
| 127 |
opts = {'memcached.servers': ['127.0.0.1:11211'], |
|---|
| 128 |
'memcached.global_index': True, |
|---|
| 129 |
'name': 'djvtest', |
|---|
| 130 |
} |
|---|
| 131 |
fixture.run(get_store("memcached", opts), mediated) |
|---|
| 132 |
|
|---|
| 133 |
def memcached2(fixture, mediated): |
|---|
| 134 |
opts = {'memcached.servers': ['127.0.0.1:11211'], |
|---|
| 135 |
'memcached.global_index': False, |
|---|
| 136 |
'name': 'djvtest', |
|---|
| 137 |
} |
|---|
| 138 |
mc = get_store("memcached", opts) |
|---|
| 139 |
|
|---|
| 140 |
nextstore = get_store('shelve', {u'Path': localDir}) |
|---|
| 141 |
|
|---|
| 142 |
sm = get_store("cache", {'Next Store': nextstore, 'cache': mc}) |
|---|
| 143 |
fixture.run(sm, mediated) |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
def msaccess(fixture, mediated): |
|---|
| 147 |
try: |
|---|
| 148 |
import pythoncom |
|---|
| 149 |
except ImportError: |
|---|
| 150 |
print ("The pythoncom module could not be imported. " |
|---|
| 151 |
"The MSAccess test will not be run.") |
|---|
| 152 |
return |
|---|
| 153 |
|
|---|
| 154 |
from geniusql.providers import ado |
|---|
| 155 |
try: |
|---|
| 156 |
ado.gen_py() |
|---|
| 157 |
except ImportError: |
|---|
| 158 |
print ("ADO 2.7 support could not be verified. " |
|---|
| 159 |
"The MSAccess test will not be run.") |
|---|
| 160 |
return |
|---|
| 161 |
|
|---|
| 162 |
opts = {'connections.Connect': |
|---|
| 163 |
"PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=%s;" % |
|---|
| 164 |
os.path.join(localDir, "zoo.mdb"), |
|---|
| 165 |
} |
|---|
| 166 |
fixture.run(get_store("access", opts), mediated) |
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
def mysql(fixture, mediated): |
|---|
| 170 |
try: |
|---|
| 171 |
import _mysql |
|---|
| 172 |
except ImportError: |
|---|
| 173 |
print("The _mysql module could not be imported. " |
|---|
| 174 |
"The test for MySQL will not be run.") |
|---|
| 175 |
return |
|---|
| 176 |
|
|---|
| 177 |
opts = {"host": "localhost", |
|---|
| 178 |
"db": "dejavu_test", |
|---|
| 179 |
"user": "root", |
|---|
| 180 |
} |
|---|
| 181 |
opts['passwd'] = getpass.getpass("Enter the password for the MySQL '%s' user:" |
|---|
| 182 |
% opts['user']) |
|---|
| 183 |
|
|---|
| 184 |
for encoding in ['latin1', 'utf8']: |
|---|
| 185 |
reload(fixture) |
|---|
| 186 |
opts['encoding'] = encoding |
|---|
| 187 |
print "\nTesting the %r encoding" % encoding |
|---|
| 188 |
fixture.run(get_store("mysql", opts), mediated) |
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
def proxy(fixture, mediated): |
|---|
| 192 |
from dejavu import storage |
|---|
| 193 |
nextstore = storage.resolve('shelve', {u'Path': localDir}) |
|---|
| 194 |
hook_into_log(nextstore) |
|---|
| 195 |
|
|---|
| 196 |
opts = {'Lifetime': '10 minutes', |
|---|
| 197 |
'Next Store': nextstore, |
|---|
| 198 |
} |
|---|
| 199 |
fixture.run(get_store("proxy", opts), mediated) |
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
def psycopg(fixture, mediated): |
|---|
| 203 |
try: |
|---|
| 204 |
try: |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
import _psycopg |
|---|
| 208 |
except ImportError: |
|---|
| 209 |
from psycopg2 import _psycopg |
|---|
| 210 |
except ImportError: |
|---|
| 211 |
print("The psycopg2._psycopg module could not be imported. " |
|---|
| 212 |
"The psycopg test will not be run.") |
|---|
| 213 |
return |
|---|
| 214 |
|
|---|
| 215 |
user = "postgres" |
|---|
| 216 |
passwd = getpass.getpass("Enter the password for the PostgreSQL '%s' user:" % user) |
|---|
| 217 |
|
|---|
| 218 |
opts = {'connections.Connect': |
|---|
| 219 |
("host=localhost dbname=dejavu_test user=%s password=%s" |
|---|
| 220 |
% (user, passwd)), |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
for encoding in ['SQL_ASCII', 'UNICODE']: |
|---|
| 224 |
reload(fixture) |
|---|
| 225 |
opts['encoding'] = encoding |
|---|
| 226 |
print "\nTesting the %r encoding" % encoding |
|---|
| 227 |
fixture.run(get_store("psycopg", opts), mediated) |
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
def pypgsql(fixture, mediated): |
|---|
| 231 |
try: |
|---|
| 232 |
from pyPgSQL import libpq |
|---|
| 233 |
except ImportError: |
|---|
| 234 |
print("The pyPgSQL.libpq module could not be imported. " |
|---|
| 235 |
"The pyPgSQL test will not be run.") |
|---|
| 236 |
return |
|---|
| 237 |
|
|---|
| 238 |
user = "postgres" |
|---|
| 239 |
passwd = getpass.getpass("Enter the password for the PostgreSQL '%s' user:" % user) |
|---|
| 240 |
opts = {'connections.Connect': |
|---|
| 241 |
("host=localhost dbname=dejavu_test user=%s password=%s" |
|---|
| 242 |
% (user, passwd)), |
|---|
| 243 |
} |
|---|
| 244 |
|
|---|
| 245 |
for encoding in ['SQL_ASCII', 'UNICODE']: |
|---|
| 246 |
reload(fixture) |
|---|
| 247 |
opts['encoding'] = encoding |
|---|
| 248 |
print "\nTesting the %r encoding" % encoding |
|---|
| 249 |
fixture.run(get_store("postgres", opts), mediated) |
|---|
| 250 |
|
|---|
| 251 |
|
|---|
| 252 |
def ram(fixture, mediated): |
|---|
| 253 |
fixture.run(get_store("ram", {}), mediated) |
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
def shelve(fixture, mediated): |
|---|
| 257 |
"""Test the shelve Storage Manager for dejavu. |
|---|
| 258 |
|
|---|
| 259 |
Notice that, since StorageManagerShelve doesn't decompile any Expressions, |
|---|
| 260 |
this will also test all native dejavu logic functions and any other aspects |
|---|
| 261 |
of Expression(unit). |
|---|
| 262 |
""" |
|---|
| 263 |
opts = {u'Path': os.path.join(localDir, "testdb")} |
|---|
| 264 |
fixture.run(get_store("shelve", opts), mediated) |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
def sqlite(fixture, mediated): |
|---|
| 268 |
_sqlite = None |
|---|
| 269 |
try: |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
import _sqlite3 as _sqlite |
|---|
| 273 |
except ImportError: |
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
try: |
|---|
| 278 |
|
|---|
| 279 |
import _sqlite |
|---|
| 280 |
except ImportError: |
|---|
| 281 |
|
|---|
| 282 |
try: |
|---|
| 283 |
from pysqlite2 import _sqlite |
|---|
| 284 |
except ImportError: |
|---|
| 285 |
print("The _sqlite module could not be imported. " |
|---|
| 286 |
"The SQLite test will not be run.") |
|---|
| 287 |
return |
|---|
| 288 |
|
|---|
| 289 |
print "\nTesting :memory: database" |
|---|
| 290 |
fixture.run(get_store("sqlite", {'Database': ':memory:'}), mediated) |
|---|
| 291 |
|
|---|
| 292 |
print "\nTesting file database" |
|---|
| 293 |
reload(fixture) |
|---|
| 294 |
opts = {"Database": os.path.join(localDir, "testdb", "sqlite_zoo_test")} |
|---|
| 295 |
fixture.run(get_store("sqlite", opts), mediated) |
|---|
| 296 |
|
|---|
| 297 |
|
|---|
| 298 |
def sqlserver(fixture, mediated): |
|---|
| 299 |
try: |
|---|
| 300 |
import pythoncom |
|---|
| 301 |
except ImportError: |
|---|
| 302 |
print ("The pythoncom module could not be imported. " |
|---|
| 303 |
"The SQLServer test will not be run.") |
|---|
| 304 |
return |
|---|
| 305 |
|
|---|
| 306 |
from geniusql.providers import ado |
|---|
| 307 |
try: |
|---|
| 308 |
ado.gen_py() |
|---|
| 309 |
except ImportError: |
|---|
| 310 |
print ("ADO 2.7 support could not be verified. " |
|---|
| 311 |
"The SQLServer test will not be run.") |
|---|
| 312 |
return |
|---|
| 313 |
|
|---|
| 314 |
opts = {'connections.Connect': |
|---|
| 315 |
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
|
|---|
| 319 |
("Provider=SQLNCLI; Integrated Security=SSPI; " |
|---|
| 320 |
"Initial Catalog=dejavu_test; Data Source=(local)\VAIO_VEDB"), |
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 |
'connections.CommandTimeout': 10, |
|---|
| 324 |
} |
|---|
| 325 |
fixture.run(get_store("sqlserver", opts), mediated) |
|---|
| 326 |
|
|---|