/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-08 14:55:19 UTC
  • mfrom: (3530 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3532.
  • Revision ID: john@arbash-meinel.com-20080708145519-paqg4kjwbpgs2xmq
Merge bzr.dev 3530

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
    )
52
52
from bzrlib.transform import (TreeTransform, ROOT_PARENT, FinalPaths, 
53
53
                              resolve_conflicts, cook_conflicts, 
54
 
                              find_interesting, build_tree, get_backup_name,
55
 
                              change_entry, _FileMover, resolve_checkout,
 
54
                              build_tree, get_backup_name,
 
55
                              _FileMover, resolve_checkout,
56
56
                              TransformPreview)
57
57
 
58
58
class TestTreeTransform(tests.TestCaseWithTransport):
64
64
 
65
65
    def get_transform(self):
66
66
        transform = TreeTransform(self.wt)
67
 
        #self.addCleanup(transform.finalize)
 
67
        self.addCleanup(transform.finalize)
68
68
        return transform, transform.root
69
69
 
70
70
    def test_existing_limbo(self):
85
85
    def test_existing_pending_deletion(self):
86
86
        transform, root = self.get_transform()
87
87
        deletion_path = self._limbodir = urlutils.local_path_from_url(
88
 
            transform._tree._control_files.controlfilename('pending-deletion'))
 
88
            transform._tree._transport.abspath('pending-deletion'))
89
89
        os.mkdir(pathjoin(deletion_path, 'blocking-directory'))
90
90
        self.assertRaises(ImmortalPendingDeletion, transform.apply)
91
91
        self.assertRaises(LockError, self.wt.unlock)
747
747
        rename.set_executability(True, myfile)
748
748
        rename.apply()
749
749
 
750
 
    def test_find_interesting(self):
751
 
        create, root = self.get_transform()
752
 
        wt = create._tree
753
 
        create.new_file('vfile', root, 'myfile-text', 'myfile-id')
754
 
        create.new_file('uvfile', root, 'othertext')
755
 
        create.apply()
756
 
        result = self.applyDeprecated(symbol_versioning.zero_fifteen,
757
 
            find_interesting, wt, wt, ['vfile'])
758
 
        self.assertEqual(result, set(['myfile-id']))
759
 
 
760
750
    def test_set_executability_order(self):
761
751
        """Ensure that executability behaves the same, no matter what order.
762
752
        
1172
1162
        transform.cancel_creation(parent)
1173
1163
        transform.finalize()
1174
1164
 
1175
 
    def test_change_entry(self):
1176
 
        txt = 'bzrlib.transform.change_entry was deprecated in version 0.90.'
1177
 
        self.callDeprecated([txt], change_entry, None, None, None, None, None,
1178
 
            None, None, None)
1179
 
 
1180
1165
    def test_case_insensitive_clash(self):
1181
1166
        self.requireFeature(CaseInsensitiveFilesystemFeature)
1182
1167
        def tt_helper():
1719
1704
        self.assertEqual([], list(target.iter_changes(revision_tree)))
1720
1705
        self.assertTrue(source.is_executable('file1-id'))
1721
1706
 
 
1707
    def test_case_insensitive_build_tree_inventory(self):
 
1708
        source = self.make_branch_and_tree('source')
 
1709
        self.build_tree(['source/file', 'source/FILE'])
 
1710
        source.add(['file', 'FILE'], ['lower-id', 'upper-id'])
 
1711
        source.commit('added files')
 
1712
        # Don't try this at home, kids!
 
1713
        # Force the tree to report that it is case insensitive
 
1714
        target = self.make_branch_and_tree('target')
 
1715
        target.case_sensitive = False
 
1716
        build_tree(source.basis_tree(), target, source, delta_from_tree=True)
 
1717
        self.assertEqual('file.moved', target.id2path('lower-id'))
 
1718
        self.assertEqual('FILE', target.id2path('upper-id'))
 
1719
 
1722
1720
 
1723
1721
class MockTransform(object):
1724
1722
 
2033
2031
        preview_tree = preview.get_preview_tree()
2034
2032
        self.assertEqual('target',
2035
2033
                         preview_tree.get_symlink_target('symlink-id'))
 
2034
 
 
2035
    def test_all_file_ids(self):
 
2036
        tree = self.make_branch_and_tree('tree')
 
2037
        self.build_tree(['tree/a', 'tree/b', 'tree/c'])
 
2038
        tree.add(['a', 'b', 'c'], ['a-id', 'b-id', 'c-id'])
 
2039
        preview = TransformPreview(tree)
 
2040
        self.addCleanup(preview.finalize)
 
2041
        preview.unversion_file(preview.trans_id_file_id('b-id'))
 
2042
        c_trans_id = preview.trans_id_file_id('c-id')
 
2043
        preview.unversion_file(c_trans_id)
 
2044
        preview.version_file('c-id', c_trans_id)
 
2045
        preview_tree = preview.get_preview_tree()
 
2046
        self.assertEqual(set(['a-id', 'c-id', tree.get_root_id()]),
 
2047
                         preview_tree.all_file_ids())
 
2048
 
 
2049
    def test_path2id_deleted_unchanged(self):
 
2050
        tree = self.make_branch_and_tree('tree')
 
2051
        self.build_tree(['tree/unchanged', 'tree/deleted'])
 
2052
        tree.add(['unchanged', 'deleted'], ['unchanged-id', 'deleted-id'])
 
2053
        preview = TransformPreview(tree)
 
2054
        self.addCleanup(preview.finalize)
 
2055
        preview.unversion_file(preview.trans_id_file_id('deleted-id'))
 
2056
        preview_tree = preview.get_preview_tree()
 
2057
        self.assertEqual('unchanged-id', preview_tree.path2id('unchanged'))
 
2058
        self.assertIs(None, preview_tree.path2id('deleted'))
 
2059
 
 
2060
    def test_path2id_created(self):
 
2061
        tree = self.make_branch_and_tree('tree')
 
2062
        self.build_tree(['tree/unchanged'])
 
2063
        tree.add(['unchanged'], ['unchanged-id'])
 
2064
        preview = TransformPreview(tree)
 
2065
        self.addCleanup(preview.finalize)
 
2066
        preview.new_file('new', preview.trans_id_file_id('unchanged-id'),
 
2067
            'contents', 'new-id')
 
2068
        preview_tree = preview.get_preview_tree()
 
2069
        self.assertEqual('new-id', preview_tree.path2id('unchanged/new'))
 
2070
 
 
2071
    def test_path2id_moved(self):
 
2072
        tree = self.make_branch_and_tree('tree')
 
2073
        self.build_tree(['tree/old_parent/', 'tree/old_parent/child'])
 
2074
        tree.add(['old_parent', 'old_parent/child'],
 
2075
                 ['old_parent-id', 'child-id'])
 
2076
        preview = TransformPreview(tree)
 
2077
        self.addCleanup(preview.finalize)
 
2078
        new_parent = preview.new_directory('new_parent', preview.root,
 
2079
                                           'new_parent-id')
 
2080
        preview.adjust_path('child', new_parent,
 
2081
                            preview.trans_id_file_id('child-id'))
 
2082
        preview_tree = preview.get_preview_tree()
 
2083
        self.assertIs(None, preview_tree.path2id('old_parent/child'))
 
2084
        self.assertEqual('child-id', preview_tree.path2id('new_parent/child'))
 
2085
 
 
2086
    def test_path2id_renamed_parent(self):
 
2087
        tree = self.make_branch_and_tree('tree')
 
2088
        self.build_tree(['tree/old_name/', 'tree/old_name/child'])
 
2089
        tree.add(['old_name', 'old_name/child'],
 
2090
                 ['parent-id', 'child-id'])
 
2091
        preview = TransformPreview(tree)
 
2092
        self.addCleanup(preview.finalize)
 
2093
        preview.adjust_path('new_name', preview.root,
 
2094
                            preview.trans_id_file_id('parent-id'))
 
2095
        preview_tree = preview.get_preview_tree()
 
2096
        self.assertIs(None, preview_tree.path2id('old_name/child'))
 
2097
        self.assertEqual('child-id', preview_tree.path2id('new_name/child'))
 
2098
 
 
2099
    def assertMatchingIterEntries(self, tt, specific_file_ids=None):
 
2100
        preview_tree = tt.get_preview_tree()
 
2101
        preview_result = list(preview_tree.iter_entries_by_dir(
 
2102
                              specific_file_ids))
 
2103
        tree = tt._tree
 
2104
        tt.apply()
 
2105
        actual_result = list(tree.iter_entries_by_dir(specific_file_ids))
 
2106
        self.assertEqual(actual_result, preview_result)
 
2107
 
 
2108
    def test_iter_entries_by_dir_new(self):
 
2109
        tree = self.make_branch_and_tree('tree')
 
2110
        tt = TreeTransform(tree)
 
2111
        tt.new_file('new', tt.root, 'contents', 'new-id')
 
2112
        self.assertMatchingIterEntries(tt)
 
2113
 
 
2114
    def test_iter_entries_by_dir_deleted(self):
 
2115
        tree = self.make_branch_and_tree('tree')
 
2116
        self.build_tree(['tree/deleted'])
 
2117
        tree.add('deleted', 'deleted-id')
 
2118
        tt = TreeTransform(tree)
 
2119
        tt.delete_contents(tt.trans_id_file_id('deleted-id'))
 
2120
        self.assertMatchingIterEntries(tt)
 
2121
 
 
2122
    def test_iter_entries_by_dir_unversioned(self):
 
2123
        tree = self.make_branch_and_tree('tree')
 
2124
        self.build_tree(['tree/removed'])
 
2125
        tree.add('removed', 'removed-id')
 
2126
        tt = TreeTransform(tree)
 
2127
        tt.unversion_file(tt.trans_id_file_id('removed-id'))
 
2128
        self.assertMatchingIterEntries(tt)
 
2129
 
 
2130
    def test_iter_entries_by_dir_moved(self):
 
2131
        tree = self.make_branch_and_tree('tree')
 
2132
        self.build_tree(['tree/moved', 'tree/new_parent/'])
 
2133
        tree.add(['moved', 'new_parent'], ['moved-id', 'new_parent-id'])
 
2134
        tt = TreeTransform(tree)
 
2135
        tt.adjust_path('moved', tt.trans_id_file_id('new_parent-id'),
 
2136
                       tt.trans_id_file_id('moved-id'))
 
2137
        self.assertMatchingIterEntries(tt)
 
2138
 
 
2139
    def test_iter_entries_by_dir_specific_file_ids(self):
 
2140
        tree = self.make_branch_and_tree('tree')
 
2141
        tree.set_root_id('tree-root-id')
 
2142
        self.build_tree(['tree/parent/', 'tree/parent/child'])
 
2143
        tree.add(['parent', 'parent/child'], ['parent-id', 'child-id'])
 
2144
        tt = TreeTransform(tree)
 
2145
        self.assertMatchingIterEntries(tt, ['tree-root-id', 'child-id'])
 
2146
 
 
2147
    def test_symlink_content_summary(self):
 
2148
        self.requireFeature(SymlinkFeature)
 
2149
        preview = self.get_empty_preview()
 
2150
        preview.new_symlink('path', preview.root, 'target', 'path-id')
 
2151
        summary = preview.get_preview_tree().path_content_summary('path')
 
2152
        self.assertEqual(('symlink', None, None, 'target'), summary)
 
2153
 
 
2154
    def test_missing_content_summary(self):
 
2155
        preview = self.get_empty_preview()
 
2156
        summary = preview.get_preview_tree().path_content_summary('path')
 
2157
        self.assertEqual(('missing', None, None, None), summary)
 
2158
 
 
2159
    def test_deleted_content_summary(self):
 
2160
        tree = self.make_branch_and_tree('tree')
 
2161
        self.build_tree(['tree/path/'])
 
2162
        tree.add('path')
 
2163
        preview = TransformPreview(tree)
 
2164
        self.addCleanup(preview.finalize)
 
2165
        preview.delete_contents(preview.trans_id_tree_path('path'))
 
2166
        summary = preview.get_preview_tree().path_content_summary('path')
 
2167
        self.assertEqual(('missing', None, None, None), summary)
 
2168
 
 
2169
    def test_file_content_summary_executable(self):
 
2170
        if not osutils.supports_executable():
 
2171
            raise TestNotApplicable()
 
2172
        preview = self.get_empty_preview()
 
2173
        path_id = preview.new_file('path', preview.root, 'contents', 'path-id')
 
2174
        preview.set_executability(True, path_id)
 
2175
        summary = preview.get_preview_tree().path_content_summary('path')
 
2176
        self.assertEqual(4, len(summary))
 
2177
        self.assertEqual('file', summary[0])
 
2178
        # size must be known
 
2179
        self.assertEqual(len('contents'), summary[1])
 
2180
        # executable
 
2181
        self.assertEqual(True, summary[2])
 
2182
        # will not have hash (not cheap to determine)
 
2183
        self.assertIs(None, summary[3])
 
2184
 
 
2185
    def test_change_executability(self):
 
2186
        if not osutils.supports_executable():
 
2187
            raise TestNotApplicable()
 
2188
        tree = self.make_branch_and_tree('tree')
 
2189
        self.build_tree(['tree/path'])
 
2190
        tree.add('path')
 
2191
        preview = TransformPreview(tree)
 
2192
        self.addCleanup(preview.finalize)
 
2193
        path_id = preview.trans_id_tree_path('path')
 
2194
        preview.set_executability(True, path_id)
 
2195
        summary = preview.get_preview_tree().path_content_summary('path')
 
2196
        self.assertEqual(True, summary[2])
 
2197
 
 
2198
    def test_file_content_summary_non_exec(self):
 
2199
        preview = self.get_empty_preview()
 
2200
        preview.new_file('path', preview.root, 'contents', 'path-id')
 
2201
        summary = preview.get_preview_tree().path_content_summary('path')
 
2202
        self.assertEqual(4, len(summary))
 
2203
        self.assertEqual('file', summary[0])
 
2204
        # size must be known
 
2205
        self.assertEqual(len('contents'), summary[1])
 
2206
        # not executable
 
2207
        if osutils.supports_executable():
 
2208
            self.assertEqual(False, summary[2])
 
2209
        else:
 
2210
            self.assertEqual(None, summary[2])
 
2211
        # will not have hash (not cheap to determine)
 
2212
        self.assertIs(None, summary[3])
 
2213
 
 
2214
    def test_dir_content_summary(self):
 
2215
        preview = self.get_empty_preview()
 
2216
        preview.new_directory('path', preview.root, 'path-id')
 
2217
        summary = preview.get_preview_tree().path_content_summary('path')
 
2218
        self.assertEqual(('directory', None, None, None), summary)
 
2219
 
 
2220
    def test_tree_content_summary(self):
 
2221
        preview = self.get_empty_preview()
 
2222
        path = preview.new_directory('path', preview.root, 'path-id')
 
2223
        preview.set_tree_reference('rev-1', path)
 
2224
        summary = preview.get_preview_tree().path_content_summary('path')
 
2225
        self.assertEqual(4, len(summary))
 
2226
        self.assertEqual('tree-reference', summary[0])
 
2227
 
 
2228
    def test_annotate(self):
 
2229
        tree = self.make_branch_and_tree('tree')
 
2230
        self.build_tree_contents([('tree/file', 'a\n')])
 
2231
        tree.add('file', 'file-id')
 
2232
        tree.commit('a', rev_id='one')
 
2233
        self.build_tree_contents([('tree/file', 'a\nb\n')])
 
2234
        preview = TransformPreview(tree)
 
2235
        self.addCleanup(preview.finalize)
 
2236
        file_trans_id = preview.trans_id_file_id('file-id')
 
2237
        preview.delete_contents(file_trans_id)
 
2238
        preview.create_file('a\nb\nc\n', file_trans_id)
 
2239
        preview_tree = preview.get_preview_tree()
 
2240
        expected = [
 
2241
            ('one', 'a\n'),
 
2242
            ('me:', 'b\n'),
 
2243
            ('me:', 'c\n'),
 
2244
        ]
 
2245
        annotation = preview_tree.annotate_iter('file-id', 'me:')
 
2246
        self.assertEqual(expected, annotation)
 
2247
 
 
2248
    def test_annotate_missing(self):
 
2249
        preview = self.get_empty_preview()
 
2250
        preview.new_file('file', preview.root, 'a\nb\nc\n', 'file-id')
 
2251
        preview_tree = preview.get_preview_tree()
 
2252
        expected = [
 
2253
            ('me:', 'a\n'),
 
2254
            ('me:', 'b\n'),
 
2255
            ('me:', 'c\n'),
 
2256
         ]
 
2257
        annotation = preview_tree.annotate_iter('file-id', 'me:')
 
2258
        self.assertEqual(expected, annotation)
 
2259
 
 
2260
    def test_annotate_rename(self):
 
2261
        tree = self.make_branch_and_tree('tree')
 
2262
        self.build_tree_contents([('tree/file', 'a\n')])
 
2263
        tree.add('file', 'file-id')
 
2264
        tree.commit('a', rev_id='one')
 
2265
        preview = TransformPreview(tree)
 
2266
        self.addCleanup(preview.finalize)
 
2267
        file_trans_id = preview.trans_id_file_id('file-id')
 
2268
        preview.adjust_path('newname', preview.root, file_trans_id)
 
2269
        preview_tree = preview.get_preview_tree()
 
2270
        expected = [
 
2271
            ('one', 'a\n'),
 
2272
        ]
 
2273
        annotation = preview_tree.annotate_iter('file-id', 'me:')
 
2274
        self.assertEqual(expected, annotation)
 
2275
 
 
2276
    def test_annotate_deleted(self):
 
2277
        tree = self.make_branch_and_tree('tree')
 
2278
        self.build_tree_contents([('tree/file', 'a\n')])
 
2279
        tree.add('file', 'file-id')
 
2280
        tree.commit('a', rev_id='one')
 
2281
        self.build_tree_contents([('tree/file', 'a\nb\n')])
 
2282
        preview = TransformPreview(tree)
 
2283
        self.addCleanup(preview.finalize)
 
2284
        file_trans_id = preview.trans_id_file_id('file-id')
 
2285
        preview.delete_contents(file_trans_id)
 
2286
        preview_tree = preview.get_preview_tree()
 
2287
        annotation = preview_tree.annotate_iter('file-id', 'me:')
 
2288
        self.assertIs(None, annotation)
 
2289
 
 
2290
    def test_stored_kind(self):
 
2291
        preview = self.get_empty_preview()
 
2292
        preview.new_file('file', preview.root, 'a\nb\nc\n', 'file-id')
 
2293
        preview_tree = preview.get_preview_tree()
 
2294
        self.assertEqual('file', preview_tree.stored_kind('file-id'))
 
2295
 
 
2296
    def test_is_executable(self):
 
2297
        preview = self.get_empty_preview()
 
2298
        preview.new_file('file', preview.root, 'a\nb\nc\n', 'file-id')
 
2299
        preview.set_executability(True, preview.trans_id_file_id('file-id'))
 
2300
        preview_tree = preview.get_preview_tree()
 
2301
        self.assertEqual(True, preview_tree.is_executable('file-id'))