@@ -27,13 +27,13 @@ def numbers(self):
2727 return (self .num , self .num + 1 )
2828
2929 def getPhysicalPath (self ):
30- return ' /{0}' .format (self .num )
30+ return " /{0}" .format (self .num )
3131
3232 def start (self ):
33- return ' 2013-07-{0:02d}' .format (self .num + 1 )
33+ return " 2013-07-{0:02d}" .format (self .num + 1 )
3434
3535 def end (self ):
36- return ' 2013-07-{0:02d}' .format (self .num + 2 )
36+ return " 2013-07-{0:02d}" .format (self .num + 2 )
3737
3838
3939class TestCatalogPlan (cleanup .CleanUp , unittest .TestCase ):
@@ -46,10 +46,11 @@ def assertRegex(self, *args, **kwargs):
4646
4747 def setUp (self ):
4848 cleanup .CleanUp .setUp (self )
49- self .cat = Catalog (' catalog' )
49+ self .cat = Catalog (" catalog" )
5050
5151 def _makeOne (self , catalog = None , query = None ):
5252 from Products .ZCatalog .plan import CatalogPlan
53+
5354 if catalog is None :
5455 catalog = self .cat
5556 return CatalogPlan (catalog , query = query )
@@ -61,14 +62,12 @@ def test_getCatalogPlan_partial(self):
6162 class SlowFieldIndex (FieldIndex ):
6263 def query_index (self , record , resultset = None ):
6364 time .sleep (0.1 )
64- return super (SlowFieldIndex , self ).query_index (
65- record , resultset )
65+ return super (SlowFieldIndex , self ).query_index (record , resultset )
6666
6767 class SlowerDateRangeIndex (DateRangeIndex ):
6868 def query_index (self , record , resultset = None ):
6969 time .sleep (0.2 )
70- return super (SlowerDateRangeIndex , self ).query_index (
71- record , resultset )
70+ return super (SlowerDateRangeIndex , self ).query_index (record , resultset )
7271
7372 cat .addIndex ("num" , SlowFieldIndex ("num" ))
7473 cat .addIndex ("numbers" , KeywordIndex ("numbers" ))
@@ -85,95 +84,75 @@ def query_index(self, record, resultset=None):
8584
8685 # without a plan index are orderd alphabetically by default
8786 self .assertEqual (zcat ._catalog .getCatalogPlan (query1 ).plan (), None )
88- self .assertEqual (
89- cat ._sorted_search_indexes (query1 ),
90- ["date" , "num" , "numbers" ]
91- )
87+ self .assertEqual (cat ._sorted_search_indexes (query1 ), ["date" , "num" , "numbers" ])
9288
9389 self .assertEqual ([b .getPath () for b in zcat .search (query1 )], ["2" ])
9490 self .assertRegex (
95- zcat .getCatalogPlan (),
96- r"(?ms).*'date':\s*\([0-9\.]+, [0-9\.]+, True\)"
91+ zcat .getCatalogPlan (), r"(?ms).*'date':\s*\([0-9\.]+, [0-9\.]+, True\)"
9792 )
9893 self .assertRegex (
99- zcat .getCatalogPlan (),
100- r"(?ms).*'num':\s*\([0-9\.]+, [0-9\.]+, True\)"
94+ zcat .getCatalogPlan (), r"(?ms).*'num':\s*\([0-9\.]+, [0-9\.]+, True\)"
10195 )
10296 self .assertRegex (
103- zcat .getCatalogPlan (),
104- r"(?ms).*'numbers':\s*\([0-9\.]+, [0-9\.]+, True\)"
97+ zcat .getCatalogPlan (), r"(?ms).*'numbers':\s*\([0-9\.]+, [0-9\.]+, True\)"
10598 )
10699
107100 # after first search field are orderd by speed
108- self .assertEqual (
109- cat .getCatalogPlan (query2 ).plan (), ["numbers" , "num" , "date" ])
101+ self .assertEqual (cat .getCatalogPlan (query2 ).plan (), ["numbers" , "num" , "date" ])
110102
111103 self .assertEqual ([b .getPath () for b in zcat .search (query2 )], [])
112104
113105 # `date', `num`, and `numbers` are all involved to filter the
114106 # results(limit flag) despite in the last query search whitin
115107 # `num` and `date` wasn't done
116108 self .assertRegex (
117- zcat .getCatalogPlan (),
118- r"(?ms).*'date':\s*\([0-9\.]+, [0-9\.]+, True\)"
109+ zcat .getCatalogPlan (), r"(?ms).*'date':\s*\([0-9\.]+, [0-9\.]+, True\)"
119110 )
120111 self .assertRegex (
121- zcat .getCatalogPlan (),
122- r"(?ms).*'num':\s*\([0-9\.]+, [0-9\.]+, True\)"
112+ zcat .getCatalogPlan (), r"(?ms).*'num':\s*\([0-9\.]+, [0-9\.]+, True\)"
123113 )
124114 self .assertRegex (
125- zcat .getCatalogPlan (),
126- r"(?ms).*'numbers':\s*\([0-9\.]+, [0-9\.]+, True\)"
127- )
128- self .assertEqual (
129- cat .getCatalogPlan (query2 ).plan (), ["numbers" , "num" , "date" ]
115+ zcat .getCatalogPlan (), r"(?ms).*'numbers':\s*\([0-9\.]+, [0-9\.]+, True\)"
130116 )
117+ self .assertEqual (cat .getCatalogPlan (query2 ).plan (), ["numbers" , "num" , "date" ])
131118
132119 # search again doesn't change the index order
133120 self .assertEqual ([b .getPath () for b in zcat .search (query1 )], ["2" ])
134- self .assertEqual (
135- cat .getCatalogPlan (query2 ).plan (), ["numbers" , "num" , "date" ]
136- )
121+ self .assertEqual (cat .getCatalogPlan (query2 ).plan (), ["numbers" , "num" , "date" ])
137122
138123 def test_not_query (self ):
139124 # not query is generally slower, force this behavior for testing
140125 class SlowNotFieldIndex (FieldIndex ):
141126 def query_index (self , record , resultset = None ):
142- if getattr (record , ' not' , None ):
127+ if getattr (record , " not" , None ):
143128 time .sleep (0.1 )
144- return super (SlowNotFieldIndex , self ).query_index (
145- record , resultset )
129+ return super (SlowNotFieldIndex , self ).query_index (record , resultset )
146130
147131 zcat = ZCatalog ("catalog" )
148132 cat = zcat ._catalog
149- cat .addIndex (
150- 'num1' , SlowNotFieldIndex ('num1' , extra = {"indexed_attrs" : "num" }))
151- cat .addIndex (
152- 'num2' , SlowNotFieldIndex ('num2' , extra = {"indexed_attrs" : "num" }))
133+ cat .addIndex ("num1" , SlowNotFieldIndex ("num1" , extra = {"indexed_attrs" : "num" }))
134+ cat .addIndex ("num2" , SlowNotFieldIndex ("num2" , extra = {"indexed_attrs" : "num" }))
153135 for i in range (100 ):
154136 obj = Dummy (i )
155137 zcat .catalog_object (obj , str (i ))
156138
157139 query1 = {"num1" : {"not" : 2 }, "num2" : 3 }
158- query2 = {"num1" : 2 , "num2" : {' not' : 5 }}
140+ query2 = {"num1" : 2 , "num2" : {" not" : 5 }}
159141
160142 # without a plan index are orderd alphabetically by default
161143 for query in [query1 , query2 ]:
162144 self .assertEqual (zcat ._catalog .getCatalogPlan (query ).plan (), None )
163- self .assertEqual (
164- cat ._sorted_search_indexes (query ),
165- ["num1" , "num2" ]
166- )
145+ self .assertEqual (cat ._sorted_search_indexes (query ), ["num1" , "num2" ])
167146
168- self .assertEqual ([b .getPath () for b in zcat .search (query1 )], ['3' ])
169- self .assertEqual ([b .getPath () for b in zcat .search (query2 )], ['2' ])
147+ self .assertEqual ([b .getPath () for b in zcat .search (query1 )], ["3" ])
148+ self .assertEqual ([b .getPath () for b in zcat .search (query2 )], ["2" ])
170149 # although there are the same fields, the plans are different, and the
171150 # slower `not` query put the field as second in the plan
172151 self .assertEqual (cat .getCatalogPlan (query1 ).plan (), ["num2" , "num1" ])
173152 self .assertEqual (cat .getCatalogPlan (query2 ).plan (), ["num1" , "num2" ])
174153
175154 # search again doesn't change the order
176- self .assertEqual ([b .getPath () for b in zcat .search (query1 )], ['3' ])
177- self .assertEqual ([b .getPath () for b in zcat .search (query2 )], ['2' ])
155+ self .assertEqual ([b .getPath () for b in zcat .search (query1 )], ["3" ])
156+ self .assertEqual ([b .getPath () for b in zcat .search (query2 )], ["2" ])
178157 self .assertEqual (cat .getCatalogPlan (query1 ).plan (), ["num2" , "num1" ])
179158 self .assertEqual (cat .getCatalogPlan (query2 ).plan (), ["num1" , "num2" ])
0 commit comments