diff --git a/tests/test_repomap.py b/tests/test_repomap.py index 328ee3bbe..b34593221 100644 --- a/tests/test_repomap.py +++ b/tests/test_repomap.py @@ -1,11 +1,12 @@ import os -import tempfile import unittest from unittest.mock import patch from aider.io import InputOutput from aider.repomap import RepoMap +from .utils import IgnorantTemporaryDirectory + class TestRepoMap(unittest.TestCase): def test_get_repo_map(self): @@ -17,7 +18,7 @@ class TestRepoMap(unittest.TestCase): "test_file4.json", ] - with tempfile.TemporaryDirectory() as temp_dir: + with IgnorantTemporaryDirectory() as temp_dir: for file in test_files: with open(os.path.join(temp_dir, file), "w") as f: f.write("") @@ -60,7 +61,7 @@ print(my_function(3, 4)) test_file3 = "test_file_pass.py" file_content3 = "pass" - with tempfile.TemporaryDirectory() as temp_dir: + with IgnorantTemporaryDirectory() as temp_dir: with open(os.path.join(temp_dir, test_file1), "w") as f: f.write(file_content1) @@ -124,7 +125,7 @@ print(my_function(3, 4)) "test_file6.js", ] - with tempfile.TemporaryDirectory() as temp_dir: + with IgnorantTemporaryDirectory() as temp_dir: for file in test_files: with open(os.path.join(temp_dir, file), "w") as f: f.write("") diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 000000000..1629c4425 --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,15 @@ +import tempfile + + +class IgnorantTemporaryDirectory: + def __init__(self): + self.temp_dir = tempfile.TemporaryDirectory() + + def __enter__(self): + return self.temp_dir.__enter__() + + def __exit__(self, exc_type, exc_val, exc_tb): + try: + self.temp_dir.__exit__(exc_type, exc_val, exc_tb) + except OSError: + pass # Ignore errors (Windows)