Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master

Add tests for commit.

Changeset fe33efa88e86

Parent f280b90eb105

by Jelmer Vernooij

Changes to 4 files · Browse files at fe33efa88e86 Showing diff from parent f280b90eb105 Diff from another changeset...

Change 1 of 2 Show Entire File dulwich/​index.py Stacked
 
18
19
20
 
21
22
23
 
227
228
229
230
 
231
 
232
233
234
 
18
19
20
21
22
23
24
 
228
229
230
 
231
232
233
234
235
236
@@ -18,6 +18,7 @@
   """Parser for the git index file format."""   +import os  import stat  import struct   @@ -227,8 +228,9 @@
    for path in sorted(trees.keys(), reverse=True):   tree = Tree() - for basename, (mode, sha) in trees[path]: + for basename, (mode, sha) in trees[path].iteritems():   tree.add(mode, basename, sha) + object_store.add_object(tree)   if path != "":   # Add to object store   parent_path, basename = os.path.split(path)
 
319
320
321
322
 
 
 
 
323
324
325
326
327
328
 
329
330
331
 
319
320
321
 
322
323
324
325
326
327
328
329
330
 
331
332
333
334
@@ -319,13 +319,16 @@
  :param name: sha for the object.   :return: tuple with object type and object contents.   """ - return self[sha].as_raw_string() + return self[name].as_raw_string() + + def __getitem__(self, name): + return self._data[name]     def add_object(self, obj):   """Add a single object to this object store.     """ - self._dict[obj.id] = obj + self._data[obj.id] = obj     def add_objects(self, objects):   """Add a set of objects to this object store.
 
231
232
233
234
235
236
 
237
 
 
 
 
 
 
238
239
240
 
420
421
422
 
 
 
423
424
425
 
231
232
233
 
 
 
234
235
236
237
238
239
240
241
242
243
244
 
424
425
426
427
428
429
430
431
432
@@ -231,10 +231,14 @@
  _needs_serialization = False   _needs_parsing = False   - @property - def data(self): - """The text contained within the blob object.""" + def get_data(self):   return self._text + + def set_data(self, data): + self._text = data + + data = property(get_data, set_data, + "The text contained within the blob object.")     @classmethod   def from_file(cls, filename): @@ -420,6 +424,9 @@
  self._needs_serialization = True     def add(self, mode, name, hexsha): + assert type(mode) == int + assert type(name) == str + assert type(hexsha) == str   self._ensure_parsed()   self._entries[name] = mode, hexsha   self._needs_serialization = True
 
17
18
19
 
20
21
22
23
 
24
25
 
 
 
 
 
 
26
27
28
 
62
63
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
@@ -17,12 +17,20 @@
 # MA 02110-1301, USA.    import os +import stat  from unittest import TestCase    from dulwich.index import (   Index, + commit_tree,   read_index,   write_index, + ) +from dulwich.object_store import ( + MemoryObjectStore, + ) +from dulwich.objects import ( + Blob,   )    class IndexTestCase(TestCase): @@ -62,3 +70,19 @@
  finally:   x.close()   + +class CommitTreeTests(TestCase): + + def setUp(self): + super(CommitTreeTests, self).setUp() + self.store = MemoryObjectStore() + + def test_single_blob(self): + blob = Blob() + blob.data = "foo" + self.store.add_object(blob) + blobs = [("bla", blob.id, stat.S_IFREG)] + rootid = commit_tree(self.store, blobs) + self.assertEquals(rootid, "1a1e80437220f9312e855c37ac4398b68e5c1d50") + self.assertEquals(blob.id, self.store[rootid]["bla"][1]) + self.assertEquals(set([rootid, blob.id]), set(self.store._data.keys()))