Clean up file headers.
[jelmer/dulwich-libgit2.git] / dulwich / tests / test_fastexport.py
1 # test_fastexport.py -- Fast export/import functionality
2 # Copyright (C) 2010 Jelmer Vernooij <jelmer@samba.org>
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; version 2
7 # of the License or (at your option) any later version of
8 # the License.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # MA  02110-1301, USA.
19
20 from cStringIO import StringIO
21 import stat
22 from unittest import TestCase
23
24 from dulwich.fastexport import (
25     FastExporter,
26     )
27 from dulwich.object_store import (
28     MemoryObjectStore,
29     )
30 from dulwich.objects import (
31     Blob,
32     Commit,
33     Tree,
34     )
35
36
37 class FastExporterTests(TestCase):
38
39     def setUp(self):
40         super(FastExporterTests, self).setUp()
41         self.store = MemoryObjectStore()
42         self.stream = StringIO()
43         self.fastexporter = FastExporter(self.stream, self.store)
44
45     def test_export_blob(self):
46         b = Blob()
47         b.data = "fooBAR"
48         self.assertEquals(1, self.fastexporter.export_blob(b))
49         self.assertEquals('blob\nmark :1\ndata 6\nfooBAR\n',
50             self.stream.getvalue())
51
52     def test_export_commit(self):
53         b = Blob()
54         b.data = "FOO"
55         t = Tree()
56         t.add(stat.S_IFREG | 0644, "foo", b.id)
57         c = Commit()
58         c.committer = c.author = "Jelmer <jelmer@host>"
59         c.author_time = c.commit_time = 1271345553.47
60         c.author_timezone = c.commit_timezone = 0
61         c.message = "msg"
62         c.tree = t.id
63         self.store.add_objects([(b, None), (t, None), (c, None)])
64         self.assertEquals(2,
65                 self.fastexporter.export_commit(c, "refs/heads/master"))
66         self.assertEquals("""blob
67 mark :1
68 data 3
69 FOO
70 commit refs/heads/master
71 mark :2
72 author Jelmer <jelmer@host> 1271345553.47 +0000
73 committer Jelmer <jelmer@host> 1271345553.47 +0000
74 data 3
75 msg
76 M 100644 :1 foo
77
78 """, self.stream.getvalue())