Skip to content

Commit cf8098c

Browse files
authored
fix: fix config tests (#450)
1 parent a501b75 commit cf8098c

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

tests/unit/codegen/shared/configs/test_constants.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
CODEGEN_REPO_ROOT,
66
CONFIG_FILENAME,
77
CONFIG_PATH,
8-
ENV_FILENAME,
9-
ENV_PATH,
108
)
119

1210

@@ -22,9 +20,3 @@ def test_config_path_construction():
2220
assert str(CONFIG_PATH).endswith(f"{CODEGEN_DIR_NAME}/{CONFIG_FILENAME}")
2321
assert CONFIG_PATH.exists()
2422
assert CONFIG_PATH.is_file()
25-
26-
27-
def test_env_path_construction():
28-
expected_path = CODEGEN_REPO_ROOT / "src" / "codegen" / ENV_FILENAME
29-
assert ENV_PATH == expected_path
30-
assert str(ENV_PATH).endswith(f"src/codegen/{ENV_FILENAME}")

tests/unit/codegen/shared/configs/test_models.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,50 @@
11
import json
2-
from pathlib import Path
32
from unittest.mock import mock_open, patch
43

54
import pytest
65
import toml
76

8-
from codegen.shared.configs.models.feature_flags import CodebaseFeatureFlags, Config, FeatureFlagsConfig, RepositoryConfig
7+
from codegen.shared.configs.models.feature_flags import CodebaseFeatureFlags, FeatureFlagsConfig
8+
from codegen.shared.configs.models.repository import RepositoryConfig
9+
from codegen.shared.configs.models.session import SessionConfig
910

1011

1112
@pytest.fixture
12-
def sample_config():
13+
def sample_config(tmpdir):
1314
codebase_flags = CodebaseFeatureFlags(debug=True, verify_graph=False)
14-
return Config(repository=RepositoryConfig(organization_name="test-org", repo_name="test-repo"), feature_flags=FeatureFlagsConfig(codebase=codebase_flags))
15+
return SessionConfig(file_path=f"{tmpdir}/test_config.toml", repository=RepositoryConfig(full_name="test-org", repo_name="test-repo"), feature_flags=FeatureFlagsConfig(codebase=codebase_flags))
1516

1617

17-
def test_config_initialization():
18-
config = Config()
18+
def test_config_initialization(tmpdir):
19+
config = SessionConfig(file_path=f"{tmpdir}/test_config.toml")
1920
assert config.repository is not None
2021
assert config.feature_flags is not None
2122
assert config.secrets is not None
2223

2324

24-
def test_config_with_values():
25-
config = Config(repository={"organization_name": "test-org", "repo_name": "test-repo"})
26-
assert config.repository.organization_name == "test-org"
25+
def test_config_with_values(tmpdir):
26+
config = SessionConfig(file_path=f"{tmpdir}/test_config.toml", repository={"full_name": "test-org", "repo_name": "test-repo"})
27+
assert config.repository.full_name == "test-org"
2728
assert config.repository.repo_name == "test-repo"
2829

2930

3031
@patch("builtins.open", new_callable=mock_open)
3132
@patch("pathlib.Path.mkdir")
3233
def test_save_config(mock_mkdir, mock_file, sample_config):
33-
sample_config.save(Path("test_config.toml"))
34+
sample_config.save()
3435

3536
mock_mkdir.assert_called_once_with(parents=True, exist_ok=True)
36-
mock_file.assert_called_once_with(Path("test_config.toml"), "w")
37+
mock_file.assert_called_once_with(sample_config.file_path, "w")
3738

3839
# Verify the content being written
3940
written_data = mock_file().write.call_args[0][0]
4041
parsed_data = toml.loads(written_data)
41-
assert parsed_data["repository"]["organization_name"] == "test-org"
42+
assert parsed_data["repository"]["full_name"] == "test-org"
4243

4344

4445
def test_get_config_value(sample_config):
4546
# Test getting a simple value
46-
assert json.loads(sample_config.get("repository.organization_name")) == "test-org"
47+
assert json.loads(sample_config.get("repository.full_name")) == "test-org"
4748

4849
# Test getting a nested value
4950
assert json.loads(sample_config.get("feature_flags.codebase.debug")) is True
@@ -56,8 +57,8 @@ def test_set_config_value(sample_config):
5657
# Instead of mocking save, we'll mock the open function used within save
5758
with patch("builtins.open", new_callable=mock_open) as mock_file:
5859
# Test setting a simple string value
59-
sample_config.set("repository.organization_name", "new-org")
60-
assert sample_config.repository.organization_name == "new-org"
60+
sample_config.set("repository.full_name", "new-org")
61+
assert sample_config.repository.full_name == "new-org"
6162

6263
# Test setting a boolean value
6364
sample_config.set("feature_flags.codebase.debug", "false")
@@ -82,7 +83,7 @@ def test_config_str_representation(sample_config):
8283
assert isinstance(config_str, str)
8384
# Verify it's valid JSON
8485
parsed = json.loads(config_str)
85-
assert parsed["repository"]["organization_name"] == "test-org"
86+
assert parsed["repository"]["full_name"] == "test-org"
8687

8788

8889
def test_set_config_new_override_key(sample_config):

0 commit comments

Comments
 (0)