11# ruff: noqa: E402
2+ import importlib
23import json
34import os .path
45import re
78import tarfile
89
910import pytest
11+ from verlib2 import Version
1012
1113pymongo = pytest .importorskip ("polars" , reason = "Skipping tests because polars is not installed" )
1214
@@ -29,15 +31,25 @@ def filenames(path: Path):
2931 return sorted ([item .name for item in path .iterdir ()])
3032
3133
32- def test_cfr_sys_export_success (cratedb , tmp_path , caplog ):
34+ @pytest .fixture (scope = "session" )
35+ def click_kwargs ():
36+ """
37+ Click 8.2 no longer understands `mix_stderr`.
38+ """
39+ kwargs = {}
40+ click_version = importlib .metadata .version ("click" )
41+ if Version (click_version ) < Version ("8.2" ):
42+ kwargs = {"mix_stderr" : False }
43+ return kwargs
44+
45+
46+ def test_cfr_sys_export_success (cratedb , click_kwargs , tmp_path , caplog ):
3347 """
3448 Verify `ctk cfr sys-export` works.
3549 """
3650
3751 # Invoke command.
38- runner = CliRunner (
39- env = {"CRATEDB_CLUSTER_URL" : cratedb .database .dburi , "CFR_TARGET" : str (tmp_path )}, mix_stderr = False
40- )
52+ runner = CliRunner (env = {"CRATEDB_CLUSTER_URL" : cratedb .database .dburi , "CFR_TARGET" : str (tmp_path )}, ** click_kwargs )
4153 result = runner .invoke (
4254 cli ,
4355 args = "--debug sys-export" ,
@@ -60,17 +72,15 @@ def test_cfr_sys_export_success(cratedb, tmp_path, caplog):
6072 assert len (data_files ) >= 10
6173
6274
63- def test_cfr_sys_export_to_archive_file (cratedb , tmp_path , caplog ):
75+ def test_cfr_sys_export_to_archive_file (cratedb , click_kwargs , tmp_path , caplog ):
6476 """
6577 Verify `ctk cfr sys-export some-file.tgz` works.
6678 """
6779
6880 target = os .path .join (tmp_path , "cluster-data.tgz" )
6981
7082 # Invoke command.
71- runner = CliRunner (
72- env = {"CRATEDB_CLUSTER_URL" : cratedb .database .dburi , "CFR_TARGET" : str (tmp_path )}, mix_stderr = False
73- )
83+ runner = CliRunner (env = {"CRATEDB_CLUSTER_URL" : cratedb .database .dburi , "CFR_TARGET" : str (tmp_path )}, ** click_kwargs )
7484 result = runner .invoke (
7585 cli ,
7686 args = f"--debug sys-export { target } " ,
@@ -100,13 +110,13 @@ def test_cfr_sys_export_to_archive_file(cratedb, tmp_path, caplog):
100110 assert len (data_files ) >= 10
101111
102112
103- def test_cfr_sys_export_failure (cratedb , tmp_path , caplog ):
113+ def test_cfr_sys_export_failure (cratedb , click_kwargs , tmp_path , caplog ):
104114 """
105115 Verify `ctk cfr sys-export` failure.
106116 """
107117
108118 # Invoke command.
109- runner = CliRunner (env = {"CRATEDB_CLUSTER_URL" : "crate://foo.bar/" , "CFR_TARGET" : str (tmp_path )}, mix_stderr = False )
119+ runner = CliRunner (env = {"CRATEDB_CLUSTER_URL" : "crate://foo.bar/" , "CFR_TARGET" : str (tmp_path )}, ** click_kwargs )
110120 result = runner .invoke (
111121 cli ,
112122 args = "--debug sys-export" ,
@@ -119,10 +129,8 @@ def test_cfr_sys_export_failure(cratedb, tmp_path, caplog):
119129 assert result .output == ""
120130
121131
122- def test_cfr_sys_export_ensure_table_name_is_quoted (cratedb , tmp_path , caplog ):
123- runner = CliRunner (
124- env = {"CRATEDB_CLUSTER_URL" : cratedb .database .dburi , "CFR_TARGET" : str (tmp_path )}, mix_stderr = False
125- )
132+ def test_cfr_sys_export_ensure_table_name_is_quoted (cratedb , click_kwargs , tmp_path , caplog ):
133+ runner = CliRunner (env = {"CRATEDB_CLUSTER_URL" : cratedb .database .dburi , "CFR_TARGET" : str (tmp_path )}, ** click_kwargs )
126134 result = runner .invoke (
127135 cli ,
128136 args = "--debug sys-export" ,
@@ -178,9 +186,7 @@ def test_cfr_sys_import_success(cratedb, tmp_path, caplog):
178186 shutil .copy (sys_operations_data , data_path )
179187
180188 # Invoke command.
181- runner = CliRunner (
182- env = {"CRATEDB_CLUSTER_URL" : cratedb .database .dburi , "CFR_SOURCE" : str (tmp_path )}, mix_stderr = False
183- )
189+ runner = CliRunner (env = {"CRATEDB_CLUSTER_URL" : cratedb .database .dburi , "CFR_SOURCE" : str (tmp_path )})
184190 result = runner .invoke (
185191 cli ,
186192 args = "--debug sys-import" ,
@@ -200,13 +206,13 @@ def test_cfr_sys_import_success(cratedb, tmp_path, caplog):
200206 assert cratedb .database .count_records ("sys-operations" ) == 1
201207
202208
203- def test_cfr_sys_import_failure (cratedb , tmp_path , caplog ):
209+ def test_cfr_sys_import_failure (cratedb , click_kwargs , tmp_path , caplog ):
204210 """
205211 Verify `ctk cfr sys-import` failure.
206212 """
207213
208214 # Invoke command.
209- runner = CliRunner (env = {"CRATEDB_CLUSTER_URL" : "crate://foo.bar/" , "CFR_SOURCE" : str (tmp_path )}, mix_stderr = False )
215+ runner = CliRunner (env = {"CRATEDB_CLUSTER_URL" : "crate://foo.bar/" , "CFR_SOURCE" : str (tmp_path )}, ** click_kwargs )
210216 result = runner .invoke (
211217 cli ,
212218 args = "--debug sys-import" ,
0 commit comments