@@ -262,6 +262,134 @@ test_that("qgis_configure() works OK if cache condition 'use_json_output' unmet"
262
262
263
263
264
264
265
+ test_that(" qgis_configure() works OK with qgisprocess.detect_newer_qgis option or envvar" , {
266
+ skip_if_not(has_qgis())
267
+ skip_if_not(is_windows() || is_macos())
268
+ version <- as.character(utils :: packageVersion(" qgisprocess" ))
269
+ cache_data_file <- file.path(
270
+ rappdirs :: user_cache_dir(" R-qgisprocess" ),
271
+ glue(" cache-{version}.rds" )
272
+ )
273
+ rlang :: local_interactive()
274
+ withr :: local_options(list (
275
+ qgisprocess.test_skip_path_availability_check = TRUE ,
276
+ qgisprocess.detect_newer_qgis = TRUE
277
+ ))
278
+ local_mocked_bindings(
279
+ qgis_detect_paths = function (... ) c(
280
+ " C:/Program Files/QGIS 3.30.0/bin/qgis_process-qgis-ltr.bat" ,
281
+ " C:/Program Files/QGIS 3.28.6/bin/qgis_process-qgis-ltr.bat"
282
+ )
283
+ )
284
+ withr :: defer(
285
+ saveRDS(
286
+ list (
287
+ path = qgis_path(),
288
+ version = qgis_version(),
289
+ algorithms = qgis_algorithms(),
290
+ plugins = qgis_plugins(),
291
+ use_json_output = qgis_using_json_output()
292
+ ),
293
+ cache_data_file
294
+ )
295
+ )
296
+
297
+ # answering 'yes' triggers reconfiguration with newer version
298
+ withr :: local_options(qgisprocess.test_try_new_qgis = " yes" )
299
+ saveRDS(
300
+ list (
301
+ path = " C:/Program Files/QGIS 3.28.6/bin/qgis_process-qgis-ltr.bat" ,
302
+ version = " 3.28.6-xxx" ,
303
+ algorithms = qgis_algorithms(),
304
+ plugins = qgis_plugins(),
305
+ use_json_output = qgis_using_json_output()
306
+ ),
307
+ cache_data_file
308
+ )
309
+ expect_message(
310
+ capture.output(qgis_configure(use_cached_data = TRUE ), type = " message" ),
311
+ " A newer QGIS installation seems to be"
312
+ )
313
+
314
+ # answering 'no' triggers another message
315
+ withr :: local_options(qgisprocess.test_try_new_qgis = " no" )
316
+ saveRDS(
317
+ list (
318
+ path = " C:/Program Files/QGIS 3.28.6/bin/qgis_process-qgis-ltr.bat" ,
319
+ version = " 3.28.6-xxx" ,
320
+ algorithms = qgis_algorithms(),
321
+ plugins = qgis_plugins(),
322
+ use_json_output = qgis_using_json_output()
323
+ ),
324
+ cache_data_file
325
+ )
326
+ expect_message(
327
+ capture.output(qgis_configure(use_cached_data = TRUE ), type = " message" ),
328
+ " if you don't want to autodetect QGIS version updates"
329
+ )
330
+
331
+ # with newest version in place: not offering to switch
332
+ withr :: local_options(qgisprocess.test_try_new_qgis = " yes" )
333
+ saveRDS(
334
+ list (
335
+ path = " C:/Program Files/QGIS 3.30.0/bin/qgis_process-qgis-ltr.bat" ,
336
+ version = " 3.30.0-xxx" ,
337
+ algorithms = qgis_algorithms(),
338
+ plugins = qgis_plugins(),
339
+ use_json_output = qgis_using_json_output()
340
+ ),
341
+ cache_data_file
342
+ )
343
+ expect_no_message(
344
+ capture.output(qgis_configure(use_cached_data = TRUE ), type = " message" ),
345
+ message = " A newer QGIS installation seems to be"
346
+ )
347
+
348
+ # without the option: not offering to switch
349
+ withr :: local_options(list (
350
+ qgisprocess.detect_newer_qgis = NULL ,
351
+ qgisprocess.test_try_new_qgis = " yes"
352
+ ))
353
+ saveRDS(
354
+ list (
355
+ path = " C:/Program Files/QGIS 3.28.6/bin/qgis_process-qgis-ltr.bat" ,
356
+ version = " 3.28.6-xxx" ,
357
+ algorithms = qgis_algorithms(),
358
+ plugins = qgis_plugins(),
359
+ use_json_output = qgis_using_json_output()
360
+ ),
361
+ cache_data_file
362
+ )
363
+ expect_no_message(
364
+ capture.output(qgis_configure(use_cached_data = TRUE ), type = " message" ),
365
+ message = " A newer QGIS installation seems to be"
366
+ )
367
+
368
+ # when not interactive: not offering to switch
369
+ rlang :: local_interactive(value = FALSE )
370
+ withr :: local_options(list (
371
+ qgisprocess.detect_newer_qgis = TRUE ,
372
+ qgisprocess.test_try_new_qgis = " yes"
373
+ ))
374
+ saveRDS(
375
+ list (
376
+ path = " C:/Program Files/QGIS 3.28.6/bin/qgis_process-qgis-ltr.bat" ,
377
+ version = " 3.28.6-xxx" ,
378
+ algorithms = qgis_algorithms(),
379
+ plugins = qgis_plugins(),
380
+ use_json_output = qgis_using_json_output()
381
+ ),
382
+ cache_data_file
383
+ )
384
+ expect_no_message(
385
+ capture.output(qgis_configure(use_cached_data = TRUE ), type = " message" ),
386
+ message = " A newer QGIS installation seems to be"
387
+ )
388
+ })
389
+
390
+
391
+
392
+
265
393
test_that(" abort_query_version() works" , {
266
394
lines <- c(" aa" , " bb" )
267
395
expect_error(
0 commit comments