mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 16:25:00 +00:00
refactor: parameterize test_yaml_config_file_loading with yml, yaml, and mixed scenarios
This commit is contained in:
parent
90642fcf14
commit
cc2e6383c3
1 changed files with 49 additions and 12 deletions
|
@ -6,6 +6,7 @@ from io import StringIO
|
|||
from pathlib import Path
|
||||
from unittest import TestCase
|
||||
from unittest.mock import MagicMock, patch
|
||||
import pytest
|
||||
|
||||
import git
|
||||
from prompt_toolkit.input import DummyInput
|
||||
|
@ -405,8 +406,15 @@ class TestMain(TestCase):
|
|||
self.assertRegex(relevant_output, r"AIDER_DARK_MODE:\s+on")
|
||||
self.assertRegex(relevant_output, r"dark_mode:\s+True")
|
||||
|
||||
@pytest.mark.parametrize(desc):
|
||||
def test_yaml_config_file_loading(self):
|
||||
@pytest.mark.parametrize(
|
||||
"scenario",
|
||||
[
|
||||
"yml_only", # Test with only .yml files
|
||||
"yaml_only", # Test with only .yaml files
|
||||
"both_formats", # Test with both .yml and .yaml files
|
||||
],
|
||||
)
|
||||
def test_yaml_config_file_loading(self, scenario):
|
||||
with GitTemporaryDirectory() as git_dir:
|
||||
git_dir = Path(git_dir)
|
||||
|
||||
|
@ -420,7 +428,7 @@ class TestMain(TestCase):
|
|||
cwd.mkdir()
|
||||
os.chdir(cwd)
|
||||
|
||||
# Create .aider.conf.yml files in different locations
|
||||
# Create config files in different locations based on scenario
|
||||
home_config_yml = fake_home / ".aider.conf.yml"
|
||||
home_config_yaml = fake_home / ".aider.conf.yaml"
|
||||
git_config_yml = git_dir / ".aider.conf.yml"
|
||||
|
@ -429,10 +437,26 @@ class TestMain(TestCase):
|
|||
cwd_config_yaml = cwd / ".aider.conf.yaml"
|
||||
named_config = git_dir / "named.aider.conf.yml"
|
||||
|
||||
cwd_config_yml.write_text("model: gpt-4-32k\nmap-tokens: 4096\n")
|
||||
git_config_yml.write_text("model: gpt-4\nmap-tokens: 2048\n")
|
||||
home_config_yml.write_text("model: gpt-3.5-turbo\nmap-tokens: 1024\n")
|
||||
named_config.write_text("model: gpt-4-1106-preview\nmap-tokens: 8192\n")
|
||||
# Create files based on the scenario
|
||||
if scenario == "yml_only":
|
||||
cwd_config_yml.write_text("model: gpt-4-32k\nmap-tokens: 4096\n")
|
||||
git_config_yml.write_text("model: gpt-4\nmap-tokens: 2048\n")
|
||||
home_config_yml.write_text("model: gpt-3.5-turbo\nmap-tokens: 1024\n")
|
||||
named_config.write_text("model: gpt-4-1106-preview\nmap-tokens: 8192\n")
|
||||
elif scenario == "yaml_only":
|
||||
cwd_config_yaml.write_text("model: gpt-4-32k\nmap-tokens: 4096\n")
|
||||
git_config_yaml.write_text("model: gpt-4\nmap-tokens: 2048\n")
|
||||
home_config_yaml.write_text("model: gpt-3.5-turbo\nmap-tokens: 1024\n")
|
||||
named_config.write_text("model: gpt-4-1106-preview\nmap-tokens: 8192\n")
|
||||
else: # both_formats
|
||||
# Create both formats, with .yaml taking precedence in each directory
|
||||
cwd_config_yml.write_text("model: gpt-4-32k-yml\nmap-tokens: 4096\n")
|
||||
cwd_config_yaml.write_text("model: gpt-4-32k\nmap-tokens: 4096\n")
|
||||
git_config_yml.write_text("model: gpt-4-yml\nmap-tokens: 2048\n")
|
||||
git_config_yaml.write_text("model: gpt-4\nmap-tokens: 2048\n")
|
||||
home_config_yml.write_text("model: gpt-3.5-turbo-yml\nmap-tokens: 1024\n")
|
||||
home_config_yaml.write_text("model: gpt-3.5-turbo\nmap-tokens: 1024\n")
|
||||
named_config.write_text("model: gpt-4-1106-preview\nmap-tokens: 8192\n")
|
||||
|
||||
with (
|
||||
patch("pathlib.Path.home", return_value=fake_home),
|
||||
|
@ -451,20 +475,33 @@ class TestMain(TestCase):
|
|||
# Test loading from current working directory
|
||||
main(["--yes", "--exit"], input=DummyInput(), output=DummyOutput())
|
||||
_, kwargs = MockCoder.call_args
|
||||
print("kwargs:", kwargs) # Add this line for debugging
|
||||
self.assertIn("main_model", kwargs, "main_model key not found in kwargs")
|
||||
self.assertEqual(kwargs["main_model"].name, "gpt-4-32k")
|
||||
self.assertEqual(kwargs["map_tokens"], 4096)
|
||||
|
||||
# Test loading from git root
|
||||
cwd_config_yml.unlink()
|
||||
# Test loading from git root by removing cwd config files
|
||||
if scenario == "yml_only":
|
||||
cwd_config_yml.unlink()
|
||||
elif scenario == "yaml_only":
|
||||
cwd_config_yaml.unlink()
|
||||
else: # both_formats
|
||||
cwd_config_yml.unlink()
|
||||
cwd_config_yaml.unlink()
|
||||
|
||||
main(["--yes", "--exit"], input=DummyInput(), output=DummyOutput())
|
||||
_, kwargs = MockCoder.call_args
|
||||
self.assertEqual(kwargs["main_model"].name, "gpt-4")
|
||||
self.assertEqual(kwargs["map_tokens"], 2048)
|
||||
|
||||
# Test loading from home directory
|
||||
git_config_yml.unlink()
|
||||
# Test loading from home directory by removing git root config files
|
||||
if scenario == "yml_only":
|
||||
git_config_yml.unlink()
|
||||
elif scenario == "yaml_only":
|
||||
git_config_yaml.unlink()
|
||||
else: # both_formats
|
||||
git_config_yml.unlink()
|
||||
git_config_yaml.unlink()
|
||||
|
||||
main(["--yes", "--exit"], input=DummyInput(), output=DummyOutput())
|
||||
_, kwargs = MockCoder.call_args
|
||||
self.assertEqual(kwargs["main_model"].name, "gpt-3.5-turbo")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue