Forráskód Böngészése

Add some basic tests for fastexport.

Jelmer Vernooij 15 éve
szülő
commit
394601eafc
3 módosított fájl, 46 hozzáadás és 1 törlés
  1. 3 1
      dulwich/fastexport.py
  2. 1 0
      dulwich/tests/__init__.py
  3. 42 0
      dulwich/tests/test_fastexport.py

+ 3 - 1
dulwich/fastexport.py

@@ -25,6 +25,7 @@ from dulwich.objects import format_timezone
 import stat
 
 class FastExporter(object):
+    """Generate a fast-export output stream for Git objects."""
 
     def __init__(self, outf, store):
         self.outf = outf
@@ -34,7 +35,8 @@ class FastExporter(object):
     def export_blob(self, blob, i):
         self.outf.write("blob\nmark :%s\n" % i)
         self.outf.write("data %s\n" % blob.raw_length())
-        self.outf.write(blob.as_raw_string())
+        for chunk in blob.as_raw_chunks():
+            self.outf.write(chunk)
         self.outf.write("\n")
 
     def export_commit(self, commit, branchname):

+ 1 - 0
dulwich/tests/__init__.py

@@ -29,6 +29,7 @@ from nose import SkipTest as TestSkipped
 def test_suite():
     names = [
         'client',
+        'fastexport',
         'file',
         'index',
         'lru_cache',

+ 42 - 0
dulwich/tests/test_fastexport.py

@@ -0,0 +1,42 @@
+# test_fastexport.py -- Fast export/import functionality
+# Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2
+# of the License or (at your option) any later version of 
+# the License.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.
+
+from cStringIO import StringIO
+
+from dulwich.fastexport import FastExporter
+from dulwich.object_store import MemoryObjectStore
+from dulwich.objects import Blob
+
+from unittest import TestCase
+
+
+class FastExporterTests(TestCase):
+
+    def setUp(self):
+        super(FastExporterTests, self).setUp()
+        self.store = MemoryObjectStore()
+        self.stream = StringIO()
+        self.fastexporter = FastExporter(self.stream, self.store)
+
+    def test_export_blob(self):
+        b = Blob()
+        b.data = "fooBAR"
+        self.fastexporter.export_blob(b, 0)
+        self.assertEquals('blob\nmark :0\ndata 6\nfooBAR\n',
+            self.stream.getvalue())