| 1 |
"""This works...most of the time. Sometimes during the Multithreading, |
|---|
| 2 |
the Access SM will crash python.""" |
|---|
| 3 |
|
|---|
| 4 |
import warnings |
|---|
| 5 |
|
|---|
| 6 |
try: |
|---|
| 7 |
import pythoncom |
|---|
| 8 |
except ImportError: |
|---|
| 9 |
def run(): |
|---|
| 10 |
warnings.warn("The pythoncom module could not be imported. " |
|---|
| 11 |
"The MSAccess test will not be run.") |
|---|
| 12 |
else: |
|---|
| 13 |
from dejavu.storage import storeado |
|---|
| 14 |
mod = storeado.gen_py() |
|---|
| 15 |
if mod is None: |
|---|
| 16 |
def run(): |
|---|
| 17 |
warnings.warn("ADO 2.7 support could not be verified. " |
|---|
| 18 |
"The MSAccess test will not be run.") |
|---|
| 19 |
else: |
|---|
| 20 |
|
|---|
| 21 |
class CurrencyAdapter(storeado.FieldTypeAdapter_MSAccess): |
|---|
| 22 |
"""Stores Decimal and FixedPoint objects as CURRENCY.""" |
|---|
| 23 |
|
|---|
| 24 |
def coerce_decimal_Decimal(self, cls, key): |
|---|
| 25 |
return "CURRENCY" |
|---|
| 26 |
|
|---|
| 27 |
def coerce_fixedpoint_FixedPoint(self, cls, key): |
|---|
| 28 |
return "CURRENCY" |
|---|
| 29 |
|
|---|
| 30 |
SM_class = "dejavu.storage.storeado.StorageManagerADO_MSAccess" |
|---|
| 31 |
opts = {u'Connect': "PROVIDER=MICROSOFT.JET.OLEDB.4.0;" |
|---|
| 32 |
"DATA SOURCE=zoo.mdb;", |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
def run(): |
|---|
| 36 |
import zoo_fixture |
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
standard_runs = [] |
|---|
| 40 |
altered_runs = [] |
|---|
| 41 |
|
|---|
| 42 |
def test_currency(obj): |
|---|
| 43 |
sm = zoo_fixture.arena.stores['testSM'] |
|---|
| 44 |
fta = sm.typeAdapter.__class__.__name__ |
|---|
| 45 |
|
|---|
| 46 |
clsnames = ('Exhibit', 'Zoo') |
|---|
| 47 |
tblnames = [sm.table_name(cn).strip('[]') for cn in clsnames] |
|---|
| 48 |
colnames = ('Acreage', 'Admission') |
|---|
| 49 |
targets = dict(zip(tblnames, colnames)) |
|---|
| 50 |
data, _ = sm.fetch(storeado.adSchemaColumns, conn=None, |
|---|
| 51 |
schema=True) |
|---|
| 52 |
for row in data: |
|---|
| 53 |
match = targets.get(row[2]) |
|---|
| 54 |
if not match: |
|---|
| 55 |
continue |
|---|
| 56 |
if match == row[3]: |
|---|
| 57 |
|
|---|
| 58 |
dt = row[11] |
|---|
| 59 |
|
|---|
| 60 |
if fta in ("CurrencyAdapter",): |
|---|
| 61 |
obj.assertEqual(dt, storeado.adCurrency) |
|---|
| 62 |
else: |
|---|
| 63 |
obj.assertEqual(dt, storeado.adDouble) |
|---|
| 64 |
obj.assertEqual(len(standard_runs), 0) |
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 |
reload(zoo_fixture) |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
print |
|---|
| 72 |
print "Standard MSAccess test." |
|---|
| 73 |
zoo_fixture.ZooTests.test_currency = test_currency |
|---|
| 74 |
zoo_fixture.init() |
|---|
| 75 |
zoo_fixture.run(SM_class, opts) |
|---|
| 76 |
standard_runs.append(True) |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
storeado.StorageManagerADO_MSAccess.typeAdapter = CurrencyAdapter() |
|---|
| 80 |
|
|---|
| 81 |
reload(zoo_fixture) |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
print |
|---|
| 87 |
print "MSAccess test - CURRENCY returned as tuple." |
|---|
| 88 |
zoo_fixture.ZooTests.test_currency = test_currency |
|---|
| 89 |
zoo_fixture.init() |
|---|
| 90 |
zoo_fixture.run(SM_class, opts) |
|---|
| 91 |
altered_runs.append(True) |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
pythoncom.__future_currency__ = True |
|---|
| 95 |
|
|---|
| 96 |
reload(zoo_fixture) |
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
print |
|---|
| 102 |
print "MSAccess test - CURRENCY returned as Decimal." |
|---|
| 103 |
zoo_fixture.ZooTests.test_currency = test_currency |
|---|
| 104 |
zoo_fixture.init() |
|---|
| 105 |
zoo_fixture.run(SM_class, opts) |
|---|
| 106 |
altered_runs.append(True) |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
if __name__ == "__main__": |
|---|
| 110 |
run() |
|---|