Dulwich.io dulwich / e8eb80f
Add tests for cleanup_mode. Jelmer Vernooij 11 years ago
2 changed file(s) with 33 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
2222 import struct
2323
2424 from dulwich.objects import (
25 S_IFGITLINK,
26 S_ISGITLINK,
2527 Tree,
2628 hex_to_sha,
2729 sha_to_hex,
131133
132134
133135 def cleanup_mode(mode):
134 if stat.S_ISLNK(fsmode):
135 mode = stat.S_IFLNK
136 else:
137 mode = stat.S_IFREG
138 mode |= (fsmode & 0111)
139 return mode
136 """Cleanup a mode value.
137
138 """
139 if stat.S_ISLNK(mode):
140 return stat.S_IFLNK
141 elif stat.S_ISDIR(mode):
142 return stat.S_IFDIR
143 elif S_ISGITLINK(mode):
144 return S_IFGITLINK
145 ret = stat.S_IFREG | 0644
146 ret |= (mode & 0111)
147 return ret
140148
141149
142150 class Index(object):
2525
2626 from dulwich.index import (
2727 Index,
28 cleanup_mode,
2829 commit_tree,
2930 read_index,
3031 write_index,
103104 self.assertEquals((stat.S_IFREG, blob.id), self.store[dirid]["bar"])
104105 self.assertEquals(set([rootid, dirid, blob.id]),
105106 set(self.store._data.keys()))
107
108
109 class CleanupModeTests(TestCase):
110
111 def test_file(self):
112 self.assertEquals(0100644, cleanup_mode(0100000))
113
114 def test_executable(self):
115 self.assertEquals(0100755, cleanup_mode(0100711))
116
117 def test_symlink(self):
118 self.assertEquals(0120000, cleanup_mode(0120711))
119
120 def test_dir(self):
121 self.assertEquals(0040000, cleanup_mode(040531))
122
123 def test_submodule(self):
124 self.assertEquals(0160000, cleanup_mode(0160744))