mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-27 15:55:00 +00:00
Fix to test so that it covers all scenarios
This commit is contained in:
parent
cc2e6383c3
commit
d67594ece3
1 changed files with 92 additions and 93 deletions
|
@ -6,7 +6,6 @@ from io import StringIO
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
import pytest
|
|
||||||
|
|
||||||
import git
|
import git
|
||||||
from prompt_toolkit.input import DummyInput
|
from prompt_toolkit.input import DummyInput
|
||||||
|
@ -406,106 +405,106 @@ class TestMain(TestCase):
|
||||||
self.assertRegex(relevant_output, r"AIDER_DARK_MODE:\s+on")
|
self.assertRegex(relevant_output, r"AIDER_DARK_MODE:\s+on")
|
||||||
self.assertRegex(relevant_output, r"dark_mode:\s+True")
|
self.assertRegex(relevant_output, r"dark_mode:\s+True")
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
def test_yaml_config_file_loading(self):
|
||||||
"scenario",
|
scenarios = [
|
||||||
[
|
"yml_only", # Test with only .yml files
|
||||||
"yml_only", # Test with only .yml files
|
"yaml_only", # Test with only .yaml files
|
||||||
"yaml_only", # Test with only .yaml files
|
"both_formats", # Test with both .yml and .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)
|
|
||||||
|
|
||||||
# Create fake home directory
|
for scenario in scenarios:
|
||||||
fake_home = git_dir / "fake_home"
|
with self.subTest(scenario=scenario):
|
||||||
fake_home.mkdir()
|
with GitTemporaryDirectory() as git_dir:
|
||||||
os.environ["HOME"] = str(fake_home)
|
git_dir = Path(git_dir)
|
||||||
|
|
||||||
# Create subdirectory as current working directory
|
# Create fake home directory
|
||||||
cwd = git_dir / "subdir"
|
fake_home = git_dir / "fake_home"
|
||||||
cwd.mkdir()
|
fake_home.mkdir()
|
||||||
os.chdir(cwd)
|
os.environ["HOME"] = str(fake_home)
|
||||||
|
|
||||||
# Create config files in different locations based on scenario
|
# Create subdirectory as current working directory
|
||||||
home_config_yml = fake_home / ".aider.conf.yml"
|
cwd = git_dir / "subdir"
|
||||||
home_config_yaml = fake_home / ".aider.conf.yaml"
|
cwd.mkdir()
|
||||||
git_config_yml = git_dir / ".aider.conf.yml"
|
os.chdir(cwd)
|
||||||
git_config_yaml = git_dir / ".aider.conf.yaml"
|
|
||||||
cwd_config_yml = cwd / ".aider.conf.yml"
|
|
||||||
cwd_config_yaml = cwd / ".aider.conf.yaml"
|
|
||||||
named_config = git_dir / "named.aider.conf.yml"
|
|
||||||
|
|
||||||
# Create files based on the scenario
|
# Create config files in different locations based on scenario
|
||||||
if scenario == "yml_only":
|
home_config_yml = fake_home / ".aider.conf.yml"
|
||||||
cwd_config_yml.write_text("model: gpt-4-32k\nmap-tokens: 4096\n")
|
home_config_yaml = fake_home / ".aider.conf.yaml"
|
||||||
git_config_yml.write_text("model: gpt-4\nmap-tokens: 2048\n")
|
git_config_yml = git_dir / ".aider.conf.yml"
|
||||||
home_config_yml.write_text("model: gpt-3.5-turbo\nmap-tokens: 1024\n")
|
git_config_yaml = git_dir / ".aider.conf.yaml"
|
||||||
named_config.write_text("model: gpt-4-1106-preview\nmap-tokens: 8192\n")
|
cwd_config_yml = cwd / ".aider.conf.yml"
|
||||||
elif scenario == "yaml_only":
|
cwd_config_yaml = cwd / ".aider.conf.yaml"
|
||||||
cwd_config_yaml.write_text("model: gpt-4-32k\nmap-tokens: 4096\n")
|
named_config = git_dir / "named.aider.conf.yml"
|
||||||
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 (
|
# Create files based on the scenario
|
||||||
patch("pathlib.Path.home", return_value=fake_home),
|
if scenario == "yml_only":
|
||||||
patch("aider.coders.Coder.create") as MockCoder,
|
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")
|
||||||
# Test loading from specified config file
|
home_config_yml.write_text("model: gpt-3.5-turbo\nmap-tokens: 1024\n")
|
||||||
main(
|
named_config.write_text("model: gpt-4-1106-preview\nmap-tokens: 8192\n")
|
||||||
["--yes", "--exit", "--config", str(named_config)],
|
elif scenario == "yaml_only":
|
||||||
input=DummyInput(),
|
cwd_config_yaml.write_text("model: gpt-4-32k\nmap-tokens: 4096\n")
|
||||||
output=DummyOutput(),
|
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")
|
||||||
_, kwargs = MockCoder.call_args
|
named_config.write_text("model: gpt-4-1106-preview\nmap-tokens: 8192\n")
|
||||||
self.assertEqual(kwargs["main_model"].name, "gpt-4-1106-preview")
|
else: # both_formats
|
||||||
self.assertEqual(kwargs["map_tokens"], 8192)
|
# Create both formats, with .yaml taking precedence in each directory
|
||||||
|
cwd_config_yml.write_text("model: gpt-4-32k\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\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\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")
|
||||||
|
|
||||||
# Test loading from current working directory
|
with (
|
||||||
main(["--yes", "--exit"], input=DummyInput(), output=DummyOutput())
|
patch("pathlib.Path.home", return_value=fake_home),
|
||||||
_, kwargs = MockCoder.call_args
|
patch("aider.coders.Coder.create") as MockCoder,
|
||||||
self.assertIn("main_model", kwargs, "main_model key not found in kwargs")
|
):
|
||||||
self.assertEqual(kwargs["main_model"].name, "gpt-4-32k")
|
# Test loading from specified config file
|
||||||
self.assertEqual(kwargs["map_tokens"], 4096)
|
main(
|
||||||
|
["--yes", "--exit", "--config", str(named_config)],
|
||||||
|
input=DummyInput(),
|
||||||
|
output=DummyOutput(),
|
||||||
|
)
|
||||||
|
_, kwargs = MockCoder.call_args
|
||||||
|
self.assertEqual(kwargs["main_model"].name, "gpt-4-1106-preview")
|
||||||
|
self.assertEqual(kwargs["map_tokens"], 8192)
|
||||||
|
|
||||||
# Test loading from git root by removing cwd config files
|
# Test loading from current working directory
|
||||||
if scenario == "yml_only":
|
main(["--yes", "--exit"], input=DummyInput(), output=DummyOutput())
|
||||||
cwd_config_yml.unlink()
|
_, kwargs = MockCoder.call_args
|
||||||
elif scenario == "yaml_only":
|
self.assertIn("main_model", kwargs, "main_model key not found in kwargs")
|
||||||
cwd_config_yaml.unlink()
|
self.assertEqual(kwargs["main_model"].name, "gpt-4-32k")
|
||||||
else: # both_formats
|
self.assertEqual(kwargs["map_tokens"], 4096)
|
||||||
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 by removing git root config files
|
# Test loading from git root by removing cwd config files
|
||||||
if scenario == "yml_only":
|
if scenario == "yml_only":
|
||||||
git_config_yml.unlink()
|
cwd_config_yml.unlink()
|
||||||
elif scenario == "yaml_only":
|
elif scenario == "yaml_only":
|
||||||
git_config_yaml.unlink()
|
cwd_config_yaml.unlink()
|
||||||
else: # both_formats
|
else: # both_formats
|
||||||
git_config_yml.unlink()
|
cwd_config_yml.unlink()
|
||||||
git_config_yaml.unlink()
|
cwd_config_yaml.unlink()
|
||||||
|
|
||||||
main(["--yes", "--exit"], input=DummyInput(), output=DummyOutput())
|
main(["--yes", "--exit"], input=DummyInput(), output=DummyOutput())
|
||||||
_, kwargs = MockCoder.call_args
|
_, kwargs = MockCoder.call_args
|
||||||
self.assertEqual(kwargs["main_model"].name, "gpt-3.5-turbo")
|
self.assertEqual(kwargs["main_model"].name, "gpt-4")
|
||||||
self.assertEqual(kwargs["map_tokens"], 1024)
|
self.assertEqual(kwargs["map_tokens"], 2048)
|
||||||
|
|
||||||
|
# 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")
|
||||||
|
self.assertEqual(kwargs["map_tokens"], 1024)
|
||||||
|
|
||||||
def test_map_tokens_option(self):
|
def test_map_tokens_option(self):
|
||||||
with GitTemporaryDirectory():
|
with GitTemporaryDirectory():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue