From 149db2e5fef68fb754b55fb33d6504e7a8e03ec0 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Mon, 29 Jul 2024 16:57:16 -0300 Subject: [PATCH] Add test for creating a Coder from another Coder with a subdirectory --- tests/basic/test_coder.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/basic/test_coder.py b/tests/basic/test_coder.py index 1643aeeb5..7f3706a04 100644 --- a/tests/basic/test_coder.py +++ b/tests/basic/test_coder.py @@ -698,6 +698,37 @@ two self.assertEqual(result.count("https://example.com"), 1) self.assertIn("https://example.com", result) + def test_coder_from_coder_with_subdir(self): + with GitTemporaryDirectory() as root: + repo = git.Repo.init(root) + + # Create a file in a subdirectory + subdir = Path(root) / "subdir" + subdir.mkdir() + test_file = subdir / "test_file.txt" + test_file.write_text("Test content") + + repo.git.add(str(test_file)) + repo.git.commit("-m", "Add test file") + + # Change directory to the subdirectory + os.chdir(subdir) + + # Create the first coder + io = InputOutput(yes=True) + coder1 = Coder.create(self.GPT35, None, io=io, fnames=[str(test_file)]) + + # Create a new coder from the first coder + coder2 = Coder.create(from_coder=coder1) + + # Check if both coders have the same set of abs_fnames + self.assertEqual(coder1.abs_fnames, coder2.abs_fnames) + + # Ensure the abs_fnames contain the correct absolute path + expected_abs_path = os.path.abspath(str(test_file)) + self.assertIn(expected_abs_path, coder1.abs_fnames) + self.assertIn(expected_abs_path, coder2.abs_fnames) + if __name__ == "__main__": unittest.main()