|
3 | 3 | # https://opensource.org/licenses/MIT. |
4 | 4 |
|
5 | 5 | import json |
| 6 | +import os |
6 | 7 | import unittest |
7 | 8 |
|
8 | 9 | import fsspec |
@@ -83,6 +84,40 @@ def test_normalize_yaml_uri(self): |
83 | 84 | f.write(yaml.dump(config)) |
84 | 85 | self.assertEqual(config, normalize_config(uri)) |
85 | 86 |
|
| 87 | + def test_interpolate_env_vars_json(self): |
| 88 | + uri = "memory://config.json" |
| 89 | + config = { |
| 90 | + "slice_storage_options": { |
| 91 | + "key": "${_TEST_S3_KEY}", |
| 92 | + "secret": "$_TEST_S3_SECRET", |
| 93 | + } |
| 94 | + } |
| 95 | + with fsspec.open(uri, "wt") as f: |
| 96 | + f.write(json.dumps(config)) |
| 97 | + os.environ["_TEST_S3_KEY"] = "abc" |
| 98 | + os.environ["_TEST_S3_SECRET"] = "123" |
| 99 | + self.assertEqual( |
| 100 | + {"slice_storage_options": {"key": "abc", "secret": "123"}}, |
| 101 | + normalize_config(uri), |
| 102 | + ) |
| 103 | + |
| 104 | + def test_interpolate_env_vars_yaml(self): |
| 105 | + uri = "memory://config.yaml" |
| 106 | + config = { |
| 107 | + "slice_storage_options": { |
| 108 | + "key": "${_TEST_S3_KEY}", |
| 109 | + "secret": "$_TEST_S3_SECRET", |
| 110 | + } |
| 111 | + } |
| 112 | + with fsspec.open(uri, "w") as f: |
| 113 | + f.write(yaml.dump(config)) |
| 114 | + os.environ["_TEST_S3_KEY"] = "abc" |
| 115 | + os.environ["_TEST_S3_SECRET"] = "123" |
| 116 | + self.assertEqual( |
| 117 | + {"slice_storage_options": {"key": "abc", "secret": 123}}, |
| 118 | + normalize_config(uri), |
| 119 | + ) |
| 120 | + |
86 | 121 | def test_normalize_file_obj(self): |
87 | 122 | file_obj = FileObj("memory://config.yaml") |
88 | 123 | config = {"version": 1, "zarr_version": 2} |
@@ -233,6 +268,8 @@ def test_exclude_from_config(self): |
233 | 268 | with exclude_from_config({"a": 1, "b": 2}, "b", "a") as config: |
234 | 269 | self.assertEqual({}, config) |
235 | 270 |
|
| 271 | + |
| 272 | +class ConfigSchemaTest(unittest.TestCase): |
236 | 273 | def test_get_config_schema(self): |
237 | 274 | schema = get_config_schema() |
238 | 275 | self.assertIn("properties", schema) |
|
0 commit comments