# pydal / pydal / test / test_nodb.py

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63``` ```import unittest import datetime import time import mx.DateTime import psycopg def datetime_equal(mxdt, pydt): assert mxdt.year == pydt.year assert mxdt.month == pydt.month assert mxdt.day == pydt.day assert mxdt.hour == pydt.hour assert mxdt.minute == pydt.minute assert math.floor(mxdt.second) == pydt.second 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 mxt.minute == pyt.minute assert math.floor(mxt.second) == pyt.second 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]) pydtd_sec = pydtd.seconds + pydtd.days * 1440 * 60 assert mxdtd_sec == pydtd_sec mxdtd_msec = int(round(math.modf(mxdtd.seconds)[0] * 1000000)) 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): mxnow = mx.DateTime.now() pynow = dbtime.mx2pydatetime(mxnow) self.assert_(datetime_equal(mxnow, pynow)) def testTypeDetector(self): mxnow = mx.DateTime.now() pynow = dbtime.mx2pydt(mxnow) 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() ```