parsedatetime.tests.TestAustralianLocale

Package parsedatetime :: Package tests :: Module TestAustralianLocale |
[hide private]
[frames] | no frames]

# Source Code for Module parsedatetime.tests.TestAustralianLocale

     1  #!/usr/bin/env python
     2
     3  """
     4  Test parsing of simple date and times using the Australian locale
     5  """
     6
     7  import unittest, time, datetime
     8  import parsedatetime.parsedatetime as pt
     9  import parsedatetime.parsedatetime_consts as ptc
    10
    11
    12    # a special compare function is used to allow us to ignore the seconds as
    13    # the running of the test could cross a minute boundary
    14 -def _compareResults(result, check):
    15      target, t_flag = result
    16      value,  v_flag = check
    17
    18      t_yr, t_mth, t_dy, t_hr, t_min, _, _, _, _ = target
    19      v_yr, v_mth, v_dy, v_hr, v_min, _, _, _, _ = value
    20
    21      return ((t_yr == v_yr) and (t_mth == v_mth) and (t_dy == v_dy) and
    22              (t_hr == v_hr) and (t_min == v_min)) and (t_flag == v_flag)
    23
    24 -class test(unittest.TestCase):
    25 -    def setUp(self):
    26          self.ptc = ptc.Constants('en_AU', usePyICU=False)
    27          self.cal = pt.Calendar(self.ptc)
    28
    29          self.yr, self.mth, self.dy, self.hr, self.mn, self.sec, self.wd, self.yd, self.isdst = time.localtime()
    30
    31
    32 -    def testTimes(self):
    33          start  = datetime.datetime(self.yr, self.mth, self.dy, self.hr, self.mn, self.sec).timetuple()
    34          target = datetime.datetime(self.yr, self.mth, self.dy, 23, 0, 0).timetuple()
    35
    36          self.assertTrue(_compareResults(self.cal.parse('11:00:00 PM', start), (target, 2)))
    37          self.assertTrue(_compareResults(self.cal.parse('11:00 PM',    start), (target, 2)))
    38          self.assertTrue(_compareResults(self.cal.parse('11 PM',       start), (target, 2)))
    39          self.assertTrue(_compareResults(self.cal.parse('11PM',        start), (target, 2)))
    40          self.assertTrue(_compareResults(self.cal.parse('2300',        start), (target, 2)))
    41          self.assertTrue(_compareResults(self.cal.parse('23:00',       start), (target, 2)))
    42          self.assertTrue(_compareResults(self.cal.parse('11p',         start), (target, 2)))
    43          self.assertTrue(_compareResults(self.cal.parse('11pm',        start), (target, 2)))
    44
    45          target = datetime.datetime(self.yr, self.mth, self.dy, 11, 0, 0).timetuple()
    46
    47          self.assertTrue(_compareResults(self.cal.parse('11:00:00 AM', start), (target, 2)))
    48          self.assertTrue(_compareResults(self.cal.parse('11:00 AM',    start), (target, 2)))
    49          self.assertTrue(_compareResults(self.cal.parse('11 AM',       start), (target, 2)))
    50          self.assertTrue(_compareResults(self.cal.parse('11AM',        start), (target, 2)))
    51          self.assertTrue(_compareResults(self.cal.parse('1100',        start), (target, 2)))
    52          self.assertTrue(_compareResults(self.cal.parse('11:00',       start), (target, 2)))
    53          self.assertTrue(_compareResults(self.cal.parse('11a',         start), (target, 2)))
    54          self.assertTrue(_compareResults(self.cal.parse('11am',        start), (target, 2)))
    55
    56          target = datetime.datetime(self.yr, self.mth, self.dy, 7, 30, 0).timetuple()
    57
    58          self.assertTrue(_compareResults(self.cal.parse('730',  start), (target, 2)))
    59          self.assertTrue(_compareResults(self.cal.parse('0730', start), (target, 2)))
    60
    61          target = datetime.datetime(self.yr, self.mth, self.dy, 17, 30, 0).timetuple()
    62
    63          self.assertTrue(_compareResults(self.cal.parse('1730',   start), (target, 2)))
    64          self.assertTrue(_compareResults(self.cal.parse('173000', start), (target, 2)))
    65
    66
    67 -    def testDates(self):
    68          start  = datetime.datetime(self.yr, self.mth, self.dy, self.hr, self.mn, self.sec).timetuple()
    69          target = datetime.datetime(2006, 8, 25,  self.hr, self.mn, self.sec).timetuple()
    70
    71          self.assertTrue(_compareResults(self.cal.parse('25-08-2006', start), (target, 1)))
    72          self.assertTrue(_compareResults(self.cal.parse('25/08/2006', start), (target, 1)))
    73          self.assertTrue(_compareResults(self.cal.parse('25.08.2006', start), (target, 1)))
    74          self.assertTrue(_compareResults(self.cal.parse('25-8-06',    start), (target, 1)))
    75          self.assertTrue(_compareResults(self.cal.parse('25/8/06',    start), (target, 1)))
    76
    77          if self.mth > 8 or (self.mth == 8 and self.dy > 25):
    78              target = datetime.datetime(self.yr+1, 8, 25,  self.hr, self.mn, self.sec).timetuple()
    79          else:
    80              target = datetime.datetime(self.yr, 8, 25,  self.hr, self.mn, self.sec).timetuple()
    81
    82          self.assertTrue(_compareResults(self.cal.parse('25-8',       start), (target, 1)))
    83          self.assertTrue(_compareResults(self.cal.parse('25/8',       start), (target, 1)))
    84          self.assertTrue(_compareResults(self.cal.parse('25.8',       start), (target, 1)))
    85          self.assertTrue(_compareResults(self.cal.parse('25-08',      start), (target, 1)))
    86          self.assertTrue(_compareResults(self.cal.parse('25/08',      start), (target, 1)))
    87
    88
    89  if __name__ == "__main__":
    90      unittest.main()
    91