mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
tempdirs in test_main now cleanup without windows errors
This commit is contained in:
parent
f4e4e3af87
commit
dd6a7964b6
2 changed files with 10 additions and 4 deletions
|
@ -13,7 +13,7 @@ from prompt_toolkit.output import DummyOutput
|
||||||
from aider.dump import dump # noqa: F401
|
from aider.dump import dump # noqa: F401
|
||||||
from aider.io import InputOutput
|
from aider.io import InputOutput
|
||||||
from aider.main import check_gitignore, main, setup_git
|
from aider.main import check_gitignore, main, setup_git
|
||||||
from aider.utils import GitTemporaryDirectory, make_repo
|
from aider.utils import GitTemporaryDirectory, IgnorantTemporaryDirectory, make_repo
|
||||||
|
|
||||||
|
|
||||||
class TestMain(TestCase):
|
class TestMain(TestCase):
|
||||||
|
@ -21,7 +21,7 @@ class TestMain(TestCase):
|
||||||
self.original_env = os.environ.copy()
|
self.original_env = os.environ.copy()
|
||||||
os.environ["OPENAI_API_KEY"] = "deadbeef"
|
os.environ["OPENAI_API_KEY"] = "deadbeef"
|
||||||
self.original_cwd = os.getcwd()
|
self.original_cwd = os.getcwd()
|
||||||
self.tempdir_obj = tempfile.TemporaryDirectory()
|
self.tempdir_obj = IgnorantTemporaryDirectory()
|
||||||
self.tempdir = self.tempdir_obj.name
|
self.tempdir = self.tempdir_obj.name
|
||||||
os.chdir(self.tempdir)
|
os.chdir(self.tempdir)
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class TestMain(TestCase):
|
||||||
def test_main_with_empty_dir_no_files_on_command(self):
|
def test_main_with_empty_dir_no_files_on_command(self):
|
||||||
main(["--no-git"], input=DummyInput(), output=DummyOutput())
|
main(["--no-git"], input=DummyInput(), output=DummyOutput())
|
||||||
|
|
||||||
def test_main_with_empty_dir_new_file(self):
|
def test_main_with_emptqy_dir_new_file(self):
|
||||||
main(["foo.txt", "--yes", "--no-git"], input=DummyInput(), output=DummyOutput())
|
main(["foo.txt", "--yes", "--no-git"], input=DummyInput(), output=DummyOutput())
|
||||||
self.assertTrue(os.path.exists("foo.txt"))
|
self.assertTrue(os.path.exists("foo.txt"))
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,17 @@ class IgnorantTemporaryDirectory:
|
||||||
return self.temp_dir.__enter__()
|
return self.temp_dir.__enter__()
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
self.cleanup()
|
||||||
|
|
||||||
|
def cleanup(self):
|
||||||
try:
|
try:
|
||||||
self.temp_dir.__exit__(exc_type, exc_val, exc_tb)
|
self.temp_dir.cleanup()
|
||||||
except (OSError, PermissionError):
|
except (OSError, PermissionError):
|
||||||
pass # Ignore errors (Windows)
|
pass # Ignore errors (Windows)
|
||||||
|
|
||||||
|
def __getattr__(self, item):
|
||||||
|
return getattr(self.temp_dir, item)
|
||||||
|
|
||||||
|
|
||||||
class ChdirTemporaryDirectory(IgnorantTemporaryDirectory):
|
class ChdirTemporaryDirectory(IgnorantTemporaryDirectory):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue