Commits

Jan Brohl  committed a2270ea

fixed imports in tests, removed unused imports, some formatting

  • Participants
  • Parent commits 84b2d07

Comments (0)

Files changed (5)

File pydal/config_MySQLdb.py

 import MySQLdb
-import datetime
-import math
 
 # special quote/escape chracters (if any)
 quote_chars = ["`"]

File pydal/test/test_dbtime.py

 import time
 import mx.DateTime
 import psycopg
+from pydal.dbapi import dbtime
+
 
 def datetime_equal(mxdt, pydt):
     assert mxdt.year == pydt.year
     assert round(math.modf(mxdt.second)[0] * 1000000) == pydt.microsecond
     return True
 
+
 def time_equal(mxt, pyt):
     assert mxt.day == 0
     assert mxt.hour == pyt.hour
     assert round(math.modf(mxt.second)[0] * 1000000) == pyt.microsecond
     return True
 
+
 def delta_equal(mxdtd, pydtd):
     assert mxdtd.day == pydtd.days
     mxdtd_sec = int(math.modf(mxdtd.seconds)[1])
     assert mxdtd_msec == pydtd.microseconds
     return True
 
+
 def date_equal(mxd, pyd):
     assert mxd.year == pyd.year
     assert mxd.month == pyd.month
     assert mxd.day == pyd.day
     return True
 
+
 class Mx2PyDateTimeTest(unittest.TestCase):
 
     def testCurrentDateTime(self):
         pynow = dbtime.mx2pydt(mxnow)
         self.assert_(datetime_equal(mxnow, pynow))
 
+
 class Mx2PyTimeTest(unittest.TestCase):
 
     def testCurrentTime(self):
         pyt = dbtime.mx2pydt(mxt)
         self.assert_(time_equal(mxt, pyt))
 
+
 class Mx2PyDtDeltaTest(unittest.TestCase):
 
     def testCurrentDelta(self):
 
     def testTypeDetector(self):
         mxdt = mx.DateTime.now()
