Skip to content

Commit

Permalink
modify tests to access Configuration data dict
Browse files Browse the repository at this point in the history
  • Loading branch information
similato87 committed Aug 10, 2024
1 parent 5eab6a4 commit 94505c5
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions tests/test_project_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@


def test_config_load():
# write example config to a file
# Write example config to a file
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
f.write(example_config)

# load the config from the file
# Load the config from the file
config = Config.from_toml(f.name)

assert config.api_config.OPENAI_API_KEY == "..."
assert config.api_config.ANTHROPIC_API_KEY == "..."
assert config.model_config.model_name == "gpt-4o"
assert config.model_config.temperature == 0.1
assert config.improve_config.is_linting is False
assert config.improve_config.is_file_selection is True
assert config.api_config["OPENAI_API_KEY"] == "..."
assert config.api_config["ANTHROPIC_API_KEY"] == "..."
assert config.model_config["model_name"] == "gpt-4o"
assert config.model_config["temperature"] == 0.1
assert config.improve_config["is_linting"] is False
assert config.improve_config["is_file_selection"] is True
assert config.to_dict()
assert config.to_toml(f.name, save=False)

# check that write+read is idempotent
# Check that write+read is idempotent
assert Config.from_toml(f.name) == config


Expand All @@ -40,33 +40,31 @@ def test_config_defaults():


def test_config_from_dict():
d = {"improve": {"is_linting": "..."}} # minimal example
d = {"improve": {"is_linting": "..."}} # Minimal example
config = Config.from_dict(d)
assert config.improve_config
assert config.improve_config.is_linting == "..."
assert config.improve_config["is_linting"] == "..."
config_dict = config.to_dict()

# check that the config dict matches the input dict exactly (no keys/defaults added)
# Check that the config dict matches the input dict exactly (no keys/defaults added)
assert config_dict == d


def test_config_load_partial():
# Loads a partial config, and checks that the rest is not set (i.e. None)
example_config = """
# Loads a partial config, and checks that the rest is not set (i.e., None)
partial_config = """
[improve]
is_linting = "..."
""".strip()
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
f.write(example_config)
f.write(partial_config)

config = Config.from_toml(f.name)
assert config.improve_config
assert config.improve_config.is_linting == "..."
assert config.improve_config["is_linting"] == "..."
assert config.to_dict()
toml_str = config.to_toml(f.name, save=False)
assert toml_str == example_config
assert toml_str.strip() == partial_config

# check that write+read is idempotent
# Check that write+read is idempotent
assert Config.from_toml(f.name) == config


Expand Down

0 comments on commit 94505c5

Please sign in to comment.