コード例 #1
0
 def test_object_diff_bin_blob_force(self):
     f = BytesIO()
     # Prepare two slightly different PNG headers
     b1 = Blob.from_string(b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"
                           b"\x00\x00\x00\x0d\x49\x48\x44\x52"
                           b"\x00\x00\x01\xd5\x00\x00\x00\x9f"
                           b"\x08\x04\x00\x00\x00\x05\x04\x8b")
     b2 = Blob.from_string(b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"
                           b"\x00\x00\x00\x0d\x49\x48\x44\x52"
                           b"\x00\x00\x01\xd5\x00\x00\x00\x9f"
                           b"\x08\x03\x00\x00\x00\x98\xd3\xb3")
     store = MemoryObjectStore()
     store.add_objects([(b1, None), (b2, None)])
     write_object_diff(f,
                       store, (b'foo.png', 0o644, b1.id),
                       (b'bar.png', 0o644, b2.id),
                       diff_binary=True)
     self.assertEqual([
         b'diff --git a/foo.png b/bar.png', b'index f73e47d..06364b7 644',
         b'--- a/foo.png', b'+++ b/bar.png', b'@@ -1,4 +1,4 @@',
         b' \x89PNG', b' \x1a', b' \x00\x00\x00',
         b'-IHDR\x00\x00\x01\xd5\x00\x00\x00'
         b'\x9f\x08\x04\x00\x00\x00\x05\x04\x8b',
         b'\\ No newline at end of file',
         b'+IHDR\x00\x00\x01\xd5\x00\x00\x00\x9f'
         b'\x08\x03\x00\x00\x00\x98\xd3\xb3',
         b'\\ No newline at end of file'
     ],
                      f.getvalue().splitlines())
コード例 #2
0
 def test_object_diff_remove_blob(self):
     f = BytesIO()
     b1 = Blob.from_string(b"new\nsame\n")
     store = MemoryObjectStore()
     store.add_object(b1)
     write_object_diff(f, store, (b"bar.txt", 0o644, b1.id),
                       (None, None, None))
     self.assertEqual([
         b'diff --git a/bar.txt /dev/null', b'deleted mode 644',
         b'index a116b51..0000000', b'--- a/bar.txt', b'+++ /dev/null',
         b'@@ -1,2 +0,0 @@', b'-new', b'-same'
     ],
                      f.getvalue().splitlines())
コード例 #3
0
 def test_object_diff_add_blob(self):
     f = BytesIO()
     store = MemoryObjectStore()
     b2 = Blob.from_string(b"new\nsame\n")
     store.add_object(b2)
     write_object_diff(f, store, (None, None, None),
                       (b"bar.txt", 0o644, b2.id))
     self.assertEqual([
         b'diff --git /dev/null b/bar.txt', b'new mode 644',
         b'index 0000000..a116b51 644', b'--- /dev/null', b'+++ b/bar.txt',
         b'@@ -0,0 +1,2 @@', b'+new', b'+same'
     ],
                      f.getvalue().splitlines())
コード例 #4
0
 def test_object_diff_blob(self):
     f = BytesIO()
     b1 = Blob.from_string(b"old\nsame\n")
     b2 = Blob.from_string(b"new\nsame\n")
     store = MemoryObjectStore()
     store.add_objects([(b1, None), (b2, None)])
     write_object_diff(f, store, (b"foo.txt", 0o644, b1.id),
                       (b"bar.txt", 0o644, b2.id))
     self.assertEqual([
         b"diff --git a/foo.txt b/bar.txt", b"index 3b0f961..a116b51 644",
         b"--- a/foo.txt", b"+++ b/bar.txt", b"@@ -1,2 +1,2 @@", b"-old",
         b"+new", b" same"
     ],
                      f.getvalue().splitlines())
コード例 #5
0
 def test_object_diff_remove_bin_blob(self):
     f = BytesIO()
     b1 = Blob.from_string(b'\x89\x50\x4e\x47\x0d\x0a\x1a\x0a'
                           b'\x00\x00\x00\x0d\x49\x48\x44\x52'
                           b'\x00\x00\x01\xd5\x00\x00\x00\x9f'
                           b'\x08\x04\x00\x00\x00\x05\x04\x8b')
     store = MemoryObjectStore()
     store.add_object(b1)
     write_object_diff(f, store, (b'foo.png', 0o644, b1.id),
                       (None, None, None))
     self.assertEqual([
         b'diff --git a/foo.png /dev/null', b'deleted mode 644',
         b'index f73e47d..0000000',
         b'Binary files a/foo.png and /dev/null differ'
     ],
                      f.getvalue().splitlines())
コード例 #6
0
 def test_object_diff_add_bin_blob(self):
     f = BytesIO()
     b2 = Blob.from_string(b'\x89\x50\x4e\x47\x0d\x0a\x1a\x0a'
                           b'\x00\x00\x00\x0d\x49\x48\x44\x52'
                           b'\x00\x00\x01\xd5\x00\x00\x00\x9f'
                           b'\x08\x03\x00\x00\x00\x98\xd3\xb3')
     store = MemoryObjectStore()
     store.add_object(b2)
     write_object_diff(f, store, (None, None, None),
                       (b'bar.png', 0o644, b2.id))
     self.assertEqual([
         b'diff --git /dev/null b/bar.png', b'new mode 644',
         b'index 0000000..06364b7 644',
         b'Binary files /dev/null and b/bar.png differ'
     ],
                      f.getvalue().splitlines())
コード例 #7
0
 def test_object_diff_bin_blob(self):
     f = BytesIO()
     # Prepare two slightly different PNG headers
     b1 = Blob.from_string(b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"
                           b"\x00\x00\x00\x0d\x49\x48\x44\x52"
                           b"\x00\x00\x01\xd5\x00\x00\x00\x9f"
                           b"\x08\x04\x00\x00\x00\x05\x04\x8b")
     b2 = Blob.from_string(b"\x89\x50\x4e\x47\x0d\x0a\x1a\x0a"
                           b"\x00\x00\x00\x0d\x49\x48\x44\x52"
                           b"\x00\x00\x01\xd5\x00\x00\x00\x9f"
                           b"\x08\x03\x00\x00\x00\x98\xd3\xb3")
     store = MemoryObjectStore()
     store.add_objects([(b1, None), (b2, None)])
     write_object_diff(f, store, (b'foo.png', 0o644, b1.id),
                       (b'bar.png', 0o644, b2.id))
     self.assertEqual([
         b'diff --git a/foo.png b/bar.png', b'index f73e47d..06364b7 644',
         b'Binary files a/foo.png and b/bar.png differ'
     ],
                      f.getvalue().splitlines())
コード例 #8
0
 def test_object_diff_kind_change(self):
     f = BytesIO()
     b1 = Blob.from_string(b"new\nsame\n")
     store = MemoryObjectStore()
     store.add_object(b1)
     write_object_diff(f, store, (b"bar.txt", 0o644, b1.id),
                       (b"bar.txt", 0o160000,
                        b"06d0bdd9e2e20377b3180e4986b14c8549b393e4"))
     self.assertEqual([
         b'diff --git a/bar.txt b/bar.txt',
         b'old mode 644',
         b'new mode 160000',
         b'index a116b51..06d0bdd 160000',
         b'--- a/bar.txt',
         b'+++ b/bar.txt',
         b'@@ -1,2 +1 @@',
         b'-new',
         b'-same',
         b'+Submodule commit 06d0bdd9e2e20377b3180e4986b14c8549b393e4',
     ],
                      f.getvalue().splitlines())