Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

I think I've seen this ORM somewhere before...

root/trunk/test/test_storemsaccess.py

Revision 223 (checked in by fumanchu, 7 years ago)

Lots of precision and scale fixes for #61. Note in particular that the float type now uses the 'precision' hint (binary digits) instead of the 'bytes' hint to determine column datatype. I also found out ADO and MySQL use 'precision' to mean 'max base 10 exponent', not 'significant digits'.

  • Property svn:eol-style set to native
Line 
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             # lists to keep track of the test_currency runs
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 ##                        print row[2], row[3], row[11]
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             # Isolate schema changes from one test to the next.
67             reload(zoo_fixture)
68            
69             # test the standard MS Access setup where Decimal and FixedPoint
70             # objects are stored in the database as INTEGERS, LONGS or DOUBLES
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             # plugin the adapter for testing CURRENCY columns
79             storeado.StorageManagerADO_MSAccess.typeAdapter = CurrencyAdapter()
80            
81             reload(zoo_fixture)
82            
83             # test storing and recalling Decimal values to the database using
84             # CURRENCY columns - the (current) default behavior of pythoncom
85             # is to return CURRENCY values as a tuple
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             # set pythoncom to return CURRENCY values as Decimal objects
94             pythoncom.__future_currency__ = True
95            
96             reload(zoo_fixture)
97            
98             # test storing and recalling Decimal values to the database using
99             # CURRENCY columns - CURRENCY values are now returned as Decimal
100             # objects
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()
Note: See TracBrowser for help on using the browser.