Dulwich.io dulwich / 58a7ef6
Remove test that unconditionally relied on C git. Fixes #720 This test is already present under dulwich/tests/compat/test_patch.py, but only run when C git is available. Jelmer Vernooij 5 days ago
2 changed file(s) with 3 addition(s) and 78 deletion(s). Raw diff Collapse all Expand all
33
44 * Avoid ``PermissionError``, since it is Python3-specific.
55 (Jelmer Vernooij)
6
7 * Fix regression that added a dependency on C git for the
8 test suite. (Jelmer Vernooij, #720)
69
710 0.19.12 2019-08-13
811
5050 build_commit_graph,
5151 make_commit,
5252 make_object,
53 )
54 from dulwich.tests.compat.utils import (
55 run_git_or_fail,
5653 )
5754
5855
704701 porcelain.diff_tree(self.repo.path, c2.tree, c3.tree,
705702 outstream=outstream)
706703 self.assertEqual(outstream.getvalue(), b"")
707
708 def test_diff_apply(self):
709 # Prepare the repository
710
711 # Create some files and commit them
712 file_list = ["to_exists", "to_modify", "to_delete"]
713 for file in file_list:
714 file_path = os.path.join(self.repo_path, file)
715
716 # Touch the files
717 with open(file_path, "w"):
718 pass
719
720 self.repo.stage(file_list)
721
722 first_commit = self.repo.do_commit(b"The first commit")
723
724 # Make a copy of the repository so we can apply the diff later
725 copy_path = os.path.join(self.test_dir, "copy")
726 shutil.copytree(self.repo_path, copy_path)
727
728 # Do some changes
729 with open(os.path.join(self.repo_path, "to_modify"), "w") as f:
730 f.write("Modified!")
731
732 os.remove(os.path.join(self.repo_path, "to_delete"))
733
734 with open(os.path.join(self.repo_path, "to_add"), "w"):
735 pass
736
737 self.repo.stage(["to_modify", "to_delete", "to_add"])
738
739 second_commit = self.repo.do_commit(b"The second commit")
740
741 # Get the patch
742 first_tree = self.repo[first_commit].tree
743 second_tree = self.repo[second_commit].tree
744
745 outstream = BytesIO()
746 porcelain.diff_tree(self.repo.path, first_tree, second_tree,
747 outstream=outstream)
748
749 # Save it on disk
750 patch_path = os.path.join(self.test_dir, "patch.patch")
751 with open(patch_path, "wb") as patch:
752 patch.write(outstream.getvalue())
753
754 # And try to apply it to the copy directory
755 git_command = ["-C", copy_path, "apply", patch_path]
756 run_git_or_fail(git_command)
757
758 # And now check that the files contents are exactly the same between
759 # the two repositories
760 original_files = set(os.listdir(self.repo_path))
761 new_files = set(os.listdir(copy_path))
762
763 # Check that we have the exact same files in both repositories
764 self.assertEqual(original_files, new_files)
765
766 for file in original_files:
767 if file == ".git":
768 continue
769
770 original_file_path = os.path.join(self.repo_path, file)
771 copy_file_path = os.path.join(copy_path, file)
772
773 self.assertTrue(os.path.isfile(copy_file_path))
774
775 with open(original_file_path, "rb") as original_file:
776 original_content = original_file.read()
777
778 with open(copy_file_path, "rb") as copy_file:
779 copy_content = copy_file.read()
780
781 self.assertEqual(original_content, copy_content)
782704
783705
784706 class CommitTreeTests(PorcelainTestCase):