Skip to content

Commit

Permalink
fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Leahh02 committed Nov 13, 2024
1 parent 216134e commit 0aa66e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 6 additions & 6 deletions beeflow/tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,16 +389,16 @@ def __init__(self, changes=None):
self._load_config()

for sec_name, opts in self.changes.items():
for opt_name, new_value in opts.items():
self.change_value(sec_name, opt_name, new_value)
for opt_name, new_value in opts.items():
self.change_value(sec_name, opt_name, new_value)

def _load_config(self):
"""Fake loading config."""
self.config = {
"DEFAULT": {
"bee_workdir": "$BEE_WORKDIR",
"workload_scheduler": "$WORKLOAD_SCHEDULER"
}
"DEFAULT": {
"bee_workdir": "$BEE_WORKDIR",
"workload_scheduler": "$WORKLOAD_SCHEDULER"
}
}

def change_value(self, sec_name, opt_name, new_value):
Expand Down
14 changes: 13 additions & 1 deletion beeflow/tests/test_config_driver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
from beeflow.tests.mocks import MockAlterConfig


# AlterConfig tests
def test_initialization_without_changes():
"""Test initialization without any changes."""
config = MockAlterConfig()
Expand All @@ -12,37 +14,46 @@ def test_initialization_without_changes():
}
assert config.changes == {}


def test_initialization_with_changes():
"""Test initialization with some predefined changes."""
changes = {"DEFAULT": {"bee_workdir": "/new/path"}}
config = MockAlterConfig(changes=changes)
assert config.config["DEFAULT"]["bee_workdir"] == "/new/path"
assert config.changes == changes


def test_change_value_success():
"""Test changing an existing config value."""
config = MockAlterConfig()
config.change_value("DEFAULT", "bee_workdir", "/new/path")
assert config.config["DEFAULT"]["bee_workdir"] == "/new/path"
assert config.changes == {"DEFAULT": {"bee_workdir": "/new/path"}}


def test_change_value_nonexistent_section():
"""Test changing a value in a nonexistent section raises an error."""
config = MockAlterConfig()
with pytest.raises(ValueError, match="Section NON_EXISTENT not found in the config."):
config.change_value("NON_EXISTENT", "some_option", "new_value")


def test_change_value_nonexistent_option():
"""Test changing a nonexistent option raises an error."""
config = MockAlterConfig()
with pytest.raises(ValueError, match="Option non_existent_option not found in section DEFAULT."):
with pytest.raises(
ValueError,
match="Option non_existent_option not found in section DEFAULT."
):
config.change_value("DEFAULT", "non_existent_option", "new_value")


def test_save():
"""Test the save function."""
config = MockAlterConfig()
assert config.save() == "Configuration saved."


def test_change_value_multiple_times():
"""Test changing a config value multiple times and tracking changes."""
config = MockAlterConfig()
Expand All @@ -51,6 +62,7 @@ def test_change_value_multiple_times():
assert config.config["DEFAULT"]["bee_workdir"] == "/path/two"
assert config.changes == {"DEFAULT": {"bee_workdir": "/path/two"}}


def test_change_value_updates_changes_dict():
"""Test that changes dictionary is updated correctly after multiple changes."""
config = MockAlterConfig()
Expand Down

0 comments on commit 0aa66e4

Please sign in to comment.