Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up config when database is disabled #578

Merged
merged 5 commits into from Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions pyiron_base/state/settings.py
Expand Up @@ -281,6 +281,21 @@ def _validate_viewer_configuration(config: Dict) -> None:
# I don't actually understand the constraint, I am just making it *explicit* as I refactor. -Liam
raise ValueError("Got sql_view arguments, but sql_type is not Postgres")

@staticmethod
def _validate_no_database_configuration(config: Dict) -> None:
if "disable_database" in config.keys() and config["disable_database"]:
if config["project_check_enabled"]:
raise ValueError(
"When the database is disabled 'disable_database=True' the project " +
"check cannot be enabled, so you have to set 'project_check_enabled=False'."
)
if len(config["project_paths"]) > 0:
raise ValueError(
"When the database is disabled 'disable_database=True' the project " +
"paths list should be empty 'project_paths=[]'. Currently it is: " +
str(config["project_paths"])
)

def _get_config_from_environment(self) -> Union[Dict, None]:
config = {}
for k, v in os.environ.items():
Expand Down Expand Up @@ -319,6 +334,7 @@ def _update_from_dict(self, config: Dict, map_: Union[None, Dict] = None) -> Non
"""
self._validate_sql_configuration(config=config)
self._validate_viewer_configuration(config=config)
self._validate_no_database_configuration(config=config)

for key, value in config.items():
key = key if map_ is None else map_[key]
Expand Down
14 changes: 14 additions & 0 deletions tests/state/test_settings.py
Expand Up @@ -129,6 +129,20 @@ def test_validate_viewer_configuration_completeness(self):
with self.assertRaises(ValueError):
s._validate_sql_configuration({"sql_type": "not_a_valid_type"})

def test_validate_no_database_configuration(self):
with self.assertRaises(ValueError):
s._validate_no_database_configuration({
"disable_database": True,
"project_check_enabled": True,
"project_paths": [],
})
with self.assertRaises(ValueError):
s._validate_no_database_configuration({
"disable_database": True,
"project_check_enabled": False,
"project_paths": ["/my/path/a"],
})

def test_get_config_from_environment(self):
os.environ["PYIRONFOO"] = "foo"
os.environ["PYIRONSQLFILE"] = "bar"
Expand Down