|
23 | 23 | _N_GROUPS = len(set(_GROUP_IDS)) |
24 | 24 | _PRODUCT_NAME = "foo_out" |
25 | 25 | _INIT_TYPES = ("filename", "asn", "models") |
| 26 | +_TEST_URI_SCHEME = "file://" |
26 | 27 |
|
27 | 28 |
|
28 | 29 | def _load_asn(filename): |
@@ -84,6 +85,14 @@ def _model_to_group_id(self, model): |
84 | 85 | raise NoGroupID(f"{model} missing group_id") |
85 | 86 |
|
86 | 87 |
|
| 88 | +class URIModelLibrary(ModelLibrary): |
| 89 | + def _datamodels_open(self, filename, **kwargs): |
| 90 | + return super()._datamodels_open(filename.removeprefix(_TEST_URI_SCHEME)) |
| 91 | + |
| 92 | + def _filename_to_group_id(self, filename): |
| 93 | + return super()._filename_to_group_id(filename.removeprefix(_TEST_URI_SCHEME)) |
| 94 | + |
| 95 | + |
87 | 96 | def _library_to_models(library): |
88 | 97 | """ |
89 | 98 | A few tests are easier to understand and write when |
@@ -145,6 +154,17 @@ def example_asn_path(example_models, tmp_path): |
145 | 154 | return asn_filename |
146 | 155 |
|
147 | 156 |
|
| 157 | +@pytest.fixture |
| 158 | +def example_uri_asn_path(example_asn_path): |
| 159 | + asn_dir = example_asn_path.parent |
| 160 | + asn_data = _load_asn(example_asn_path) |
| 161 | + for member in asn_data["products"][0]["members"]: |
| 162 | + member["expname"] = _TEST_URI_SCHEME + str(asn_dir / member["expname"]) |
| 163 | + asn_filename = asn_dir / "uri_asn.json" |
| 164 | + _write_asn(asn_data, asn_filename) |
| 165 | + return asn_filename |
| 166 | + |
| 167 | + |
148 | 168 | @pytest.fixture |
149 | 169 | def example_library(example_asn_path): |
150 | 170 | """ |
@@ -801,3 +821,16 @@ def test_get_filename(table_name, filename): |
801 | 821 | if table_name != "MISSING": |
802 | 822 | lib._asn["table_name"] = table_name |
803 | 823 | assert Step._get_filename(lib) == filename |
| 824 | + |
| 825 | + |
| 826 | +@pytest.mark.parametrize("loaded", [False, True]) |
| 827 | +def test_uri_member_paths(example_uri_asn_path, loaded): |
| 828 | + if loaded: |
| 829 | + asn = _load_asn(example_uri_asn_path) |
| 830 | + else: |
| 831 | + asn = example_uri_asn_path |
| 832 | + lib = URIModelLibrary(asn) |
| 833 | + with lib: |
| 834 | + for i, model in enumerate(lib): |
| 835 | + assert model |
| 836 | + lib.shelve(model, i, modify=False) |
0 commit comments