test: refactor repo map language test to run each language separately

This commit is contained in:
Paul Gauthier 2024-11-27 06:48:10 -08:00 committed by Paul Gauthier (aider)
parent 48ea13e130
commit 2337b2bb3e

View file

@ -373,20 +373,6 @@ class TestRepoMapAllLanguages(unittest.TestCase):
def test_get_repo_map_all_languages(self): def test_get_repo_map_all_languages(self):
language_files = { language_files = {
"dart": (
"test.dart",
"""void main() {
print('Hello, World!');
}
class Greeter {
String sayHello(String name) {
return 'Hello, $name!';
}
}
""",
"Greeter", # Key symbol to check
),
"c": ( "c": (
"test.c", "test.c",
( (
@ -395,14 +381,6 @@ class Greeter {
), ),
"main", # Key symbol to check "main", # Key symbol to check
), ),
"csharp": (
"test.cs",
(
"using System;\n\nclass Program {\n static void Main() {\n "
' Console.WriteLine("Hello, World!");\n }\n}\n'
),
"Program", # Key symbol to check
),
"cpp": ( "cpp": (
"test.cpp", "test.cpp",
( (
@ -411,11 +389,6 @@ class Greeter {
), ),
"main", # Key symbol to check "main", # Key symbol to check
), ),
"elisp": (
"test.el",
'(defun greet (name)\n (message "Hello, %s!" name))\n',
"greet", # Key symbol to check
),
"elixir": ( "elixir": (
"test.ex", "test.ex",
( (
@ -424,22 +397,6 @@ class Greeter {
), ),
"Greeter", # Key symbol to check "Greeter", # Key symbol to check
), ),
"elm": (
"test.elm",
(
"module Main exposing (main)\n\nimport Html exposing (text)\n\nmain =\n text"
' "Hello, World!"\n'
),
"Main", # Key symbol to check
),
"go": (
"test.go",
(
'package main\n\nimport "fmt"\n\nfunc main() {\n fmt.Println("Hello,'
' World!")\n}\n'
),
"main", # Key symbol to check
),
"java": ( "java": (
"Test.java", "Test.java",
( (
@ -450,7 +407,7 @@ class Greeter {
), ),
"javascript": ( "javascript": (
"test.js", "test.js",
"function greet(name) {\n console.log(`Hello, ${name}!`);\n}\n", "var greet= 1;function greet(name) {\n console.log(`Hello, ${name}!`);\n}\n",
"greet", # Key symbol to check "greet", # Key symbol to check
), ),
"ocaml": ( "ocaml": (
@ -497,27 +454,70 @@ class Greeter {
), ),
"Greeting", # Key symbol to check "Greeting", # Key symbol to check
), ),
"csharp": (
"test.cs",
(
"using System;\n\nclass Program {\n static void Main() {\n "
' Console.WriteLine("Hello, World!");\n }\n}\n'
),
"Program", # Key symbol to check
),
#####################
"dart": (
"test.dart",
"""void main() {
print('Hello, World!');
} }
with IgnorantTemporaryDirectory() as temp_dir: class Greeter {
for _, (filename, content, _) in language_files.items(): String sayHello(String name) {
return 'Hello, $name!';
}
}
""",
"Greeter", # Key symbol to check
),
"elisp": (
"test.el",
'(defun greet (name)\n (message "Hello, %s!" name))\n',
"greet", # Key symbol to check
),
"elm": (
"test.elm",
(
"module Main exposing (main)\n\nimport Html exposing (text)\n\nmain =\n text"
' "Hello, World!"\n'
),
"Main", # Key symbol to check
),
"go": (
"test.go",
(
'package main\n\nimport "fmt"\n\nfunc main() {\n fmt.Println("Hello,'
' World!")\n}\n'
),
"main", # Key symbol to check
),
}
for lang, (filename, content, key_symbol) in language_files.items():
with GitTemporaryDirectory() as temp_dir:
with open(os.path.join(temp_dir, filename), "w") as f: with open(os.path.join(temp_dir, filename), "w") as f:
f.write(content) f.write(content)
io = InputOutput() io = InputOutput()
repo_map = RepoMap(main_model=self.GPT35, root=temp_dir, io=io) repo_map = RepoMap(main_model=self.GPT35, root=temp_dir, io=io)
other_files = [ other_files = [filename]
os.path.join(temp_dir, filename) for filename, _, _ in language_files.values()
]
result = repo_map.get_repo_map([], other_files) result = repo_map.get_repo_map([], other_files)
dump(lang)
dump(result)
# Check if the result contains all the expected files and symbols # Check if the result contains all the expected files and symbols
for lang, (filename, _, key_symbol) in language_files.items(): self.assertIn(filename, result, f"File for language {lang} not found in repo map: {result}")
self.assertIn(filename, result, f"File for language {lang} not found in repo map")
self.assertIn( self.assertIn(
key_symbol, key_symbol,
result, result,
f"Key symbol '{key_symbol}' for language {lang} not found in repo map", f"Key symbol '{key_symbol}' for language {lang} not found in repo map: {result}",
) )
# close the open cache files, so Windows won't error # close the open cache files, so Windows won't error