-        mxdtd = mx.DateTime.DateTimeDelta(0, mxdt.hour, mxdt.minute, 
+        mxdtd = mx.DateTime.DateTimeDelta(0, mxdt.hour, mxdt.minute,
                                           mxdt.second)
         pydtd = dbtime.mx2pydtdelta(mxdtd)
         self.assert_(delta_equal(mxdtd, pydtd))
 
+
 class Mx2PyDtTest(unittest.TestCase):
 
     def testCurrentDate(self):
         pyd = dbtime.mx2pydt(mxd)
         self.assert_(date_equal(mxd, pyd))
 
+
 class Py2MxDtTest(unittest.TestCase):
 
     def testCurrentDateTime(self):
         mxdt = dbtime.py2mxdt(pydt)
         self.assert_(date_equal(mxdt, pydt))
 
+
 class Py2MxTimeTest(unittest.TestCase):
-    
+
     def testCurrentTime(self):
         pyt = datetime.datetime.now().time()
         mxt = dbtime.py2mxtime(pyt)
         mxt = dbtime.py2mxdt(pyt)
         self.assert_(time_equal(mxt, pyt))
 
+
 class Py2MxDtDeltaTest(unittest.TestCase):
-    
+
     def testCurrentDelta(self):
         pydt = datetime.datetime.now()
         pydtd = datetime.timedelta(0, pydt.second, pydt.microsecond, 0,
         mxdtd = dbtime.py2mxdt(pydtd)
         self.assert_(delta_equal(mxdtd, pydtd))
 
+
 # Date and time construction tests
 
+
 class ConstructDateTest(unittest.TestCase):
 
     def testCurrentDate(self):
         cdt = dbtime.construct_date('mx', dt.year, dt.month, dt.day)
         self.assert_(isinstance(cdt, mx.DateTime.DateTimeType))
 
+
 class ConstructTimeTest(unittest.TestCase):
-    
+
     def testCurrentTime(self):
         t = datetime.datetime.now().time()
         ct = dbtime.construct_time('py', t.hour, t.minute, t.second)
         ct = dbtime.construct_time('mx', t.hour, t.minute, t.second)
         self.assert_(isinstance(ct, mx.DateTime.DateTimeDeltaType))
 
+
 class ConstructTimeStampTest(unittest.TestCase):
-    
+
     def testCurrentDateTime(self):
         dt = datetime.datetime.now()
         cdt = dbtime.construct_timestamp('py', dt.year, dt.month, dt.day,
                                          dt.hour, dt.minute, dt.second)
         self.assert_(isinstance(cdt, mx.DateTime.DateTimeType))
 
+
 class ConstructDateFromTicksTest(unittest.TestCase):
-    
+
     def testCurrentDate(self):
         ticks = time.time()
         date = datetime.date.fromtimestamp(ticks)
         self.assert_(isinstance(cdate, mx.DateTime.DateTimeType))
         self.assertEqual(date, cdate)
 
+
 class ConstructTimeFromTicksTest(unittest.TestCase):
-    
+
     def testCurrentTime(self):
         ticks = time.time()
         nowtime = datetime.datetime.fromtimestamp(ticks).time()
         self.assert_(isinstance(cnowtime, mx.DateTime.DateTimeDeltaType))
         self.assertEqual(nowtime, cnowtime)
 
+
 class ConstructTimeStampFromTicksTest(unittest.TestCase):
-    
+
     def testCurrentDate(self):
         ticks = time.time()
         dt = datetime.datetime.fromtimestamp(ticks)
 
 # Other functions
 
+
 class Native2Pref(unittest.TestCase):
 
     # to datetime.datetime type
         self.assert_(isinstance(mxdt, mx.DateTime.DateTimeType))
 
     def testMx2MxDateTime(self):
-        mxdt1 = mx.DateTime.now() 
+        mxdt1 = mx.DateTime.now()
         mxdt2 = dbtime.native2pref(mxdt1, 'mx')
         self.assertEqual(mxdt1, mxdt2)
 
         self.assert_(isinstance(pydt2, datetime.time))
         self.assertEqual(pydt1, pydt2)
 
-    def testStr2PyDate(self):
+    def testStr2PyDate2(self):
         strdt = '12:21:32 AM'
         pydt1 = datetime.time(12, 21, 32)
         pydt2 = dbtime.native2pref(strdt, 'py')
     def testCustomType(self):
         pass
 
+
 class DtClass(unittest.TestCase):
 
     def testPy(self):
         result = dbtime.dtclass(strdt)
         self.failUnless(result == None)
 
+
 class DtSubNative(unittest.TestCase):
 
     def testPyPyscopg(self):
 
 
 if __name__ == '__main__':
-    from pydal.dbapi import dbtime
     unittest.main()

File pydal/test/test_mysql.py

 import datetime
 import mx.DateTime
 import time
+from pydal.dbapi import wrapdriver
 
 class Initialization(unittest.TestCase):
 
         del self.dbmod
 
 def main():
-    dbmod = dal.wrapdriver('MySQLdb')
+    dbmod = wrapdriver('MySQLdb')
     cn = dbmod.connect(db='dball', user='randall', passwd='arnold1')
     cs = cn.cursor()
     cs.use_db_row = True
 
 
 if __name__ == '__main__':
-    import os
-    cwd = os.getcwd()
-    cwds = cwd.split('/')
-    dal_dir = '/'.join(cwds[:-3])
-    import sys
-    sys.path.insert(0, dal_dir)
-    import dal
     unittest.main()

File pydal/test/test_nodb.py

 import unittest
-import datetime
-import time
 import mx.DateTime
-import psycopg
+import math
+from pydal.dbapi import dbtime
+
 
 def datetime_equal(mxdt, pydt):
     assert mxdt.year == pydt.year
     assert round(math.modf(mxdt.second)[0] * 1000000) == pydt.microsecond
     return True
 
+
 def time_equal(mxt, pyt):
     assert mxt.day == 0
     assert mxt.hour == pyt.hour
     assert round(math.modf(mxt.second)[0] * 1000000) == pyt.microsecond
     return True
 
+
 def delta_equal(mxdtd, pydtd):
     assert mxdtd.day == pydtd.days
     mxdtd_sec = int(math.modf(mxdtd.seconds)[1])
     assert mxdtd_msec == pydtd.microseconds
     return True
 
+
 def date_equal(mxd, pyd):
     assert mxd.year == pyd.year
     assert mxd.month == pyd.month
     assert mxd.day == pyd.day
     return True
 
+
 class Mx2PyDateTimeTest(unittest.TestCase):
 
     def testCurrentDateTime(self):
         self.assert_(datetime_equal(mxnow, pynow))
 
 
-
-
 if __name__ == '__main__':
-    import os
-    cwd = os.getcwd()
-    cwds = cwd.split('/')
-    dal_dir = '/'.join(cwds[:-3])
-    import sys
-    sys.path.insert(0, dal_dir)
-    import dal
     unittest.main()

File pydal/test/test_paramstyles.py

 Peter's first stab at a unit test
 """
 import unittest
-from dal.dbapi.paramstyles import *
+from pydal.paramstyles import convert, segmentize
 
 SEGMENTIZE_TESTS = [
-    [ r'S1', ['S1'] ],
-    [ r'"S1"S2', ['"S1"', 'S2'] ],
-]
+                    [r'S1', ['S1'] ],
+                    [r'"S1"S2', ['"S1"', 'S2'] ]
+                    ]
 
 PARAMSTYLE_TESTS = [
     {
 
     def testSegments(self):
         for test in self.tests:
-            input    = test[0]
+            input = test[0]
             expected = test[1]
-            actual   = segmentize(input)
+            actual = segmentize(input)
             assert actual == expected, 'input=%s, expected=%s, actual=%s' % (input, expected, actual)
 
+
 class ParamstyleTests(unittest.TestCase):
 
     def setUp(self):
     def testParamstyles(self):
         for test in self.tests:
             from_paramstyle = test['from']
-            to_paramstyle   = test['to']
-            input_query     = test['input_query']
-            expected_query  = test['expected_query']
-            input_params    = test['input_params']
+            to_paramstyle = test['to']
+            input_query = test['input_query']
+            expected_query = test['expected_query']
+            input_params = test['input_params']
             expected_params = test['expected_params']
-            actual_query, actual_params = convert( from_paramstyle, to_paramstyle, input_query, input_params )
-            assert actual_query == expected_query and actual_params == expected_params, 'from=%s, to=%s, input_query=%s, input_params=%s, expected_query=%s, expected_params=%s, actual_query=%s, actual_params=%s' % (from_paramstyle, to_paramstyle, input_query, input_params, expected_query, expected_params, actual_query, actual_params)
+            actual_query, actual_params = convert(from_paramstyle, to_paramstyle, input_query, input_params)
+            assert (actual_query == expected_query and actual_params == expected_params,
+                    'from=%s, to=%s, input_query=%s, input_params=%s, expected_query=%s, expected_params=%s, actual_query=%s, actual_params=%s' %
+                    (from_paramstyle, to_paramstyle, input_query, input_params, expected_query, expected_params, actual_query, actual_params))
 
 
 if __name__ == '__main__':
-    import os
-    cwd = os.getcwd()
-    cwds = cwd.split('/')
-    dal_dir = '/'.join(cwds[:-3])
-    import sys
-    sys.path.insert(0, dal_dir)
-    import dal
     unittest.main()