PyLucene 3.4.0-1 import
[pylucene.git] / test / test_BooleanQuery.py
1 # ====================================================================
2 #   Licensed under the Apache License, Version 2.0 (the "License");
3 #   you may not use this file except in compliance with the License.
4 #   You may obtain a copy of the License at
5 #
6 #       http://www.apache.org/licenses/LICENSE-2.0
7 #
8 #   Unless required by applicable law or agreed to in writing, software
9 #   distributed under the License is distributed on an "AS IS" BASIS,
10 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 #   See the License for the specific language governing permissions and
12 #   limitations under the License.
13 # ====================================================================
14
15 from unittest import TestCase, main
16 from lucene import *
17
18
19 class TestBooleanQuery(TestCase):
20     """
21     Unit tests ported from Java Lucene
22     """
23
24     def testEquality(self):
25
26         bq1 = BooleanQuery()
27         bq1.add(TermQuery(Term("field", "value1")), BooleanClause.Occur.SHOULD)
28         bq1.add(TermQuery(Term("field", "value2")), BooleanClause.Occur.SHOULD)
29
30         nested1 = BooleanQuery()
31         nested1.add(TermQuery(Term("field", "nestedvalue1")), BooleanClause.Occur.SHOULD)
32         nested1.add(TermQuery(Term("field", "nestedvalue2")), BooleanClause.Occur.SHOULD)
33         bq1.add(nested1, BooleanClause.Occur.SHOULD)
34
35         bq2 = BooleanQuery()
36         bq2.add(TermQuery(Term("field", "value1")), BooleanClause.Occur.SHOULD)
37         bq2.add(TermQuery(Term("field", "value2")), BooleanClause.Occur.SHOULD)
38
39         nested2 = BooleanQuery()
40         nested2.add(TermQuery(Term("field", "nestedvalue1")), BooleanClause.Occur.SHOULD)
41         nested2.add(TermQuery(Term("field", "nestedvalue2")), BooleanClause.Occur.SHOULD)
42         bq2.add(nested2, BooleanClause.Occur.SHOULD)
43         
44         self.assert_(bq1.equals(bq2))
45
46
47 if __name__ == "__main__":
48     import sys, lucene
49     lucene.initVM()
50     if '-loop' in sys.argv:
51         sys.argv.remove('-loop')
52         while True:
53             try:
54                 main()
55             except:
56                 pass
57     else:
58          main()