3131import pygit2
3232from . import utils
3333
34- BLOB_SHA = 'a520c24d85fbfc815d385957eed41406ca5a860b'
35- BLOB_OLD_CONTENT = """hello world
34+ BLOB_OLD_SHA = 'a520c24d85fbfc815d385957eed41406ca5a860b'
35+ BLOB_NEW_SHA = '3b18e512dba79e4c8300dd08aeb37f8e728b8dad'
36+ BLOB_OLD_CONTENT = b"""hello world
3637hola mundo
3738bonjour le monde
38- """ . encode ()
39+ """
3940BLOB_NEW_CONTENT = b'foo bar\n '
4041
4142BLOB_OLD_PATH = 'a/file'
4243BLOB_NEW_PATH = 'b/file'
4344
45+ BLOB_PATCH2 = """diff --git a/a/file b/b/file
46+ index a520c24..3b18e51 100644
47+ --- a/a/file
48+ +++ b/b/file
49+ @@ -1,3 +1 @@
50+ hello world
51+ -hola mundo
52+ -bonjour le monde
53+ """
54+
4455BLOB_PATCH = """diff --git a/a/file b/b/file
4556index a520c24..d675fa4 100644
4657--- a/a/file
@@ -78,55 +89,55 @@ class PatchTest(utils.RepoTestCase):
7889 def test_patch_create_from_buffers (self ):
7990 patch = pygit2 .Patch .create_from (
8091 BLOB_OLD_CONTENT ,
81- BLOB_OLD_PATH ,
8292 BLOB_NEW_CONTENT ,
83- BLOB_NEW_PATH ,
93+ old_as_path = BLOB_OLD_PATH ,
94+ new_as_path = BLOB_NEW_PATH ,
8495 )
8596
8697 self .assertEqual (patch .patch , BLOB_PATCH )
8798
8899 def test_patch_create_from_blobs (self ):
89- old_blob = self .repo . create_blob ( BLOB_OLD_CONTENT )
90- new_blob = self .repo . create_blob ( BLOB_NEW_CONTENT )
100+ old_blob = self .repo [ BLOB_OLD_SHA ]
101+ new_blob = self .repo [ BLOB_NEW_SHA ]
91102
92103 patch = pygit2 .Patch .create_from (
93- self . repo [ old_blob ] ,
94- BLOB_OLD_PATH ,
95- self . repo [ new_blob ] ,
96- BLOB_NEW_PATH ,
104+ old_blob ,
105+ new_blob ,
106+ old_as_path = BLOB_OLD_PATH ,
107+ new_as_path = BLOB_NEW_PATH ,
97108 )
98109
99- self .assertEqual (patch .patch , BLOB_PATCH )
110+ self .assertEqual (patch .patch , BLOB_PATCH2 )
100111
101112 def test_patch_create_from_blob_buffer (self ):
102- old_blob = self .repo . create_blob ( BLOB_OLD_CONTENT )
113+ old_blob = self .repo [ BLOB_OLD_SHA ]
103114 patch = pygit2 .Patch .create_from (
104- self .repo [old_blob ],
105- BLOB_OLD_PATH ,
115+ old_blob ,
106116 BLOB_NEW_CONTENT ,
107- BLOB_NEW_PATH ,
117+ old_as_path = BLOB_OLD_PATH ,
118+ new_as_path = BLOB_NEW_PATH ,
108119 )
109120
110121 self .assertEqual (patch .patch , BLOB_PATCH )
111122
112123 def test_patch_create_from_blob_buffer_add (self ):
113124 patch = pygit2 .Patch .create_from (
114125 None ,
115- BLOB_OLD_PATH ,
116126 BLOB_NEW_CONTENT ,
117- BLOB_NEW_PATH ,
127+ old_as_path = BLOB_OLD_PATH ,
128+ new_as_path = BLOB_NEW_PATH ,
118129 )
119130
120131 self .assertEqual (patch .patch , BLOB_PATCH_ADDED )
121132
122133 def test_patch_create_from_blob_buffer_delete (self ):
123- old_blob = self .repo . create_blob ( BLOB_OLD_CONTENT )
134+ old_blob = self .repo [ BLOB_OLD_SHA ]
124135
125136 patch = pygit2 .Patch .create_from (
126- self .repo [old_blob ],
127- BLOB_OLD_PATH ,
137+ old_blob ,
128138 None ,
129- BLOB_NEW_PATH ,
139+ old_as_path = BLOB_OLD_PATH ,
140+ new_as_path = BLOB_NEW_PATH ,
130141 )
131142
132143 self .assertEqual (patch .patch , BLOB_PATCH_DELETED )
@@ -135,16 +146,12 @@ def test_patch_create_from_bad_old_type_arg(self):
135146 with self .assertRaises (TypeError ):
136147 pygit2 .Patch .create_from (
137148 self .repo ,
138- BLOB_OLD_PATH ,
139149 BLOB_NEW_CONTENT ,
140- BLOB_NEW_PATH ,
141150 )
142151
143152 def test_patch_create_from_bad_new_type_arg (self ):
144153 with self .assertRaises (TypeError ):
145154 pygit2 .Patch .create_from (
146155 None ,
147- BLOB_OLD_PATH ,
148156 self .repo ,
149- BLOB_NEW_PATH ,
150157 )
0 commit comments