Skip to content

Commit

Permalink
Add configuration synchronizing helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
YooSunYoung committed Aug 28, 2024
1 parent a49a1fd commit 51492a8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ background_ingestor \\
You can use a json file to configure options.
There is a template, ``resources/config.sample.json`` you can copy/paste to make your own configuration file.

```bash
cp resources/config.sample.json config.20240405.json
```
In order to update the configurations, you should update it the ``scicat_configuration`` module.

Then ``scicat_ingestor`` will automatically use the configuration file.
The template file can be synchronized automatically by ``synchronize_config`` command.

### Configuration Validator

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dynamic = ["version"]
scicat_ingestor = "scicat_online_ingestor:main"
background_ingestor = "scicat_offline_ingestor:main"
validate_ingestor_config = "scicat_configuration:validate_config_file"
synchronize_config = "scicat_configuration:synchronize_config_file"

[project.entry-points."scicat_ingestor.metadata_extractor"]
max = "numpy:max"
Expand Down
3 changes: 2 additions & 1 deletion tests/invalid_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"hash_file_extension": "b2b",
"ingestor_files_directory": "../ingestor",
"message_to_file": true,
"message_file_extension": "message.json"
"message_file_extension": "message.json",
"some_random_field": 0
}
}
}
27 changes: 19 additions & 8 deletions tests/test_scicat_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,27 @@ def template_config_file() -> Path:
return Path(__file__).parent / "../resources/config.sample.json"


def test_config_validator(template_config_file: Path) -> None:
_validate_config_file(OnlineIngestorConfig, template_config_file)
def test_template_config_file_synchronized(template_config_file: Path) -> None:
"""Template config file should have all the fields in the OnlineIngestorConfig
If this test fails, it means that the template config file is out of sync with the
OnlineIngestorConfig class.
In that case, use the command ``synchronize_config`` to update the template file.
```bash
synchronize_config
```
"""
import json

assert (
json.loads(template_config_file.read_text())
== OnlineIngestorConfig(config_file="").to_dict()
)


def test_config_validator_invalid_config_raises() -> None:
with pytest.raises(TypeError, match="(OnlineIngestorConfig.__init__)*(missing)"):
_validate_config_file(
OnlineIngestorConfig,
Path(__file__).parent / "invalid_config.json",
)
def test_config_validator(template_config_file: Path) -> None:
_validate_config_file(OnlineIngestorConfig, template_config_file)


def test_config_validator_unused_args_raises() -> None:
Expand Down

0 comments on commit 51492a8

Please sign in to comment.