@@ -189,30 +189,36 @@ def test_setup_db_metadata_table_is_current(autoimport):
189
189
190
190
191
191
class TestQueryUsesIndexes :
192
+ def explain (self , autoimport , query ):
193
+ explanation = list (autoimport ._execute (query .explain (), ("abc" ,)))[0 ][- 1 ]
194
+ # the explanation text varies, on some sqlite version
195
+ explanation = explanation .replace ("TABLE " , "" )
196
+ return explanation
197
+
192
198
def test_search_by_name_uses_index (self , autoimport ):
193
- query = models .Name .search_by_name .select_star (). explain ()
199
+ query = models .Name .search_by_name .select_star ()
194
200
assert (
195
- list ( autoimport . _execute ( query , ( "abc" ,)))[ 0 ][ - 1 ]
201
+ self . explain ( autoimport , query )
196
202
== "SEARCH names USING INDEX names_name (name=?)"
197
203
)
198
204
199
205
def test_search_by_name_like_uses_index (self , autoimport ):
200
- query = models .Name .search_by_name_like .select_star (). explain ()
206
+ query = models .Name .search_by_name_like .select_star ()
201
207
assert (
202
- list ( autoimport . _execute ( query , ( "abc" ,)))[ 0 ][ - 1 ]
208
+ self . explain ( autoimport , query )
203
209
== "SEARCH names USING INDEX names_name_nocase (name>? AND name<?)"
204
210
)
205
211
206
212
def test_search_module_like_uses_index (self , autoimport ):
207
- query = models .Name .search_module_like .select_star (). explain ()
213
+ query = models .Name .search_module_like .select_star ()
208
214
assert (
209
- list ( autoimport . _execute ( query , ( "abc" ,)))[ 0 ][ - 1 ]
215
+ self . explain ( autoimport , query )
210
216
== "SEARCH names USING INDEX names_module_nocase (module>? AND module<?)"
211
217
)
212
218
213
219
def test_search_submodule_like_uses_index (self , autoimport ):
214
- query = models .Name .search_submodule_like .select_star (). explain ()
220
+ query = models .Name .search_submodule_like .select_star ()
215
221
assert (
216
- list ( autoimport . _execute ( query , ( "abc" ,)))[ 0 ][ - 1 ]
222
+ self . explain ( autoimport , query )
217
223
== "SCAN names" # FIXME: avoid full table scan
218
224
)
0 commit comments