Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: appengine/monorail/search/test/query2ast_test.py

Issue 1941853002: [Monorail] Deflake the unit tests for parsing date queries. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « appengine/monorail/search/query2ast.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is govered by a BSD-style 2 # Use of this source code is govered by a BSD-style
3 # license that can be found in the LICENSE file or at 3 # license that can be found in the LICENSE file or at
4 # https://developers.google.com/open-source/licenses/bsd 4 # https://developers.google.com/open-source/licenses/bsd
5 5
6 """Tests for the query2ast module.""" 6 """Tests for the query2ast module."""
7 7
8 import datetime 8 import datetime
9 import time 9 import time
10 import unittest 10 import unittest
(...skipping 20 matching lines...) Expand all
31 GE = query2ast.GE 31 GE = query2ast.GE
32 TEXT_HAS = query2ast.TEXT_HAS 32 TEXT_HAS = query2ast.TEXT_HAS
33 NOT_TEXT_HAS = query2ast.NOT_TEXT_HAS 33 NOT_TEXT_HAS = query2ast.NOT_TEXT_HAS
34 TEXT_MATCHES = query2ast.TEXT_MATCHES 34 TEXT_MATCHES = query2ast.TEXT_MATCHES
35 NOT_TEXT_MATCHES = query2ast.NOT_TEXT_MATCHES 35 NOT_TEXT_MATCHES = query2ast.NOT_TEXT_MATCHES
36 IS_DEFINED = query2ast.IS_DEFINED 36 IS_DEFINED = query2ast.IS_DEFINED
37 IS_NOT_DEFINED = query2ast.IS_NOT_DEFINED 37 IS_NOT_DEFINED = query2ast.IS_NOT_DEFINED
38 KEY_HAS = query2ast.KEY_HAS 38 KEY_HAS = query2ast.KEY_HAS
39 39
40 MakeCond = ast_pb2.MakeCond 40 MakeCond = ast_pb2.MakeCond
41 NOW = 1277762224
41 42
42 43
43 class QueryParsingUnitTest(unittest.TestCase): 44 class QueryParsingUnitTest(unittest.TestCase):
44 45
45 def setUp(self): 46 def setUp(self):
46 self.project_id = 789 47 self.project_id = 789
47 self.default_config = tracker_bizobj.MakeDefaultProjectIssueConfig( 48 self.default_config = tracker_bizobj.MakeDefaultProjectIssueConfig(
48 self.project_id) 49 self.project_id)
49 50
50 def testParseUserQuery_OrClauseDisabled(self): 51 def testParseUserQuery_OrClauseDisabled(self):
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 MakeCond(TEXT_HAS, [ANY_FIELD], ['two'], []), ft_cond2) 557 MakeCond(TEXT_HAS, [ANY_FIELD], ['two'], []), ft_cond2)
557 self.assertEqual( 558 self.assertEqual(
558 MakeCond(GE, [BUILTIN_ISSUE_FIELDS['modified']], [], [ts1]), cond1) 559 MakeCond(GE, [BUILTIN_ISSUE_FIELDS['modified']], [], [ts1]), cond1)
559 ts2 = int(time.mktime(datetime.datetime(2008, 1, 1).timetuple())) 560 ts2 = int(time.mktime(datetime.datetime(2008, 1, 1).timetuple()))
560 self.assertEqual( 561 self.assertEqual(
561 MakeCond(LT, [BUILTIN_ISSUE_FIELDS['opened']], [], [ts2]), cond2) 562 MakeCond(LT, [BUILTIN_ISSUE_FIELDS['opened']], [], [ts2]), cond2)
562 563
563 # query with a date field compared to "today" 564 # query with a date field compared to "today"
564 ast = query2ast.ParseUserQuery( 565 ast = query2ast.ParseUserQuery(
565 'modified<today', '', BUILTIN_ISSUE_FIELDS, 566 'modified<today', '', BUILTIN_ISSUE_FIELDS,
566 self.default_config) 567 self.default_config, now=NOW)
567 cond1 = ast.conjunctions[0].conds[0] 568 cond1 = ast.conjunctions[0].conds[0]
568 ts1 = query2ast._CalculatePastDate(0) 569 ts1 = query2ast._CalculatePastDate(0, now=NOW)
569 self.assertEqual(MakeCond(LT, [BUILTIN_ISSUE_FIELDS['modified']], 570 self.assertEqual(MakeCond(LT, [BUILTIN_ISSUE_FIELDS['modified']],
570 [], [ts1]), 571 [], [ts1]),
571 cond1) 572 cond1)
572 573
573 # query with a daterange using today-N alias 574 # query with a daterange using today-N alias
574 ast = query2ast.ParseUserQuery( 575 ast = query2ast.ParseUserQuery(
575 'modified>=today-13', '', BUILTIN_ISSUE_FIELDS, 576 'modified>=today-13', '', BUILTIN_ISSUE_FIELDS,
576 self.default_config) 577 self.default_config, now=NOW)
577 cond1 = ast.conjunctions[0].conds[0] 578 cond1 = ast.conjunctions[0].conds[0]
578 ts1 = query2ast._CalculatePastDate(13) 579 ts1 = query2ast._CalculatePastDate(13, now=NOW)
579 self.assertEqual(MakeCond(GE, [BUILTIN_ISSUE_FIELDS['modified']], 580 self.assertEqual(MakeCond(GE, [BUILTIN_ISSUE_FIELDS['modified']],
580 [], [ts1]), 581 [], [ts1]),
581 cond1) 582 cond1)
582 583
583 ast = query2ast.ParseUserQuery( 584 ast = query2ast.ParseUserQuery(
584 'modified>today-13', '', BUILTIN_ISSUE_FIELDS, self.default_config) 585 'modified>today-13', '', BUILTIN_ISSUE_FIELDS, self.default_config,
586 now=NOW)
585 cond1 = ast.conjunctions[0].conds[0] 587 cond1 = ast.conjunctions[0].conds[0]
586 ts1 = query2ast._CalculatePastDate(13) 588 ts1 = query2ast._CalculatePastDate(13, now=NOW)
587 self.assertEqual(MakeCond(GT, [BUILTIN_ISSUE_FIELDS['modified']], 589 self.assertEqual(MakeCond(GT, [BUILTIN_ISSUE_FIELDS['modified']],
588 [], [ts1]), 590 [], [ts1]),
589 cond1) 591 cond1)
590 592
591 # query with multiple old date query terms. 593 # query with multiple old date query terms.
592 ast = query2ast.ParseUserQuery( 594 ast = query2ast.ParseUserQuery(
593 'modified-after:2009-5-12 opened-before:2008/1/1 ' 595 'modified-after:2009-5-12 opened-before:2008/1/1 '
594 'closed-after:2007-2-1', '', 596 'closed-after:2007-2-1', '',
595 BUILTIN_ISSUE_FIELDS, self.default_config) 597 BUILTIN_ISSUE_FIELDS, self.default_config)
596 cond1, cond2, cond3 = ast.conjunctions[0].conds 598 cond1, cond2, cond3 = ast.conjunctions[0].conds
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 warnings = [] 655 warnings = []
654 msg = query2ast.CheckSyntax( 656 msg = query2ast.CheckSyntax(
655 'foo (bar)', self.default_config, warnings=warnings) 657 'foo (bar)', self.default_config, warnings=warnings)
656 self.assertIsNone(msg) 658 self.assertIsNone(msg)
657 self.assertEqual( 659 self.assertEqual(
658 ['Parentheses are ignored in user queries.'], 660 ['Parentheses are ignored in user queries.'],
659 warnings) 661 warnings)
660 662
661 if __name__ == '__main__': 663 if __name__ == '__main__':
662 unittest.main() 664 unittest.main()
OLDNEW
« no previous file with comments | « appengine/monorail/search/query2ast.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698