def testLongDistanceDates(self): # If the result contains a year part, month part, week part # and day part the number of parts is controlled by # @max_no_sections (default 3) t1 = DateTime('2004/11/12 00:08:30.937 GMT') t2 = DateTime('2006/05/01 09:47:07.123 GMT') difference_default = Utils.timeSince(t1, t2) self.assertEqual(difference_default, '1 year and 5 months and 2 weeks') difference_2_parts = Utils.timeSince(t1, t2, max_no_sections=2) self.assertEqual(difference_2_parts, '1 year and 5 months') difference_99_parts = Utils.timeSince(t1, t2, max_no_sections=99) self.assertEqual(difference_99_parts, '1 year and 5 months and 2 weeks and 6 days')
def testMinutes1(self): # the timeSince() function drops the hour # part if the difference is in days t1 = DateTime('2005/04/01 12:00') t2 = DateTime('2005/04/01 12:30') difference = Utils.timeSince(t1, t2) self.assertEqual(difference, 0)
def testWeek1(self): # use the week notation t1 = DateTime('2005/04/01') t2 = DateTime('2005/04/08') difference = Utils.timeSince(t1, t2) self.assertEqual(difference, "1 week")
def testMinutes2(self): # the timeSince() function drops the hour # part if the difference is in days t1 = DateTime('2005/04/01 12:00') t2 = DateTime('2005/04/01 12:01') difference = Utils.timeSince(t1, t2, minute_granularity=1) self.assertEqual(difference, "1 minute")
def testPositives(self): T = lambda email: self.assertEqual(Utils.ValidEmailAddress(email), True ) T('*****@*****.**') T(u'*****@*****.**') T('*****@*****.**') T("peter'*****@*****.**") T('*****@*****.**') T('*****@*****.**')
def testNegatives(self): F = lambda email: self.assertEqual(Utils.ValidEmailAddress(email), False) F('[email protected]') F('peter @fry-it.com') F('[email protected]') F(u'[email protected]') F('[email protected]@r.com') F('invalid@f#o.com') F('*****@*****.**') F('invalid@foo.')
def testDays2(self): t1 = DateTime('2005/04/01') t2 = DateTime('2005/04/03') difference = Utils.timeSince(t1, t2) self.assertEqual(difference, "2 days")
def testYears2B(self): t1 = DateTime('2004/01/02') t2 = DateTime('2002/01/01') difference = Utils.timeSince(t1, t2) self.assertEqual(difference, "2 years and 1 day")
def test2Weeks(self): # use the week notation t1 = DateTime('2005/12/08 15:54:18.715 GMT') t2 = DateTime('2006/01/06 10:26:18.571 GMT') difference = Utils.timeSince(t1, t2) self.assertEqual(difference, '4 weeks')
def testWeek2point1(self): # use the week notation t1 = DateTime('2005/04/01') t2 = DateTime('2005/04/16') difference = Utils.timeSince(t1, t2) self.assertEqual(difference, "2 weeks and 1 day")
def test2Weeks(self): # use the week notation t1 = DateTime('2005/11/12 00:08:30.937 GMT') t2 = DateTime('2006/01/09 09:47:07.123 GMT') difference = Utils.timeSince(t1, t2) self.assertEqual(difference, '1 month and 4 weeks')
def testBasic1(self): inp = "peter anders bengt" exp = ['peter', 'anders', 'bengt'] self.assertEqual(Utils.splitTerms(inp), exp)
def testHours2(self): t1 = DateTime('2005/04/01 12:00') t2 = DateTime('2005/04/01 14:00') difference = Utils.timeSince(t1, t2) self.assertEqual(difference, "2 hours")
def testTwoQuotes(self): inp = 'peter "bengt anders" bengtsson "and again" peter' exp = ['peter','"bengt anders"','bengtsson', '"and again"','peter'] self.assertEqual(Utils.splitTerms(inp), exp)
def testEndingQuote(self): inp = 'peter "bengt anders"' exp = ['peter','"bengt anders"'] self.assertEqual(Utils.splitTerms(inp), exp)
def testOneQuote(self): inp = 'peter "bengt anders" bengtsson' exp = ['peter','"bengt anders"','bengtsson'] self.assertEqual(Utils.splitTerms(inp), exp)
def testUnbalanced(self): inp = 'peter "bengt anders bengtsson' exp = ['peter','"bengt','anders','bengtsson'] self.assertEqual(Utils.splitTerms(inp), exp)
def testBasic1(self): inp = "peter anders bengt" exp = ['peter','anders','bengt'] self.assertEqual(Utils.splitTerms(inp), exp)
def testOneQuote(self): inp = 'peter "bengt anders" bengtsson' exp = ['peter', '"bengt anders"', 'bengtsson'] self.assertEqual(Utils.splitTerms(inp), exp)
def testEndingQuote(self): inp = 'peter "bengt anders"' exp = ['peter', '"bengt anders"'] self.assertEqual(Utils.splitTerms(inp), exp)
def _find(self, text, zfill, trackerid=None, prefix=None): c = Utils.getFindIssueLinksRegex(zfill, trackerid, prefix) return c.findall(text)
def testBasic(self): inpu, inpp = "http://www.com", {'msg': 'foo bar'} exp = "http://www.com?msg=foo%20bar" self.assertEqual(Utils.AddParam2URL(inpu, inpp), exp)
def _find(self, word, text): return Utils.createStandaloneWordRegex(word).findall(text)
def testStartingQuote(self): inp = '"bengt anders" bengtsson' exp = ['"bengt anders"','bengtsson'] self.assertEqual(Utils.splitTerms(inp), exp)
def testUnbalanced(self): inp = 'peter "bengt anders bengtsson' exp = ['peter', '"bengt', 'anders', 'bengtsson'] self.assertEqual(Utils.splitTerms(inp), exp)
def testTwoQuotes(self): inp = 'peter "bengt anders" bengtsson "and again" peter' exp = ['peter', '"bengt anders"', 'bengtsson', '"and again"', 'peter'] self.assertEqual(Utils.splitTerms(inp), exp)
def testYears2A(self): t1 = DateTime('2005/01/01') # 2004 was a leap year t2 = DateTime('2003/01/02') difference = Utils.timeSince(t1, t2) self.assertEqual(difference, "2 years")
def testStartingQuote(self): inp = '"bengt anders" bengtsson' exp = ['"bengt anders"', 'bengtsson'] self.assertEqual(Utils.splitTerms(inp), exp)
def testBasicPlus(self): inpu, inpp = "http://www.com", {'msg': 'foo bar'} exp = "http://www.com?msg=foo+bar" self.assertEqual(Utils.AddParam2URL(inpu, inpp, plus_quote=1), exp)
def testYears3B(self): t1 = DateTime('2004/02/01') # 2004 was a leap year t2 = DateTime('2002/01/01') difference = Utils.timeSince(t1, t2) self.assertEqual(difference, "2 years and 1 month and 1 day")
def testMonths(self): t1 = DateTime('2005/04/01') t2 = DateTime('2005/05/01') difference = Utils.timeSince(t1, t2) self.assertEqual(difference, "1 month")