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

Source Code for Module parsedatetime.tests.TestErrors

 1   
 2  """ 
 3  Test parsing of units 
 4  """ 
 5   
 6  import unittest, time, datetime 
 7  import parsedatetime as pdt 
8 9 -class test(unittest.TestCase):
10 11 @pdt.tests.assertEqualWithComparator
12 - def assertExpectedResult(self, result, check, **kwargs):
13 return pdt.tests.compareResultByTimeTuplesAndFlags(result, check, **kwargs)
14 15 @pdt.tests.assertEqualWithComparator
16 - def assertExpectedErrorFlag(self, result, check, **kwargs):
17 return pdt.tests.compareResultByFlags(result, check, **kwargs)
18
19 - def setUp(self):
20 self.cal = pdt.Calendar() 21 self.yr, self.mth, self.dy, self.hr, self.mn, self.sec, self.wd, self.yd, self.isdst = time.localtime()
22
23 - def testErrors(self):
24 s = datetime.datetime.now() 25 start = s.timetuple() 26 27 # These tests all return current date/time as they are out of range 28 self.assertExpectedResult(self.cal.parse('01/0', start), (start, 0)) 29 self.assertExpectedResult(self.cal.parse('08/35', start), (start, 0)) 30 self.assertExpectedResult(self.cal.parse('18/35', start), (start, 0)) 31 self.assertExpectedResult(self.cal.parse('1799', start), (start, 0)) 32 self.assertExpectedResult(self.cal.parse('781', start), (start, 0)) 33 self.assertExpectedResult(self.cal.parse('2702', start), (start, 0)) 34 self.assertExpectedResult(self.cal.parse('78', start), (start, 0)) 35 self.assertExpectedResult(self.cal.parse('11', start), (start, 0)) 36 self.assertExpectedResult(self.cal.parse('1', start), (start, 0)) 37 self.assertExpectedResult(self.cal.parse('174565', start), (start, 0)) 38 self.assertExpectedResult(self.cal.parse('177505', start), (start, 0)) 39 # ensure short month names do not cause false positives within a word - jun (june) 40 self.assertExpectedResult(self.cal.parse('injunction', start), (start, 0)) 41 # ensure short month names do not cause false positives at the start of a word - jul (juuly) 42 self.assertExpectedResult(self.cal.parse('julius', start), (start, 0)) 43 # ensure short month names do not cause false positives at the end of a word - mar (march) 44 self.assertExpectedResult(self.cal.parse('lamar', start), (start, 0)) 45 # ensure short weekday names do not cause false positives within a word - mon (monday) 46 self.assertExpectedResult(self.cal.parse('demonize', start), (start, 0)) 47 # ensure short weekday names do not cause false positives at the start of a word - mon (monday) 48 self.assertExpectedResult(self.cal.parse('money', start), (start, 0)) 49 # ensure short weekday names do not cause false positives at the end of a word - th (thursday) 50 self.assertExpectedResult(self.cal.parse('month', start), (start, 0)) 51 self.assertExpectedErrorFlag(self.cal.parse('30/030/01/071/07', start), (start, 0))
52 53 54 if __name__ == "__main__": 55 unittest.main() 56