46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
"""Integration test for multi-file code execution, linting, and prompt context formatting."""
|
|
import unittest
|
|
from src.core.executor import CodeExecutor
|
|
from src.core.linter import CodeLinter
|
|
from src.core.prompts import format_multifile_context, compress_file_content
|
|
|
|
class TestMultiFile(unittest.TestCase):
|
|
def setUp(self):
|
|
self.executor = CodeExecutor()
|
|
self.linter = CodeLinter()
|
|
|
|
def test_cpp_multifile_execution(self):
|
|
files = {
|
|
"main.cpp": '#include "main.h"\n#include <iostream>\nint main() { printMessage(); return 0; }\n',
|
|
"main.h": '#ifndef MAIN_H\n#define MAIN_H\n#include <iostream>\ninline void printMessage() { std::cout << "C++ Multi-File Success!"; }\n#endif\n'
|
|
}
|
|
res = self.executor.run("cpp", code="", stdin="", files=files)
|
|
self.assertEqual(res.get("exit_code"), 0)
|
|
self.assertIn("C++ Multi-File Success!", res.get("stdout"))
|
|
|
|
def test_python_multifile_execution(self):
|
|
files = {
|
|
"main.py": 'import helper\nprint(helper.get_msg())\n',
|
|
"helper.py": 'def get_msg(): return "Python Multi-File Success!"\n'
|
|
}
|
|
res = self.executor.run("python", code="", stdin="", files=files)
|
|
self.assertEqual(res.get("exit_code"), 0)
|
|
self.assertIn("Python Multi-File Success!", res.get("stdout"))
|
|
|
|
def test_multifile_context_formatting(self):
|
|
files = {
|
|
"main.cpp": '#include "main.h"\nint main() { return 0; }',
|
|
"main.h": '#define MSG "Hello"'
|
|
}
|
|
ctx = format_multifile_context(files, active_file="main.cpp")
|
|
self.assertIn("=== File: main.cpp (Active) ===", ctx)
|
|
self.assertIn("=== File: main.h ===", ctx)
|
|
|
|
def test_compression(self):
|
|
large_code = "def foo():\n pass\n" * 100
|
|
compressed = compress_file_content("test.py", large_code)
|
|
self.assertIn("def foo()", compressed)
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|