mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 16:25:00 +00:00
refactor: simplify test_yaml_config_file_loading by removing redundant test cases
This commit is contained in:
parent
24ae592d80
commit
90642fcf14
1 changed files with 7 additions and 58 deletions
|
@ -405,6 +405,7 @@ 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):
|
||||
with GitTemporaryDirectory() as git_dir:
|
||||
git_dir = Path(git_dir)
|
||||
|
@ -419,7 +420,7 @@ class TestMain(TestCase):
|
|||
cwd.mkdir()
|
||||
os.chdir(cwd)
|
||||
|
||||
# Create .aider.conf.yml and .aider.conf.yaml files in different locations
|
||||
# Create .aider.conf.yml files in different locations
|
||||
home_config_yml = fake_home / ".aider.conf.yml"
|
||||
home_config_yaml = fake_home / ".aider.conf.yaml"
|
||||
git_config_yml = git_dir / ".aider.conf.yml"
|
||||
|
@ -428,20 +429,16 @@ class TestMain(TestCase):
|
|||
cwd_config_yaml = cwd / ".aider.conf.yaml"
|
||||
named_config = git_dir / "named.aider.conf.yml"
|
||||
|
||||
# Create all config files with appropriate content
|
||||
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")
|
||||
cwd_config_yaml.write_text("model: gpt-4-32k-yaml\nmap-tokens: 4096\n")
|
||||
git_config_yaml.write_text("model: gpt-4-yaml\nmap-tokens: 2048\n")
|
||||
home_config_yaml.write_text("model: gpt-3.5-turbo-yaml\nmap-tokens: 1024\n")
|
||||
|
||||
with (
|
||||
patch("pathlib.Path.home", return_value=fake_home),
|
||||
patch("aider.coders.Coder.create") as MockCoder,
|
||||
):
|
||||
# 1. Test loading from specified config file
|
||||
# Test loading from specified config file
|
||||
main(
|
||||
["--yes", "--exit", "--config", str(named_config)],
|
||||
input=DummyInput(),
|
||||
|
@ -451,76 +448,28 @@ class TestMain(TestCase):
|
|||
self.assertEqual(kwargs["main_model"].name, "gpt-4-1106-preview")
|
||||
self.assertEqual(kwargs["map_tokens"], 8192)
|
||||
|
||||
# 2. Test with just .yml files (cwd -> git_root -> home)
|
||||
# Remove all .yaml files first
|
||||
cwd_config_yaml.unlink()
|
||||
git_config_yaml.unlink()
|
||||
home_config_yaml.unlink()
|
||||
|
||||
# Test loading from current working directory (.yml)
|
||||
# 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 (.yml)
|
||||
# Test loading from git root
|
||||
cwd_config_yml.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 (.yml)
|
||||
# Test loading from home directory
|
||||
git_config_yml.unlink()
|
||||
main(["--yes", "--exit"], input=DummyInput(), output=DummyOutput())
|
||||
_, kwargs = MockCoder.call_args
|
||||
self.assertEqual(kwargs["main_model"].name, "gpt-3.5-turbo")
|
||||
self.assertEqual(kwargs["map_tokens"], 1024)
|
||||
|
||||
# 3. Test with just .yaml files (cwd -> git_root -> home)
|
||||
# Remove all .yml files and recreate .yaml files
|
||||
home_config_yml.unlink()
|
||||
cwd_config_yaml.write_text("model: gpt-4-32k-yaml\nmap-tokens: 4096\n")
|
||||
git_config_yaml.write_text("model: gpt-4-yaml\nmap-tokens: 2048\n")
|
||||
home_config_yaml.write_text("model: gpt-3.5-turbo-yaml\nmap-tokens: 1024\n")
|
||||
|
||||
# Test loading from .yaml in cwd
|
||||
main(["--yes", "--exit"], input=DummyInput(), output=DummyOutput())
|
||||
_, kwargs = MockCoder.call_args
|
||||
self.assertEqual(kwargs["main_model"].name, "gpt-4-32k-yaml")
|
||||
self.assertEqual(kwargs["map_tokens"], 4096)
|
||||
|
||||
# Test loading from .yaml in git root
|
||||
cwd_config_yaml.unlink()
|
||||
main(["--yes", "--exit"], input=DummyInput(), output=DummyOutput())
|
||||
_, kwargs = MockCoder.call_args
|
||||
self.assertEqual(kwargs["main_model"].name, "gpt-4-yaml")
|
||||
self.assertEqual(kwargs["map_tokens"], 2048)
|
||||
|
||||
# Test loading from .yaml in home
|
||||
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-yaml")
|
||||
self.assertEqual(kwargs["map_tokens"], 1024)
|
||||
|
||||
# 4. Test with both .yml and .yaml present, .yml preferred and warning printed
|
||||
# Recreate all config files
|
||||
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")
|
||||
cwd_config_yaml.write_text("model: gpt-4-32k-yaml\nmap-tokens: 4096\n")
|
||||
git_config_yaml.write_text("model: gpt-4-yaml\nmap-tokens: 2048\n")
|
||||
home_config_yaml.write_text("model: gpt-3.5-turbo-yaml\nmap-tokens: 1024\n")
|
||||
|
||||
with patch("builtins.print") as mock_print:
|
||||
main(["--yes", "--exit"], input=DummyInput(), output=DummyOutput())
|
||||
_, kwargs = MockCoder.call_args
|
||||
self.assertEqual(kwargs["main_model"].name, "gpt-4-32k")
|
||||
self.assertEqual(kwargs["map_tokens"], 4096)
|
||||
mock_print.assert_any_call("Warning: Both .aider.conf.yml and .aider.conf.yaml found in the same directory. Using .aider.conf.yml.")
|
||||
|
||||
def test_map_tokens_option(self):
|
||||
with GitTemporaryDirectory():
|
||||
with patch("aider.coders.base_coder.RepoMap") as MockRepoMap:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue