|
4 | 4 | import uuid |
5 | 5 | from unittest import mock |
6 | 6 | import os |
| 7 | +import yaml |
7 | 8 |
|
8 | 9 | from deltacat.catalog import ( |
9 | 10 | CatalogProperties, |
@@ -147,11 +148,54 @@ def test_init_with_default_catalog_name(self, reset_catalogs): |
147 | 148 | force=True, |
148 | 149 | ) |
149 | 150 |
|
150 | | - # Get the default catalog and check it's catalog2 |
| 151 | + # Get the def ault catalog and check it's catalog2 |
151 | 152 | default_catalog = get_catalog() |
152 | 153 | assert default_catalog.impl == MockCatalogImpl |
153 | 154 | assert default_catalog.inner["kwargs"]["id"] == 2 |
154 | 155 |
|
| 156 | + def test_init_with_config_yaml(self, tmp_path, reset_catalogs): |
| 157 | + """ |
| 158 | + Test initializing Catalogs from a YAML config file. |
| 159 | + CatalogProperties will infer filesystem and storage, so we don't |
| 160 | + put actual Python objects in the YAML. |
| 161 | + - load_catalog_configs_from_yaml returns a dict[str, CatalogProperties], |
| 162 | + so we provide one entry keyed by a catalog name. |
| 163 | + - get_catalog() with no arguments should always return the *default* |
| 164 | + catalog, even if multiple catalogs are loaded. In this case we only |
| 165 | + provide one catalog ("test_catalog"), so it should automatically |
| 166 | + become the default. |
| 167 | + """ |
| 168 | + # YAML data compatible with CatalogProperties |
| 169 | + config_data = { |
| 170 | + "test-catalog": { |
| 171 | + "root": str(tmp_path), # path for catalog metadata/data |
| 172 | + "filesystem": None, # leave None; CatalogProperties will infer filesystem |
| 173 | + "storage": None, # leave None; CatalogProperties will infer storage |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + # Write the YAML config file |
| 178 | + config_path = tmp_path / "config.yaml" |
| 179 | + with open(config_path, "w") as f: |
| 180 | + yaml.dump(config_data, f) |
| 181 | + |
| 182 | + # Initialize from the YAML config |
| 183 | + init(config_path=str(config_path), force=True) |
| 184 | + |
| 185 | + # Retrieve the default catalog (returns CatalogProperties directly) |
| 186 | + catalog_props = get_catalog() # no args → default "test-catalog" |
| 187 | + |
| 188 | + # Should be a CatalogProperties instance |
| 189 | + assert isinstance(catalog_props, CatalogProperties) |
| 190 | + assert catalog_props.root == str(tmp_path) |
| 191 | + |
| 192 | + # filesystem and storage are inferred by CatalogProperties; check types |
| 193 | + import pyarrow.fs |
| 194 | + |
| 195 | + assert isinstance(catalog_props.filesystem, pyarrow.fs.FileSystem) |
| 196 | + # TODO: If storage has a default class, check its type here |
| 197 | + # assert isinstance(inner.storage, ExpectedStorageClass) |
| 198 | + |
155 | 199 | def test_put_catalog(self, reset_catalogs): |
156 | 200 | """Test adding a catalog after initialization.""" |
157 | 201 | # Initialize with a single catalog |
|
0 commit comments