refactor: simplify language test map and read from fixture files

This commit is contained in:
Paul Gauthier (aider) 2024-11-27 07:11:45 -08:00
parent 447b7af573
commit 2ce01b157b

View file

@ -333,96 +333,46 @@ class TestRepoMapAllLanguages(unittest.TestCase):
def test_get_repo_map_all_languages(self): def test_get_repo_map_all_languages(self):
language_files = { language_files = {
"c": ( "c": "main",
"test.c", "cpp": "main",
"", # Now reads from fixture file "elixir": "Greeter",
"main", # Key symbol to check "java": "Greeting",
), "javascript": "Person",
"cpp": ( "ocaml": "Greeter",
"test.cpp", "php": "greet",
"", # Now reads from fixture file "python": "Person",
"main", # Key symbol to check "ql": "greet",
), "ruby": "greet",
"elixir": ( "rust": "Person",
"test.ex", "typescript": "greet",
"", # Now reads from fixture file "tsx": "UserProps",
"Greeter", # Key symbol to check "csharp": "IGreeter",
), "elisp": "greeter",
"java": ( "elm": "Person",
"Test.java", "go": "Greeter",
"", # Now reads from fixture file
"Greeting", # Key symbol to check
),
"javascript": (
"test.js",
"", # Now reads from fixture file
"Person", # Key symbol to check
),
"ocaml": (
"test.ml",
"", # Now reads from fixture file
"Greeter", # Key symbol to check
),
"php": (
"test.php",
"", # Now reads from fixture file
"greet", # Key symbol to check
),
"python": (
"test.py",
"", # Now reads from fixture file
"Person", # Key symbol to check
),
"ql": (
"test.ql",
"", # Now reads from fixture file
"greet", # Key symbol to check
),
"ruby": (
"test.rb",
"", # Now reads from fixture file
"greet", # Key symbol to check
),
"rust": (
"test.rs",
"", # Now reads from fixture file
"Person", # Key symbol to check
),
"typescript": (
"test.ts",
"", # Now reads from fixture file
"greet", # Key symbol to check
),
"tsx": (
"test.tsx",
"", # Now reads from fixture file
"UserProps", # Key symbol to check
),
"csharp": (
"test.cs",
"", # Now reads from fixture file
"IGreeter", # Key symbol to check
),
"elisp": (
"test.el",
"", # Now reads from fixture file
"greeter", # Key symbol to check
),
"elm": (
"test.elm",
"", # Now reads from fixture file
"Person", # Key symbol to check
),
"go": (
"test.go",
"", # Now reads from fixture file
"Greeter", # Key symbol to check
),
} }
for lang, (filename, content, key_symbol) in language_files.items(): fixtures_dir = Path(__file__).parent.parent / "fixtures" / "languages"
for lang, key_symbol in language_files.items():
# Get the fixture file path and name based on language
fixture_dir = fixtures_dir / lang
if lang == "cpp":
filename = "hello.cpp"
elif lang == "c":
filename = "hello.c"
else:
filename = "test." + {"csharp": "cs"}.get(lang, lang)
fixture_path = fixture_dir / filename
self.assertTrue(fixture_path.exists(), f"Fixture file missing for {lang}: {fixture_path}")
# Read the fixture content
with open(fixture_path, "r", encoding="utf-8") as f:
content = f.read()
with GitTemporaryDirectory() as temp_dir: with GitTemporaryDirectory() as temp_dir:
with open(os.path.join(temp_dir, filename), "w") as f: test_file = os.path.join(temp_dir, filename)
with open(test_file, "w", encoding="utf-8") as f:
f.write(content) f.write(content)
io = InputOutput() io = InputOutput()