def test_unchanged(self): b = Blob.from_string(b'b') delta = self.transform([('unchanged', (b'a', stat.S_IFREG | 0o644, b), (b'a', stat.S_IFREG | 0o644, b))]) expected_delta = TreeDelta() expected_delta.unchanged.append( TreeChange(b'git:a', ('a', 'a'), False, (True, True), (b'TREE_ROOT', b'TREE_ROOT'), ('a', 'a'), ('file', 'file'), (False, False), False))
def test_add(self): b = Blob.from_string(b'b') self.assertEqual([ TreeChange(b'git:a', (None, 'a'), True, (False, True), (None, b'TREE_ROOT'), (None, 'a'), (None, 'file'), (None, False), False) ], self.transform([('add', (None, None, None), (b'a', stat.S_IFREG | 0o644, b))]))
def test_rename_no_changes(self): a = Blob.from_string(b'a') self.assertEqual([ TreeChange(b'git:old', ('old', 'a'), False, (True, True), (b'TREE_ROOT', b'TREE_ROOT'), ('old', 'a'), ('file', 'file'), (False, False), False) ], self.transform([('rename', (b'old', stat.S_IFREG | 0o644, a), (b'a', stat.S_IFREG | 0o644, a))]))
def test_delete(self): b = Blob.from_string(b'b') delta = self.transform([('remove', (b'a', stat.S_IFREG | 0o644, b), (None, None, None))]) expected_delta = TreeDelta() expected_delta.removed.append( TreeChange(b'git:a', ('a', None), True, (True, False), (b'TREE_ROOT', None), ('a', None), ('file', None), (False, None), False)) self.assertEqual(delta, expected_delta)
def test_copy_no_changes(self): a = Blob.from_string(b'a') delta = self.transform([('copy', (b'old', stat.S_IFREG | 0o644, a), (b'a', stat.S_IFREG | 0o644, a))]) expected_delta = TreeDelta() expected_delta.copied.append( TreeChange(b'git:a', ('old', 'a'), False, (True, True), (b'TREE_ROOT', b'TREE_ROOT'), ('old', 'a'), ('file', 'file'), (False, False), True)) self.assertEqual(expected_delta, delta)
def test_delete(self): b = Blob.from_string(b'b') self.assertEqual([ TreeChange(b'git:a', ('a', None), True, (True, False), (b'TREE_ROOT', None), ('a', None), ('file', None), (False, None), False) ], self.transform([('remove', (b'a', stat.S_IFREG | 0o644, b), (None, None, None))]))
def test_rename_and_modify(self): a = Blob.from_string(b'a') b = Blob.from_string(b'b') self.assertEqual([ TreeChange(b'git:a', ('a', 'b'), True, (True, True), (b'TREE_ROOT', b'TREE_ROOT'), ('a', 'b'), ('file', 'file'), (False, False), False) ], self.transform([('rename', (b'a', stat.S_IFREG | 0o644, a), (b'b', stat.S_IFREG | 0o644, b))]))
def test_kind_changed(self): a = Blob.from_string(b'a') b = Blob.from_string(b'target') self.assertEqual([ TreeChange(b'git:a', ('a', 'a'), True, (True, True), (b'TREE_ROOT', b'TREE_ROOT'), ('a', 'a'), ('file', 'symlink'), (False, False), False) ], self.transform([('modify', (b'a', stat.S_IFREG | 0o644, a), (b'a', stat.S_IFLNK, b))]))
def test_kind_change(self): a = Blob.from_string(b'a') b = Blob.from_string(b'target') delta = self.transform([('modify', (b'a', stat.S_IFREG | 0o644, a), (b'a', stat.S_IFLNK, b))]) expected_delta = TreeDelta() expected_delta.kind_changed.append( TreeChange(b'git:a', ('a', 'a'), True, (True, True), (b'TREE_ROOT', b'TREE_ROOT'), ('a', 'a'), ('file', 'symlink'), (False, False), False)) self.assertEqual(expected_delta, delta)
def test_rename_and_modify(self): a = Blob.from_string(b'a') b = Blob.from_string(b'b') delta = self.transform([('rename', (b'a', stat.S_IFREG | 0o644, a), (b'b', stat.S_IFREG | 0o644, b))]) expected_delta = TreeDelta() expected_delta.renamed.append( TreeChange(b'git:a', ('a', 'b'), True, (True, True), (b'TREE_ROOT', b'TREE_ROOT'), ('a', 'b'), ('file', 'file'), (False, False), False)) self.assertEqual(delta, expected_delta)
def test_unversioned(self): b = Blob.from_string(b'b') self.assertEqual([ TreeChange(None, (None, 'a'), True, (False, False), (None, b'TREE_ROOT'), (None, 'a'), (None, 'file'), (None, False), False) ], self.transform([('add', (None, None, None), (b'a', stat.S_IFREG | 0o644, b))], target_extras=set([b'a']))) self.assertEqual([ TreeChange(None, ('a', 'a'), False, (False, False), (b'TREE_ROOT', b'TREE_ROOT'), ('a', 'a'), ('file', 'file'), (False, False), False) ], self.transform([('add', (b'a', stat.S_IFREG | 0o644, b), (b'a', stat.S_IFREG | 0o644, b))], source_extras=set([b'a']), target_extras=set([b'a'])))
def test_unversioned(self): b = Blob.from_string(b'b') delta = self.transform([('add', (None, None, None), (b'a', stat.S_IFREG | 0o644, b))], target_extras=set([b'a'])) expected_delta = TreeDelta() expected_delta.unversioned.append( TreeChange(None, (None, 'a'), True, (False, False), (None, b'TREE_ROOT'), (None, 'a'), (None, 'file'), (None, False), False)) self.assertEqual(delta, expected_delta) delta = self.transform([('add', (b'a', stat.S_IFREG | 0o644, b), (b'a', stat.S_IFREG | 0o644, b))], source_extras=set([b'a']), target_extras=set([b'a'])) expected_delta = TreeDelta() expected_delta.unversioned.append( TreeChange(None, ('a', 'a'), False, (False, False), (b'TREE_ROOT', b'TREE_ROOT'), ('a', 'a'), ('file', 'file'), (False, False), False)) self.assertEqual(delta, expected_delta)
def test_unchanged(self): b = Blob.from_string(b'b') self.assertEqual([ TreeChange(b'git:a', ('a', 'a'), False, (True, True), (b'TREE_ROOT', b'TREE_ROOT'), ('a', 'a'), ('file', 'file'), (False, False), False) ], self.transform([('unchanged', (b'a', stat.S_IFREG | 0o644, b), (b'a', stat.S_IFREG | 0o644, b))], include_unchanged=True)) self.assertEqual([], self.transform([('unchanged', (b'a', stat.S_IFREG | 0o644, b), (b'a', stat.S_IFREG | 0o644, b))], include_unchanged=False))