88import pandas as pd
99import pytest
1010
11- from pandas_openscm .db import FeatherDataBackend , FeatherIndexBackend , OpenSCMDB
11+ from pandas_openscm .db import (
12+ CSVDataBackend ,
13+ CSVIndexBackend ,
14+ FeatherDataBackend ,
15+ FeatherIndexBackend ,
16+ OpenSCMDB ,
17+ netCDFDataBackend ,
18+ netCDFIndexBackend ,
19+ )
1220from pandas_openscm .testing import assert_frame_alike
1321
22+ pytest .importorskip ("filelock" )
23+
1424
1525@pytest .mark .parametrize (
16- "backend_data_for_class_method, backend_index_for_class_method " ,
26+ "backend_data, backend_index " ,
1727 (
1828 pytest .param (
1929 FeatherDataBackend (),
2030 FeatherIndexBackend (),
21- id = "provided" ,
31+ id = "feather" ,
32+ ),
33+ pytest .param (
34+ netCDFDataBackend (),
35+ netCDFIndexBackend (),
36+ id = "netCDF" ,
2237 ),
2338 pytest .param (
24- None ,
25- None ,
26- id = "guessed " ,
39+ CSVDataBackend () ,
40+ CSVIndexBackend () ,
41+ id = "csv " ,
2742 ),
2843 ),
2944)
30- def test_move_db (
31- backend_data_for_class_method ,
32- backend_index_for_class_method ,
45+ @pytest .mark .parametrize ("provide_backend_data_to_class_method" , (True , False ))
46+ @pytest .mark .parametrize ("provide_backend_index_to_class_method" , (True , False ))
47+ def test_move_db ( # noqa: PLR0913
48+ provide_backend_index_to_class_method ,
49+ provide_backend_data_to_class_method ,
50+ backend_data ,
51+ backend_index ,
3352 tmpdir ,
3453 setup_pandas_accessor ,
3554):
@@ -39,8 +58,8 @@ def test_move_db(
3958
4059 db = OpenSCMDB (
4160 db_dir = initial_db_dir ,
42- backend_data = FeatherDataBackend () ,
43- backend_index = FeatherIndexBackend () ,
61+ backend_data = backend_data ,
62+ backend_index = backend_index ,
4463 )
4564
4665 df_timeseries_like = pd .DataFrame (
@@ -63,19 +82,24 @@ def test_move_db(
6382 tar_archive = db .to_gzipped_tar_archive (tar_archive )
6483
6584 # Expand elsewhere
85+ from_gzipped_tar_archive_kwargs = {}
86+ if provide_backend_data_to_class_method :
87+ from_gzipped_tar_archive_kwargs ["backend_data" ] = backend_data
88+
89+ if provide_backend_index_to_class_method :
90+ from_gzipped_tar_archive_kwargs ["backend_index" ] = backend_index
91+
6692 db_other = OpenSCMDB .from_gzipped_tar_archive (
67- tar_archive ,
68- db_dir = other_db_dir ,
69- backend_data = backend_data_for_class_method ,
70- backend_index = backend_index_for_class_method ,
93+ tar_archive , db_dir = other_db_dir , ** from_gzipped_tar_archive_kwargs
7194 )
7295
7396 # Delete the original
7497 db .delete ()
7598
76- assert_frame_alike (df_timeseries_like , db_other .load ())
99+ assert_frame_alike (df_timeseries_like , db_other .load (out_columns_type = int ))
77100
78101 locator = pd .Index (["scenario_b" ], name = "scenario" )
79102 assert_frame_alike (
80- df_timeseries_like .openscm .mi_loc (locator ), db_other .load (locator )
103+ df_timeseries_like .openscm .mi_loc (locator ),
104+ db_other .load (locator , out_columns_type = int ),
81105 )
0 commit comments