~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_transform.py

  • Committer: Mark Hammond
  • Date: 2008-08-10 11:16:39 UTC
  • mto: (3606.5.3 1.6)
  • mto: This revision was merged to the branch mainline in revision 3626.
  • Revision ID: mhammond@skippinet.com.au-20080810111639-9upz1wig1s8lvz62
install all files with 'restartreplace uninsrestartdelete' and close
tbzrcache at uninstall time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
 
18
import stat
18
19
from StringIO import StringIO
19
20
import sys
20
 
import time
21
21
 
22
22
from bzrlib import (
23
 
    bencode,
24
23
    errors,
25
 
    filters,
26
24
    generate_ids,
27
25
    osutils,
28
26
    progress,
29
27
    revision as _mod_revision,
30
 
    rules,
 
28
    symbol_versioning,
31
29
    tests,
32
30
    urlutils,
33
31
    )
37
35
                              NonDirectoryParent)
38
36
from bzrlib.diff import show_diff_trees
39
37
from bzrlib.errors import (DuplicateKey, MalformedTransform, NoSuchFile,
40
 
                           ReusingTransform, CantMoveRoot,
 
38
                           ReusingTransform, CantMoveRoot, 
41
39
                           PathsNotVersionedError, ExistingLimbo,
42
40
                           ExistingPendingDeletion, ImmortalLimbo,
43
41
                           ImmortalPendingDeletion, LockError)
44
42
from bzrlib.osutils import file_kind, pathjoin
45
 
from bzrlib.merge import Merge3Merger, Merger
 
43
from bzrlib.merge import Merge3Merger
46
44
from bzrlib.tests import (
 
45
    CaseInsensitiveFilesystemFeature,
47
46
    HardlinkFeature,
48
47
    SymlinkFeature,
49
48
    TestCase,
50
49
    TestCaseInTempDir,
51
50
    TestSkipped,
52
51
    )
53
 
from bzrlib.transform import (TreeTransform, ROOT_PARENT, FinalPaths,
54
 
                              resolve_conflicts, cook_conflicts,
 
52
from bzrlib.transform import (TreeTransform, ROOT_PARENT, FinalPaths, 
 
53
                              resolve_conflicts, cook_conflicts, 
55
54
                              build_tree, get_backup_name,
56
55
                              _FileMover, resolve_checkout,
57
 
                              TransformPreview, create_from_tree)
58
 
 
 
56
                              TransformPreview)
59
57
 
60
58
class TestTreeTransform(tests.TestCaseWithTransport):
61
59
 
130
128
        self.assertIs(self.wt.is_executable('my_pretties2'), False)
131
129
        self.assertEqual('directory', file_kind(self.wt.abspath('oz')))
132
130
        self.assertEqual(len(modified_paths), 3)
133
 
        tree_mod_paths = [self.wt.id2abspath(f) for f in
 
131
        tree_mod_paths = [self.wt.id2abspath(f) for f in 
134
132
                          ('ozzie', 'my_pretties', 'my_pretties2')]
135
133
        self.assertSubset(tree_mod_paths, modified_paths)
136
134
        # is it safe to finalize repeatedly?
137
135
        transform.finalize()
138
136
        transform.finalize()
139
137
 
140
 
    def test_create_files_same_timestamp(self):
141
 
        transform, root = self.get_transform()
142
 
        self.wt.lock_tree_write()
143
 
        self.addCleanup(self.wt.unlock)
144
 
        # Roll back the clock, so that we know everything is being set to the
145
 
        # exact time
146
 
        transform._creation_mtime = creation_mtime = time.time() - 20.0
147
 
        transform.create_file('content-one',
148
 
                              transform.create_path('one', root))
149
 
        time.sleep(1) # *ugly*
150
 
        transform.create_file('content-two',
151
 
                              transform.create_path('two', root))
152
 
        transform.apply()
153
 
        fo, st1 = self.wt.get_file_with_stat(None, path='one', filtered=False)
154
 
        fo.close()
155
 
        fo, st2 = self.wt.get_file_with_stat(None, path='two', filtered=False)
156
 
        fo.close()
157
 
        # We only guarantee 2s resolution
158
 
        self.assertTrue(abs(creation_mtime - st1.st_mtime) < 2.0,
159
 
            "%s != %s within 2 seconds" % (creation_mtime, st1.st_mtime))
160
 
        # But if we have more than that, all files should get the same result
161
 
        self.assertEqual(st1.st_mtime, st2.st_mtime)
162
 
 
163
 
    def test_change_root_id(self):
164
 
        transform, root = self.get_transform()
165
 
        self.assertNotEqual('new-root-id', self.wt.get_root_id())
166
 
        transform.new_directory('', ROOT_PARENT, 'new-root-id')
167
 
        transform.delete_contents(root)
168
 
        transform.unversion_file(root)
169
 
        transform.fixup_new_roots()
170
 
        transform.apply()
171
 
        self.assertEqual('new-root-id', self.wt.get_root_id())
172
 
 
173
 
    def test_change_root_id_add_files(self):
174
 
        transform, root = self.get_transform()
175
 
        self.assertNotEqual('new-root-id', self.wt.get_root_id())
176
 
        new_trans_id = transform.new_directory('', ROOT_PARENT, 'new-root-id')
177
 
        transform.new_file('file', new_trans_id, ['new-contents\n'],
178
 
                           'new-file-id')
179
 
        transform.delete_contents(root)
180
 
        transform.unversion_file(root)
181
 
        transform.fixup_new_roots()
182
 
        transform.apply()
183
 
        self.assertEqual('new-root-id', self.wt.get_root_id())
184
 
        self.assertEqual('new-file-id', self.wt.path2id('file'))
185
 
        self.assertFileEqual('new-contents\n', self.wt.abspath('file'))
186
 
 
187
 
    def test_add_two_roots(self):
188
 
        transform, root = self.get_transform()
189
 
        new_trans_id = transform.new_directory('', ROOT_PARENT, 'new-root-id')
190
 
        new_trans_id = transform.new_directory('', ROOT_PARENT, 'alt-root-id')
191
 
        self.assertRaises(ValueError, transform.fixup_new_roots)
192
 
 
193
138
    def test_hardlink(self):
194
139
        self.requireFeature(HardlinkFeature)
195
140
        transform, root = self.get_transform()
209
154
        transform, root = self.get_transform()
210
155
        self.wt.lock_tree_write()
211
156
        self.addCleanup(self.wt.unlock)
212
 
        trans_id = transform.new_file('name', root, 'contents',
 
157
        trans_id = transform.new_file('name', root, 'contents', 
213
158
                                      'my_pretties', True)
214
159
        oz = transform.new_directory('oz', root, 'oz-id')
215
160
        dorothy = transform.new_directory('dorothy', oz, 'dorothy-id')
216
 
        toto = transform.new_file('toto', dorothy, 'toto-contents',
 
161
        toto = transform.new_file('toto', dorothy, 'toto-contents', 
217
162
                                  'toto-id', False)
218
163
 
219
164
        self.assertEqual(len(transform.find_conflicts()), 0)
243
188
 
244
189
    def test_conflicts(self):
245
190
        transform, root = self.get_transform()
246
 
        trans_id = transform.new_file('name', root, 'contents',
 
191
        trans_id = transform.new_file('name', root, 'contents', 
247
192
                                      'my_pretties')
248
193
        self.assertEqual(len(transform.find_conflicts()), 0)
249
194
        trans_id2 = transform.new_file('name', root, 'Crontents', 'toto')
250
 
        self.assertEqual(transform.find_conflicts(),
 
195
        self.assertEqual(transform.find_conflicts(), 
251
196
                         [('duplicate', trans_id, trans_id2, 'name')])
252
197
        self.assertRaises(MalformedTransform, transform.apply)
253
198
        transform.adjust_path('name', trans_id, trans_id2)
254
 
        self.assertEqual(transform.find_conflicts(),
 
199
        self.assertEqual(transform.find_conflicts(), 
255
200
                         [('non-directory parent', trans_id)])
256
201
        tinman_id = transform.trans_id_tree_path('tinman')
257
202
        transform.adjust_path('name', tinman_id, trans_id2)
258
 
        self.assertEqual(transform.find_conflicts(),
259
 
                         [('unversioned parent', tinman_id),
 
203
        self.assertEqual(transform.find_conflicts(), 
 
204
                         [('unversioned parent', tinman_id), 
260
205
                          ('missing parent', tinman_id)])
261
206
        lion_id = transform.create_path('lion', root)
262
 
        self.assertEqual(transform.find_conflicts(),
263
 
                         [('unversioned parent', tinman_id),
 
207
        self.assertEqual(transform.find_conflicts(), 
 
208
                         [('unversioned parent', tinman_id), 
264
209
                          ('missing parent', tinman_id)])
265
210
        transform.adjust_path('name', lion_id, trans_id2)
266
 
        self.assertEqual(transform.find_conflicts(),
 
211
        self.assertEqual(transform.find_conflicts(), 
267
212
                         [('unversioned parent', lion_id),
268
213
                          ('missing parent', lion_id)])
269
214
        transform.version_file("Courage", lion_id)
270
 
        self.assertEqual(transform.find_conflicts(),
271
 
                         [('missing parent', lion_id),
 
215
        self.assertEqual(transform.find_conflicts(), 
 
216
                         [('missing parent', lion_id), 
272
217
                          ('versioning no contents', lion_id)])
273
218
        transform.adjust_path('name2', root, trans_id2)
274
 
        self.assertEqual(transform.find_conflicts(),
 
219
        self.assertEqual(transform.find_conflicts(), 
275
220
                         [('versioning no contents', lion_id)])
276
221
        transform.create_file('Contents, okay?', lion_id)
277
222
        transform.adjust_path('name2', trans_id2, trans_id2)
278
 
        self.assertEqual(transform.find_conflicts(),
279
 
                         [('parent loop', trans_id2),
 
223
        self.assertEqual(transform.find_conflicts(), 
 
224
                         [('parent loop', trans_id2), 
280
225
                          ('non-directory parent', trans_id2)])
281
226
        transform.adjust_path('name2', root, trans_id2)
282
227
        oz_id = transform.new_directory('oz', root)
283
228
        transform.set_executability(True, oz_id)
284
 
        self.assertEqual(transform.find_conflicts(),
 
229
        self.assertEqual(transform.find_conflicts(), 
285
230
                         [('unversioned executability', oz_id)])
286
231
        transform.version_file('oz-id', oz_id)
287
 
        self.assertEqual(transform.find_conflicts(),
 
232
        self.assertEqual(transform.find_conflicts(), 
288
233
                         [('non-file executability', oz_id)])
289
234
        transform.set_executability(None, oz_id)
290
235
        tip_id = transform.new_file('tip', oz_id, 'ozma', 'tip-id')
299
244
        self.assert_('oz/tip' in transform2._tree_path_ids)
300
245
        self.assertEqual(fp.get_path(newtip), pathjoin('oz', 'tip'))
301
246
        self.assertEqual(len(result), 2)
302
 
        self.assertEqual((result[0][0], result[0][1]),
 
247
        self.assertEqual((result[0][0], result[0][1]), 
303
248
                         ('duplicate', newtip))
304
 
        self.assertEqual((result[1][0], result[1][2]),
 
249
        self.assertEqual((result[1][0], result[1][2]), 
305
250
                         ('duplicate id', newtip))
306
251
        transform2.finalize()
307
252
        transform3 = TreeTransform(self.wt)
308
253
        self.addCleanup(transform3.finalize)
309
254
        oz_id = transform3.trans_id_tree_file_id('oz-id')
310
255
        transform3.delete_contents(oz_id)
311
 
        self.assertEqual(transform3.find_conflicts(),
 
256
        self.assertEqual(transform3.find_conflicts(), 
312
257
                         [('missing parent', oz_id)])
313
258
        root_id = transform3.root
314
259
        tip_id = transform3.trans_id_tree_file_id('tip-id')
423
368
        self.assertContainsRe(transform._limbo_name(first), 'new-1/file')
424
369
        self.assertNotContainsRe(transform._limbo_name(second), 'new-1/FiLe')
425
370
 
426
 
    def test_adjust_path_updates_child_limbo_names(self):
427
 
        tree = self.make_branch_and_tree('tree')
428
 
        transform = TreeTransform(tree)
429
 
        self.addCleanup(transform.finalize)
430
 
        foo_id = transform.new_directory('foo', transform.root)
431
 
        bar_id = transform.new_directory('bar', foo_id)
432
 
        baz_id = transform.new_directory('baz', bar_id)
433
 
        qux_id = transform.new_directory('qux', baz_id)
434
 
        transform.adjust_path('quxx', foo_id, bar_id)
435
 
        self.assertStartsWith(transform._limbo_name(qux_id),
436
 
                              transform._limbo_name(bar_id))
437
 
 
438
371
    def test_add_del(self):
439
372
        start, root = self.get_transform()
440
373
        start.new_directory('a', root, 'a')
453
386
        self.addCleanup(unversion.finalize)
454
387
        parent = unversion.trans_id_tree_path('parent')
455
388
        unversion.unversion_file(parent)
456
 
        self.assertEqual(unversion.find_conflicts(),
 
389
        self.assertEqual(unversion.find_conflicts(), 
457
390
                         [('unversioned parent', parent_id)])
458
391
        file_id = unversion.trans_id_tree_file_id('child-id')
459
392
        unversion.unversion_file(file_id)
479
412
        mangle_tree.adjust_path('name2', root, name1)
480
413
        mangle_tree.adjust_path('name1', root, name2)
481
414
 
482
 
        #tests for deleting parent directories
 
415
        #tests for deleting parent directories 
483
416
        ddir = mangle_tree.trans_id_tree_file_id('ddir')
484
417
        mangle_tree.delete_contents(ddir)
485
418
        dfile = mangle_tree.trans_id_tree_file_id('dfile')
514
447
        create_tree,root = self.get_transform()
515
448
        newdir = create_tree.new_directory('selftest', root, 'selftest-id')
516
449
        create_tree.new_file('blackbox.py', newdir, 'hello1', 'blackbox-id')
517
 
        create_tree.apply()
 
450
        create_tree.apply()        
518
451
        mangle_tree,root = self.get_transform()
519
452
        selftest = mangle_tree.trans_id_tree_file_id('selftest-id')
520
453
        blackbox = mangle_tree.trans_id_tree_file_id('blackbox-id')
528
461
        bzrlib = create_tree.new_directory('bzrlib', root, 'bzrlib-id')
529
462
        tests = create_tree.new_directory('tests', bzrlib, 'tests-id')
530
463
        blackbox = create_tree.new_directory('blackbox', tests, 'blackbox-id')
531
 
        create_tree.new_file('test_too_much.py', blackbox, 'hello1',
 
464
        create_tree.new_file('test_too_much.py', blackbox, 'hello1', 
532
465
                             'test_too_much-id')
533
 
        create_tree.apply()
 
466
        create_tree.apply()        
534
467
        mangle_tree,root = self.get_transform()
535
468
        bzrlib = mangle_tree.trans_id_tree_file_id('bzrlib-id')
536
469
        tests = mangle_tree.trans_id_tree_file_id('tests-id')
537
470
        test_too_much = mangle_tree.trans_id_tree_file_id('test_too_much-id')
538
471
        mangle_tree.adjust_path('selftest', bzrlib, tests)
539
 
        mangle_tree.adjust_path('blackbox.py', tests, test_too_much)
 
472
        mangle_tree.adjust_path('blackbox.py', tests, test_too_much) 
540
473
        mangle_tree.set_executability(True, test_too_much)
541
474
        mangle_tree.apply()
542
475
 
543
476
    def test_both_rename3(self):
544
477
        create_tree,root = self.get_transform()
545
478
        tests = create_tree.new_directory('tests', root, 'tests-id')
546
 
        create_tree.new_file('test_too_much.py', tests, 'hello1',
 
479
        create_tree.new_file('test_too_much.py', tests, 'hello1', 
547
480
                             'test_too_much-id')
548
 
        create_tree.apply()
 
481
        create_tree.apply()        
549
482
        mangle_tree,root = self.get_transform()
550
483
        tests = mangle_tree.trans_id_tree_file_id('tests-id')
551
484
        test_too_much = mangle_tree.trans_id_tree_file_id('test_too_much-id')
552
485
        mangle_tree.adjust_path('selftest', root, tests)
553
 
        mangle_tree.adjust_path('blackbox.py', tests, test_too_much)
 
486
        mangle_tree.adjust_path('blackbox.py', tests, test_too_much) 
554
487
        mangle_tree.set_executability(True, test_too_much)
555
488
        mangle_tree.apply()
556
489
 
569
502
        newdir = move_id.new_directory('dir', root, 'newdir')
570
503
        move_id.adjust_path('name2', newdir, name1)
571
504
        move_id.apply()
572
 
 
 
505
        
573
506
    def test_replace_dangling_ie(self):
574
507
        create_tree, root = self.get_transform()
575
508
        # prepare tree
591
524
        resolve_conflicts(replace)
592
525
        replace.apply()
593
526
 
594
 
    def _test_symlinks(self, link_name1,link_target1,
595
 
                       link_name2, link_target2):
596
 
 
597
 
        def ozpath(p): return 'oz/' + p
598
 
 
 
527
    def test_symlinks(self):
599
528
        self.requireFeature(SymlinkFeature)
600
 
        transform, root = self.get_transform()
 
529
        transform,root = self.get_transform()
601
530
        oz_id = transform.new_directory('oz', root, 'oz-id')
602
 
        wizard = transform.new_symlink(link_name1, oz_id, link_target1,
 
531
        wizard = transform.new_symlink('wizard', oz_id, 'wizard-target', 
603
532
                                       'wizard-id')
604
 
        wiz_id = transform.create_path(link_name2, oz_id)
605
 
        transform.create_symlink(link_target2, wiz_id)
606
 
        transform.version_file('wiz-id2', wiz_id)
 
533
        wiz_id = transform.create_path('wizard2', oz_id)
 
534
        transform.create_symlink('behind_curtain', wiz_id)
 
535
        transform.version_file('wiz-id2', wiz_id)            
607
536
        transform.set_executability(True, wiz_id)
608
 
        self.assertEqual(transform.find_conflicts(),
 
537
        self.assertEqual(transform.find_conflicts(), 
609
538
                         [('non-file executability', wiz_id)])
610
539
        transform.set_executability(None, wiz_id)
611
540
        transform.apply()
612
 
        self.assertEqual(self.wt.path2id(ozpath(link_name1)), 'wizard-id')
613
 
        self.assertEqual('symlink',
614
 
                         file_kind(self.wt.abspath(ozpath(link_name1))))
615
 
        self.assertEqual(link_target2,
616
 
                         osutils.readlink(self.wt.abspath(ozpath(link_name2))))
617
 
        self.assertEqual(link_target1,
618
 
                         osutils.readlink(self.wt.abspath(ozpath(link_name1))))
619
 
 
620
 
    def test_symlinks(self):
621
 
        self._test_symlinks('wizard', 'wizard-target',
622
 
                            'wizard2', 'behind_curtain')
623
 
 
624
 
    def test_symlinks_unicode(self):
625
 
        self.requireFeature(tests.UnicodeFilenameFeature)
626
 
        self._test_symlinks(u'\N{Euro Sign}wizard',
627
 
                            u'wizard-targ\N{Euro Sign}t',
628
 
                            u'\N{Euro Sign}wizard2',
629
 
                            u'b\N{Euro Sign}hind_curtain')
 
541
        self.assertEqual(self.wt.path2id('oz/wizard'), 'wizard-id')
 
542
        self.assertEqual(file_kind(self.wt.abspath('oz/wizard')), 'symlink')
 
543
        self.assertEqual(os.readlink(self.wt.abspath('oz/wizard2')), 
 
544
                         'behind_curtain')
 
545
        self.assertEqual(os.readlink(self.wt.abspath('oz/wizard')),
 
546
                         'wizard-target')
630
547
 
631
548
    def test_unable_create_symlink(self):
632
549
        def tt_helper():
656
573
        create.apply()
657
574
        conflicts,root = self.get_transform()
658
575
        # set up duplicate entry, duplicate id
659
 
        new_dorothy = conflicts.new_file('dorothy', root, 'dorothy',
 
576
        new_dorothy = conflicts.new_file('dorothy', root, 'dorothy', 
660
577
                                         'dorothy-id')
661
578
        old_dorothy = conflicts.trans_id_tree_file_id('dorothy-id')
662
579
        oz = conflicts.trans_id_tree_file_id('oz-id')
686
603
        tt, emerald, oz, old_dorothy, new_dorothy = self.get_conflicted()
687
604
        raw_conflicts = resolve_conflicts(tt)
688
605
        cooked_conflicts = cook_conflicts(raw_conflicts, tt)
689
 
        duplicate = DuplicateEntry('Moved existing file to', 'dorothy.moved',
 
606
        duplicate = DuplicateEntry('Moved existing file to', 'dorothy.moved', 
690
607
                                   'dorothy', None, 'dorothy-id')
691
608
        self.assertEqual(cooked_conflicts[0], duplicate)
692
 
        duplicate_id = DuplicateID('Unversioned existing file',
 
609
        duplicate_id = DuplicateID('Unversioned existing file', 
693
610
                                   'dorothy.moved', 'dorothy', None,
694
611
                                   'dorothy-id')
695
612
        self.assertEqual(cooked_conflicts[1], duplicate_id)
703
620
        unversioned_parent2 = UnversionedParent('Versioned directory', 'oz',
704
621
                                               'oz-id')
705
622
        self.assertEqual(cooked_conflicts[3], unversioned_parent)
706
 
        parent_loop = ParentLoop('Cancelled move', 'oz/emeraldcity',
 
623
        parent_loop = ParentLoop('Cancelled move', 'oz/emeraldcity', 
707
624
                                 'oz/emeraldcity', 'emerald-id', 'emerald-id')
708
625
        self.assertEqual(cooked_conflicts[4], deleted_parent)
709
626
        self.assertEqual(cooked_conflicts[5], unversioned_parent2)
812
729
        create.apply()
813
730
        transform, root = self.get_transform()
814
731
        transform.adjust_root_path('oldroot', fun)
815
 
        new_root = transform.trans_id_tree_path('')
 
732
        new_root=transform.trans_id_tree_path('')
816
733
        transform.version_file('new-root', new_root)
817
734
        transform.apply()
818
735
 
832
749
 
833
750
    def test_set_executability_order(self):
834
751
        """Ensure that executability behaves the same, no matter what order.
835
 
 
 
752
        
836
753
        - create file and set executability simultaneously
837
754
        - create file and set executability afterward
838
755
        - unsetting the executability of a file whose executability has not been
1245
1162
        transform.cancel_creation(parent)
1246
1163
        transform.finalize()
1247
1164
 
1248
 
    def test_rollback_on_directory_clash(self):
 
1165
    def test_case_insensitive_clash(self):
 
1166
        self.requireFeature(CaseInsensitiveFilesystemFeature)
1249
1167
        def tt_helper():
1250
1168
            wt = self.make_branch_and_tree('.')
1251
1169
            tt = TreeTransform(wt)  # TreeTransform obtains write lock
1252
1170
            try:
1253
 
                foo = tt.new_directory('foo', tt.root)
1254
 
                tt.new_file('bar', foo, 'foobar')
1255
 
                baz = tt.new_directory('baz', tt.root)
1256
 
                tt.new_file('qux', baz, 'quux')
1257
 
                # Ask for a rename 'foo' -> 'baz'
1258
 
                tt.adjust_path('baz', tt.root, foo)
 
1171
                tt.new_file('foo', tt.root, 'bar')
 
1172
                tt.new_file('Foo', tt.root, 'spam')
1259
1173
                # Lie to tt that we've already resolved all conflicts.
1260
1174
                tt.apply(no_conflicts=True)
1261
1175
            except:
1262
1176
                wt.unlock()
1263
1177
                raise
1264
 
        # The rename will fail because the target directory is not empty (but
1265
 
        # raises FileExists anyway).
1266
1178
        err = self.assertRaises(errors.FileExists, tt_helper)
1267
1179
        self.assertContainsRe(str(err),
1268
 
            "^File exists: .+/baz")
 
1180
            "^File exists: .+/foo")
1269
1181
 
1270
1182
    def test_two_directories_clash(self):
1271
1183
        def tt_helper():
1274
1186
            try:
1275
1187
                foo_1 = tt.new_directory('foo', tt.root)
1276
1188
                tt.new_directory('bar', foo_1)
1277
 
                # Adding the same directory with a different content
1278
1189
                foo_2 = tt.new_directory('foo', tt.root)
1279
1190
                tt.new_directory('baz', foo_2)
1280
1191
                # Lie to tt that we've already resolved all conflicts.
1293
1204
            try:
1294
1205
                foo_1 = tt.new_directory('foo', tt.root)
1295
1206
                tt.new_directory('bar', foo_1)
1296
 
                # Adding the same directory with a different content
1297
1207
                foo_2 = tt.new_directory('foo', tt.root)
1298
1208
                tt.new_directory('baz', foo_2)
1299
1209
                # Lie to tt that we've already resolved all conflicts.
1309
1219
        wt = self.make_branch_and_tree('.')
1310
1220
        self.build_tree(['foo'])
1311
1221
        wt.add(['foo'])
1312
 
        wt.commit("one")
1313
1222
        tt = TreeTransform(wt)
1314
1223
        self.addCleanup(tt.finalize)
1315
1224
        foo_trans_id = tt.trans_id_tree_path("foo")
1320
1229
        tt.version_file("bar-1", bar_trans_id)
1321
1230
        tt.apply()
1322
1231
        self.failUnlessExists("foo/bar")
1323
 
        wt.lock_read()
1324
 
        try:
1325
 
            self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1326
 
                    "directory")
1327
 
        finally:
1328
 
            wt.unlock()
1329
 
        wt.commit("two")
1330
 
        changes = wt.changes_from(wt.basis_tree())
1331
 
        self.assertFalse(changes.has_changed(), changes)
1332
 
 
1333
 
    def test_file_to_symlink(self):
1334
 
        self.requireFeature(SymlinkFeature)
1335
 
        wt = self.make_branch_and_tree('.')
1336
 
        self.build_tree(['foo'])
1337
 
        wt.add(['foo'])
1338
 
        wt.commit("one")
1339
 
        tt = TreeTransform(wt)
1340
 
        self.addCleanup(tt.finalize)
1341
 
        foo_trans_id = tt.trans_id_tree_path("foo")
1342
 
        tt.delete_contents(foo_trans_id)
1343
 
        tt.create_symlink("bar", foo_trans_id)
1344
 
        tt.apply()
1345
 
        self.failUnlessExists("foo")
1346
 
        wt.lock_read()
1347
 
        self.addCleanup(wt.unlock)
1348
 
        self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1349
 
                "symlink")
1350
 
 
1351
 
    def test_dir_to_file(self):
1352
 
        wt = self.make_branch_and_tree('.')
1353
 
        self.build_tree(['foo/', 'foo/bar'])
1354
 
        wt.add(['foo', 'foo/bar'])
1355
 
        wt.commit("one")
1356
 
        tt = TreeTransform(wt)
1357
 
        self.addCleanup(tt.finalize)
1358
 
        foo_trans_id = tt.trans_id_tree_path("foo")
1359
 
        bar_trans_id = tt.trans_id_tree_path("foo/bar")
1360
 
        tt.delete_contents(foo_trans_id)
1361
 
        tt.delete_versioned(bar_trans_id)
1362
 
        tt.create_file(["aa\n"], foo_trans_id)
1363
 
        tt.apply()
1364
 
        self.failUnlessExists("foo")
1365
 
        wt.lock_read()
1366
 
        self.addCleanup(wt.unlock)
1367
 
        self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1368
 
                "file")
1369
 
 
1370
 
    def test_dir_to_hardlink(self):
1371
 
        self.requireFeature(HardlinkFeature)
1372
 
        wt = self.make_branch_and_tree('.')
1373
 
        self.build_tree(['foo/', 'foo/bar'])
1374
 
        wt.add(['foo', 'foo/bar'])
1375
 
        wt.commit("one")
1376
 
        tt = TreeTransform(wt)
1377
 
        self.addCleanup(tt.finalize)
1378
 
        foo_trans_id = tt.trans_id_tree_path("foo")
1379
 
        bar_trans_id = tt.trans_id_tree_path("foo/bar")
1380
 
        tt.delete_contents(foo_trans_id)
1381
 
        tt.delete_versioned(bar_trans_id)
1382
 
        self.build_tree(['baz'])
1383
 
        tt.create_hardlink("baz", foo_trans_id)
1384
 
        tt.apply()
1385
 
        self.failUnlessExists("foo")
1386
 
        self.failUnlessExists("baz")
1387
 
        wt.lock_read()
1388
 
        self.addCleanup(wt.unlock)
1389
 
        self.assertEqual(wt.inventory.get_file_kind(wt.path2id("foo")),
1390
 
                "file")
1391
 
 
1392
 
    def test_no_final_path(self):
1393
 
        transform, root = self.get_transform()
1394
 
        trans_id = transform.trans_id_file_id('foo')
1395
 
        transform.create_file('bar', trans_id)
1396
 
        transform.cancel_creation(trans_id)
1397
 
        transform.apply()
1398
 
 
1399
 
    def test_create_from_tree(self):
1400
 
        tree1 = self.make_branch_and_tree('tree1')
1401
 
        self.build_tree_contents([('tree1/foo/',), ('tree1/bar', 'baz')])
1402
 
        tree1.add(['foo', 'bar'], ['foo-id', 'bar-id'])
1403
 
        tree2 = self.make_branch_and_tree('tree2')
1404
 
        tt = TreeTransform(tree2)
1405
 
        foo_trans_id = tt.create_path('foo', tt.root)
1406
 
        create_from_tree(tt, foo_trans_id, tree1, 'foo-id')
1407
 
        bar_trans_id = tt.create_path('bar', tt.root)
1408
 
        create_from_tree(tt, bar_trans_id, tree1, 'bar-id')
1409
 
        tt.apply()
1410
 
        self.assertEqual('directory', osutils.file_kind('tree2/foo'))
1411
 
        self.assertFileEqual('baz', 'tree2/bar')
1412
 
 
1413
 
    def test_create_from_tree_bytes(self):
1414
 
        """Provided lines are used instead of tree content."""
1415
 
        tree1 = self.make_branch_and_tree('tree1')
1416
 
        self.build_tree_contents([('tree1/foo', 'bar'),])
1417
 
        tree1.add('foo', 'foo-id')
1418
 
        tree2 = self.make_branch_and_tree('tree2')
1419
 
        tt = TreeTransform(tree2)
1420
 
        foo_trans_id = tt.create_path('foo', tt.root)
1421
 
        create_from_tree(tt, foo_trans_id, tree1, 'foo-id', bytes='qux')
1422
 
        tt.apply()
1423
 
        self.assertFileEqual('qux', 'tree2/foo')
1424
 
 
1425
 
    def test_create_from_tree_symlink(self):
1426
 
        self.requireFeature(SymlinkFeature)
1427
 
        tree1 = self.make_branch_and_tree('tree1')
1428
 
        os.symlink('bar', 'tree1/foo')
1429
 
        tree1.add('foo', 'foo-id')
1430
 
        tt = TreeTransform(self.make_branch_and_tree('tree2'))
1431
 
        foo_trans_id = tt.create_path('foo', tt.root)
1432
 
        create_from_tree(tt, foo_trans_id, tree1, 'foo-id')
1433
 
        tt.apply()
1434
 
        self.assertEqual('bar', os.readlink('tree2/foo'))
1435
1232
 
1436
1233
 
1437
1234
class TransformGroup(object):
1492
1289
        # textual merge
1493
1290
        self.assertEqual(this.wt.get_file('a').read(), 'y\nb\nc\nd\bz\n')
1494
1291
        # three-way text conflict
1495
 
        self.assertEqual(this.wt.get_file('b').read(),
 
1292
        self.assertEqual(this.wt.get_file('b').read(), 
1496
1293
                         conflict_text('b', 'b2'))
1497
1294
        # OTHER wins
1498
1295
        self.assertEqual(this.wt.get_file('c').read(), 'c2')
1502
1299
        self.assertEqual(this.wt.get_file('e').read(), 'e2')
1503
1300
        # No change
1504
1301
        self.assertEqual(this.wt.get_file('f').read(), 'f')
1505
 
        # Correct correct results when THIS == OTHER
 
1302
        # Correct correct results when THIS == OTHER 
1506
1303
        self.assertEqual(this.wt.get_file('g').read(), 'g')
1507
1304
        # Text conflict when THIS & OTHER are text and BASE is dir
1508
 
        self.assertEqual(this.wt.get_file('h').read(),
 
1305
        self.assertEqual(this.wt.get_file('h').read(), 
1509
1306
                         conflict_text('1\n2\n3\n4\n', 'h\ni\nj\nk\n'))
1510
1307
        self.assertEqual(this.wt.get_file_byname('h.THIS').read(),
1511
1308
                         '1\n2\n3\n4\n')
1512
1309
        self.assertEqual(this.wt.get_file_byname('h.OTHER').read(),
1513
1310
                         'h\ni\nj\nk\n')
1514
1311
        self.assertEqual(file_kind(this.wt.abspath('h.BASE')), 'directory')
1515
 
        self.assertEqual(this.wt.get_file('i').read(),
 
1312
        self.assertEqual(this.wt.get_file('i').read(), 
1516
1313
                         conflict_text('1\n2\n3\n4\n', 'h\ni\nj\nk\n'))
1517
1314
        self.assertEqual(this.wt.get_file_byname('i.THIS').read(),
1518
1315
                         '1\n2\n3\n4\n')
1542
1339
            tg.tt.new_symlink('b', tg.root, 'b', 'b')
1543
1340
            tg.tt.new_file('c', tg.root, 'c', 'c')
1544
1341
            tg.tt.new_symlink('d', tg.root, tg.name, 'd')
1545
 
        targets = ((base, 'base-e', 'base-f', None, None),
1546
 
                   (this, 'other-e', 'this-f', 'other-g', 'this-h'),
 
1342
        targets = ((base, 'base-e', 'base-f', None, None), 
 
1343
                   (this, 'other-e', 'this-f', 'other-g', 'this-h'), 
1547
1344
                   (other, 'other-e', None, 'other-g', 'other-h'))
1548
1345
        for tg, e_target, f_target, g_target, h_target in targets:
1549
 
            for link, target in (('e', e_target), ('f', f_target),
 
1346
            for link, target in (('e', e_target), ('f', f_target), 
1550
1347
                                 ('g', g_target), ('h', h_target)):
1551
1348
                if target is not None:
1552
1349
                    tg.tt.new_symlink(link, tg.root, target, link)
1578
1375
        base = TransformGroup("BASE", root_id)
1579
1376
        this = TransformGroup("THIS", root_id)
1580
1377
        other = TransformGroup("OTHER", root_id)
1581
 
        base_a, this_a, other_a = [t.tt.new_directory('a', t.root, 'a')
 
1378
        base_a, this_a, other_a = [t.tt.new_directory('a', t.root, 'a') 
1582
1379
                                   for t in [base, this, other]]
1583
 
        base_b, this_b, other_b = [t.tt.new_directory('b', t.root, 'b')
 
1380
        base_b, this_b, other_b = [t.tt.new_directory('b', t.root, 'b') 
1584
1381
                                   for t in [base, this, other]]
1585
1382
        base.tt.new_directory('c', base_a, 'c')
1586
1383
        this.tt.new_directory('c1', this_a, 'c')
1611
1408
        base = TransformGroup("BASE", root_id)
1612
1409
        this = TransformGroup("THIS", root_id)
1613
1410
        other = TransformGroup("OTHER", root_id)
1614
 
        base_a, this_a, other_a = [t.tt.new_directory('a', t.root, 'a')
 
1411
        base_a, this_a, other_a = [t.tt.new_directory('a', t.root, 'a') 
1615
1412
                                   for t in [base, this, other]]
1616
 
        base_b, this_b, other_b = [t.tt.new_directory('b', t.root, 'b')
 
1413
        base_b, this_b, other_b = [t.tt.new_directory('b', t.root, 'b') 
1617
1414
                                   for t in [base, this, other]]
1618
1415
 
1619
1416
        base.tt.new_file('g', base_a, 'g', 'g')
1710
1507
        os.symlink('foo', 'target2/symlink')
1711
1508
        build_tree(source.basis_tree(), target)
1712
1509
        self.assertEqual([], target.conflicts())
1713
 
 
 
1510
        
1714
1511
    def test_directory_conflict_handling(self):
1715
1512
        """Ensure that when building trees, conflict handling is done"""
1716
1513
        source = self.make_branch_and_tree('source')
1772
1569
        target = self.make_branch_and_tree('target')
1773
1570
        self.build_tree(['target/name'])
1774
1571
        target.add('name')
1775
 
        self.assertRaises(errors.WorkingTreeAlreadyPopulated,
 
1572
        self.assertRaises(errors.WorkingTreeAlreadyPopulated, 
1776
1573
            build_tree, source.basis_tree(), target)
1777
1574
 
1778
1575
    def test_build_tree_rename_count(self):
1922
1719
        self.assertEqual([], list(target.iter_changes(revision_tree)))
1923
1720
        self.assertTrue(source.is_executable('file1-id'))
1924
1721
 
1925
 
    def install_rot13_content_filter(self, pattern):
1926
 
        original_registry = filters._reset_registry()
1927
 
        def restore_registry():
1928
 
            filters._reset_registry(original_registry)
1929
 
        self.addCleanup(restore_registry)
1930
 
        def rot13(chunks, context=None):
1931
 
            return [''.join(chunks).encode('rot13')]
1932
 
        rot13filter = filters.ContentFilter(rot13, rot13)
1933
 
        filters.register_filter_stack_map('rot13', {'yes': [rot13filter]}.get)
1934
 
        os.mkdir(self.test_home_dir + '/.bazaar')
1935
 
        rules_filename = self.test_home_dir + '/.bazaar/rules'
1936
 
        f = open(rules_filename, 'wb')
1937
 
        f.write('[name %s]\nrot13=yes\n' % (pattern,))
1938
 
        f.close()
1939
 
        def uninstall_rules():
1940
 
            os.remove(rules_filename)
1941
 
            rules.reset_rules()
1942
 
        self.addCleanup(uninstall_rules)
1943
 
        rules.reset_rules()
1944
 
 
1945
 
    def test_build_tree_content_filtered_files_are_not_hardlinked(self):
1946
 
        """build_tree will not hardlink files that have content filtering rules
1947
 
        applied to them (but will still hardlink other files from the same tree
1948
 
        if it can).
1949
 
        """
1950
 
        self.requireFeature(HardlinkFeature)
1951
 
        self.install_rot13_content_filter('file1')
1952
 
        source = self.create_ab_tree()
1953
 
        target = self.make_branch_and_tree('target')
1954
 
        revision_tree = source.basis_tree()
1955
 
        revision_tree.lock_read()
1956
 
        self.addCleanup(revision_tree.unlock)
1957
 
        build_tree(revision_tree, target, source, hardlink=True)
1958
 
        target.lock_read()
1959
 
        self.addCleanup(target.unlock)
1960
 
        self.assertEqual([], list(target.iter_changes(revision_tree)))
1961
 
        source_stat = os.stat('source/file1')
1962
 
        target_stat = os.stat('target/file1')
1963
 
        self.assertNotEqual(source_stat, target_stat)
1964
 
        source_stat = os.stat('source/file2')
1965
 
        target_stat = os.stat('target/file2')
1966
 
        self.assertEqualStat(source_stat, target_stat)
1967
 
 
1968
1722
    def test_case_insensitive_build_tree_inventory(self):
1969
 
        if (tests.CaseInsensitiveFilesystemFeature.available()
1970
 
            or tests.CaseInsCasePresFilenameFeature.available()):
1971
 
            raise tests.UnavailableFeature('Fully case sensitive filesystem')
1972
1723
        source = self.make_branch_and_tree('source')
1973
1724
        self.build_tree(['source/file', 'source/FILE'])
1974
1725
        source.add(['file', 'FILE'], ['lower-id', 'upper-id'])
1982
1733
        self.assertEqual('FILE', target.id2path('upper-id'))
1983
1734
 
1984
1735
 
1985
 
class TestCommitTransform(tests.TestCaseWithTransport):
1986
 
 
1987
 
    def get_branch(self):
1988
 
        tree = self.make_branch_and_tree('tree')
1989
 
        tree.lock_write()
1990
 
        self.addCleanup(tree.unlock)
1991
 
        tree.commit('empty commit')
1992
 
        return tree.branch
1993
 
 
1994
 
    def get_branch_and_transform(self):
1995
 
        branch = self.get_branch()
1996
 
        tt = TransformPreview(branch.basis_tree())
1997
 
        self.addCleanup(tt.finalize)
1998
 
        return branch, tt
1999
 
 
2000
 
    def test_commit_wrong_basis(self):
2001
 
        branch = self.get_branch()
2002
 
        basis = branch.repository.revision_tree(
2003
 
            _mod_revision.NULL_REVISION)
2004
 
        tt = TransformPreview(basis)
2005
 
        self.addCleanup(tt.finalize)
2006
 
        e = self.assertRaises(ValueError, tt.commit, branch, '')
2007
 
        self.assertEqual('TreeTransform not based on branch basis: null:',
2008
 
                         str(e))
2009
 
 
2010
 
    def test_empy_commit(self):
2011
 
        branch, tt = self.get_branch_and_transform()
2012
 
        rev = tt.commit(branch, 'my message')
2013
 
        self.assertEqual(2, branch.revno())
2014
 
        repo = branch.repository
2015
 
        self.assertEqual('my message', repo.get_revision(rev).message)
2016
 
 
2017
 
    def test_merge_parents(self):
2018
 
        branch, tt = self.get_branch_and_transform()
2019
 
        rev = tt.commit(branch, 'my message', ['rev1b', 'rev1c'])
2020
 
        self.assertEqual(['rev1b', 'rev1c'],
2021
 
                         branch.basis_tree().get_parent_ids()[1:])
2022
 
 
2023
 
    def test_first_commit(self):
2024
 
        branch = self.make_branch('branch')
2025
 
        branch.lock_write()
2026
 
        self.addCleanup(branch.unlock)
2027
 
        tt = TransformPreview(branch.basis_tree())
2028
 
        self.addCleanup(tt.finalize)
2029
 
        tt.new_directory('', ROOT_PARENT, 'TREE_ROOT')
2030
 
        rev = tt.commit(branch, 'my message')
2031
 
        self.assertEqual([], branch.basis_tree().get_parent_ids())
2032
 
        self.assertNotEqual(_mod_revision.NULL_REVISION,
2033
 
                            branch.last_revision())
2034
 
 
2035
 
    def test_first_commit_with_merge_parents(self):
2036
 
        branch = self.make_branch('branch')
2037
 
        branch.lock_write()
2038
 
        self.addCleanup(branch.unlock)
2039
 
        tt = TransformPreview(branch.basis_tree())
2040
 
        self.addCleanup(tt.finalize)
2041
 
        e = self.assertRaises(ValueError, tt.commit, branch,
2042
 
                          'my message', ['rev1b-id'])
2043
 
        self.assertEqual('Cannot supply merge parents for first commit.',
2044
 
                         str(e))
2045
 
        self.assertEqual(_mod_revision.NULL_REVISION, branch.last_revision())
2046
 
 
2047
 
    def test_add_files(self):
2048
 
        branch, tt = self.get_branch_and_transform()
2049
 
        tt.new_file('file', tt.root, 'contents', 'file-id')
2050
 
        trans_id = tt.new_directory('dir', tt.root, 'dir-id')
2051
 
        if SymlinkFeature.available():
2052
 
            tt.new_symlink('symlink', trans_id, 'target', 'symlink-id')
2053
 
        rev = tt.commit(branch, 'message')
2054
 
        tree = branch.basis_tree()
2055
 
        self.assertEqual('file', tree.id2path('file-id'))
2056
 
        self.assertEqual('contents', tree.get_file_text('file-id'))
2057
 
        self.assertEqual('dir', tree.id2path('dir-id'))
2058
 
        if SymlinkFeature.available():
2059
 
            self.assertEqual('dir/symlink', tree.id2path('symlink-id'))
2060
 
            self.assertEqual('target', tree.get_symlink_target('symlink-id'))
2061
 
 
2062
 
    def test_add_unversioned(self):
2063
 
        branch, tt = self.get_branch_and_transform()
2064
 
        tt.new_file('file', tt.root, 'contents')
2065
 
        self.assertRaises(errors.StrictCommitFailed, tt.commit, branch,
2066
 
                          'message', strict=True)
2067
 
 
2068
 
    def test_modify_strict(self):
2069
 
        branch, tt = self.get_branch_and_transform()
2070
 
        tt.new_file('file', tt.root, 'contents', 'file-id')
2071
 
        tt.commit(branch, 'message', strict=True)
2072
 
        tt = TransformPreview(branch.basis_tree())
2073
 
        self.addCleanup(tt.finalize)
2074
 
        trans_id = tt.trans_id_file_id('file-id')
2075
 
        tt.delete_contents(trans_id)
2076
 
        tt.create_file('contents', trans_id)
2077
 
        tt.commit(branch, 'message', strict=True)
2078
 
 
2079
 
    def test_commit_malformed(self):
2080
 
        """Committing a malformed transform should raise an exception.
2081
 
 
2082
 
        In this case, we are adding a file without adding its parent.
2083
 
        """
2084
 
        branch, tt = self.get_branch_and_transform()
2085
 
        parent_id = tt.trans_id_file_id('parent-id')
2086
 
        tt.new_file('file', parent_id, 'contents', 'file-id')
2087
 
        self.assertRaises(errors.MalformedTransform, tt.commit, branch,
2088
 
                          'message')
2089
 
 
2090
 
 
2091
1736
class MockTransform(object):
2092
1737
 
2093
1738
    def has_named_child(self, by_parent, parent_id, name):
2248
1893
        resolve_conflicts(tt)
2249
1894
 
2250
1895
 
2251
 
A_ENTRY = ('a-id', ('a', 'a'), True, (True, True),
2252
 
                  ('TREE_ROOT', 'TREE_ROOT'), ('a', 'a'), ('file', 'file'),
2253
 
                  (False, False))
2254
 
ROOT_ENTRY = ('TREE_ROOT', ('', ''), False, (True, True), (None, None),
2255
 
              ('', ''), ('directory', 'directory'), (False, None))
2256
 
 
2257
 
 
2258
1896
class TestTransformPreview(tests.TestCaseWithTransport):
2259
1897
 
2260
1898
    def create_tree(self):
2261
1899
        tree = self.make_branch_and_tree('.')
2262
1900
        self.build_tree_contents([('a', 'content 1')])
2263
 
        tree.set_root_id('TREE_ROOT')
2264
1901
        tree.add('a', 'a-id')
2265
1902
        tree.commit('rev1', rev_id='rev1')
2266
1903
        return tree.branch.repository.revision_tree('rev1')
2333
1970
                          (False, False))],
2334
1971
                          list(preview_tree.iter_changes(revision_tree)))
2335
1972
 
2336
 
    def test_include_unchanged_succeeds(self):
 
1973
    def test_wrong_tree_value_error(self):
2337
1974
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2338
 
        changes = preview_tree.iter_changes(revision_tree,
2339
 
                                            include_unchanged=True)
2340
 
        root = revision_tree.inventory.root.file_id
 
1975
        e = self.assertRaises(ValueError, preview_tree.iter_changes,
 
1976
                              preview_tree)
 
1977
        self.assertEqual('from_tree must be transform source tree.', str(e))
2341
1978
 
2342
 
        self.assertEqual([ROOT_ENTRY, A_ENTRY], list(changes))
 
1979
    def test_include_unchanged_value_error(self):
 
1980
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
 
1981
        e = self.assertRaises(ValueError, preview_tree.iter_changes,
 
1982
                              revision_tree, include_unchanged=True)
 
1983
        self.assertEqual('include_unchanged is not supported', str(e))
2343
1984
 
2344
1985
    def test_specific_files(self):
2345
1986
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2346
 
        changes = preview_tree.iter_changes(revision_tree,
2347
 
                                            specific_files=[''])
2348
 
        self.assertEqual([ROOT_ENTRY, A_ENTRY], list(changes))
 
1987
        e = self.assertRaises(ValueError, preview_tree.iter_changes,
 
1988
                              revision_tree, specific_files=['pete'])
 
1989
        self.assertEqual('specific_files is not supported', str(e))
2349
1990
 
2350
 
    def test_want_unversioned(self):
 
1991
    def test_want_unversioned_value_error(self):
2351
1992
        revision_tree, preview_tree = self.get_tree_and_preview_tree()
2352
 
        changes = preview_tree.iter_changes(revision_tree,
2353
 
                                            want_unversioned=True)
2354
 
        self.assertEqual([ROOT_ENTRY, A_ENTRY], list(changes))
 
1993
        e = self.assertRaises(ValueError, preview_tree.iter_changes,
 
1994
                              revision_tree, want_unversioned=True)
 
1995
        self.assertEqual('want_unversioned is not supported', str(e))
2355
1996
 
2356
1997
    def test_ignore_extra_trees_no_specific_files(self):
2357
1998
        # extra_trees is harmless without specific_files, so we'll silently
2388
2029
        self.assertEqual(os.stat(limbo_path).st_mtime,
2389
2030
                         preview_tree.get_file_mtime('file-id'))
2390
2031
 
2391
 
    def test_get_file_mtime_renamed(self):
2392
 
        work_tree = self.make_branch_and_tree('tree')
2393
 
        self.build_tree(['tree/file'])
2394
 
        work_tree.add('file', 'file-id')
2395
 
        preview = TransformPreview(work_tree)
2396
 
        self.addCleanup(preview.finalize)
2397
 
        file_trans_id = preview.trans_id_tree_file_id('file-id')
2398
 
        preview.adjust_path('renamed', preview.root, file_trans_id)
2399
 
        preview_tree = preview.get_preview_tree()
2400
 
        preview_mtime = preview_tree.get_file_mtime('file-id', 'renamed')
2401
 
        work_mtime = work_tree.get_file_mtime('file-id', 'file')
2402
 
 
2403
2032
    def test_get_file(self):
2404
2033
        preview = self.get_empty_preview()
2405
2034
        preview.new_file('file', preview.root, 'contents', 'file-id')
2553
2182
        self.assertEqual(('missing', None, None, None), summary)
2554
2183
 
2555
2184
    def test_file_content_summary_executable(self):
 
2185
        if not osutils.supports_executable():
 
2186
            raise TestNotApplicable()
2556
2187
        preview = self.get_empty_preview()
2557
2188
        path_id = preview.new_file('path', preview.root, 'contents', 'path-id')
2558
2189
        preview.set_executability(True, path_id)
2567
2198
        self.assertIs(None, summary[3])
2568
2199
 
2569
2200
    def test_change_executability(self):
 
2201
        if not osutils.supports_executable():
 
2202
            raise TestNotApplicable()
2570
2203
        tree = self.make_branch_and_tree('tree')
2571
2204
        self.build_tree(['tree/path'])
2572
2205
        tree.add('path')
2586
2219
        # size must be known
2587
2220
        self.assertEqual(len('contents'), summary[1])
2588
2221
        # not executable
2589
 
        self.assertEqual(False, summary[2])
 
2222
        if osutils.supports_executable():
 
2223
            self.assertEqual(False, summary[2])
 
2224
        else:
 
2225
            self.assertEqual(None, summary[2])
2590
2226
        # will not have hash (not cheap to determine)
2591
2227
        self.assertIs(None, summary[3])
2592
2228
 
2730
2366
            ('new-a', 'e\n'),
2731
2367
            ('new-b', 'f\n'),
2732
2368
        ], list(tree_a.plan_file_merge('file-id', tree_b)))
2733
 
 
2734
 
    def test_walkdirs(self):
2735
 
        preview = self.get_empty_preview()
2736
 
        root = preview.new_directory('', ROOT_PARENT, 'tree-root')
2737
 
        # FIXME: new_directory should mark root.
2738
 
        preview.fixup_new_roots()
2739
 
        preview_tree = preview.get_preview_tree()
2740
 
        file_trans_id = preview.new_file('a', preview.root, 'contents',
2741
 
                                         'a-id')
2742
 
        expected = [(('', 'tree-root'),
2743
 
                    [('a', 'a', 'file', None, 'a-id', 'file')])]
2744
 
        self.assertEqual(expected, list(preview_tree.walkdirs()))
2745
 
 
2746
 
    def test_extras(self):
2747
 
        work_tree = self.make_branch_and_tree('tree')
2748
 
        self.build_tree(['tree/removed-file', 'tree/existing-file',
2749
 
                         'tree/not-removed-file'])
2750
 
        work_tree.add(['removed-file', 'not-removed-file'])
2751
 
        preview = TransformPreview(work_tree)
2752
 
        self.addCleanup(preview.finalize)
2753
 
        preview.new_file('new-file', preview.root, 'contents')
2754
 
        preview.new_file('new-versioned-file', preview.root, 'contents',
2755
 
                         'new-versioned-id')
2756
 
        tree = preview.get_preview_tree()
2757
 
        preview.unversion_file(preview.trans_id_tree_path('removed-file'))
2758
 
        self.assertEqual(set(['new-file', 'removed-file', 'existing-file']),
2759
 
                         set(tree.extras()))
2760
 
 
2761
 
    def test_merge_into_preview(self):
2762
 
        work_tree = self.make_branch_and_tree('tree')
2763
 
        self.build_tree_contents([('tree/file','b\n')])
2764
 
        work_tree.add('file', 'file-id')
2765
 
        work_tree.commit('first commit')
2766
 
        child_tree = work_tree.bzrdir.sprout('child').open_workingtree()
2767
 
        self.build_tree_contents([('child/file','b\nc\n')])
2768
 
        child_tree.commit('child commit')
2769
 
        child_tree.lock_write()
2770
 
        self.addCleanup(child_tree.unlock)
2771
 
        work_tree.lock_write()
2772
 
        self.addCleanup(work_tree.unlock)
2773
 
        preview = TransformPreview(work_tree)
2774
 
        self.addCleanup(preview.finalize)
2775
 
        file_trans_id = preview.trans_id_file_id('file-id')
2776
 
        preview.delete_contents(file_trans_id)
2777
 
        preview.create_file('a\nb\n', file_trans_id)
2778
 
        pb = progress.DummyProgress()
2779
 
        preview_tree = preview.get_preview_tree()
2780
 
        merger = Merger.from_revision_ids(pb, preview_tree,
2781
 
                                          child_tree.branch.last_revision(),
2782
 
                                          other_branch=child_tree.branch,
2783
 
                                          tree_branch=work_tree.branch)
2784
 
        merger.merge_type = Merge3Merger
2785
 
        tt = merger.make_merger().make_preview_transform()
2786
 
        self.addCleanup(tt.finalize)
2787
 
        final_tree = tt.get_preview_tree()
2788
 
        self.assertEqual('a\nb\nc\n', final_tree.get_file_text('file-id'))
2789
 
 
2790
 
    def test_merge_preview_into_workingtree(self):
2791
 
        tree = self.make_branch_and_tree('tree')
2792
 
        tree.set_root_id('TREE_ROOT')
2793
 
        tt = TransformPreview(tree)
2794
 
        self.addCleanup(tt.finalize)
2795
 
        tt.new_file('name', tt.root, 'content', 'file-id')
2796
 
        tree2 = self.make_branch_and_tree('tree2')
2797
 
        tree2.set_root_id('TREE_ROOT')
2798
 
        pb = progress.DummyProgress()
2799
 
        merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
2800
 
                                         pb, tree.basis_tree())
2801
 
        merger.merge_type = Merge3Merger
2802
 
        merger.do_merge()
2803
 
 
2804
 
    def test_merge_preview_into_workingtree_handles_conflicts(self):
2805
 
        tree = self.make_branch_and_tree('tree')
2806
 
        self.build_tree_contents([('tree/foo', 'bar')])
2807
 
        tree.add('foo', 'foo-id')
2808
 
        tree.commit('foo')
2809
 
        tt = TransformPreview(tree)
2810
 
        self.addCleanup(tt.finalize)
2811
 
        trans_id = tt.trans_id_file_id('foo-id')
2812
 
        tt.delete_contents(trans_id)
2813
 
        tt.create_file('baz', trans_id)
2814
 
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
2815
 
        self.build_tree_contents([('tree2/foo', 'qux')])
2816
 
        pb = progress.DummyProgress()
2817
 
        merger = Merger.from_uncommitted(tree2, tt.get_preview_tree(),
2818
 
                                         pb, tree.basis_tree())
2819
 
        merger.merge_type = Merge3Merger
2820
 
        merger.do_merge()
2821
 
 
2822
 
    def test_is_executable(self):
2823
 
        tree = self.make_branch_and_tree('tree')
2824
 
        preview = TransformPreview(tree)
2825
 
        self.addCleanup(preview.finalize)
2826
 
        preview.new_file('foo', preview.root, 'bar', 'baz-id')
2827
 
        preview_tree = preview.get_preview_tree()
2828
 
        self.assertEqual(False, preview_tree.is_executable('baz-id',
2829
 
                                                           'tree/foo'))
2830
 
        self.assertEqual(False, preview_tree.is_executable('baz-id'))
2831
 
 
2832
 
    def test_commit_preview_tree(self):
2833
 
        tree = self.make_branch_and_tree('tree')
2834
 
        rev_id = tree.commit('rev1')
2835
 
        tree.branch.lock_write()
2836
 
        self.addCleanup(tree.branch.unlock)
2837
 
        tt = TransformPreview(tree)
2838
 
        tt.new_file('file', tt.root, 'contents', 'file_id')
2839
 
        self.addCleanup(tt.finalize)
2840
 
        preview = tt.get_preview_tree()
2841
 
        preview.set_parent_ids([rev_id])
2842
 
        builder = tree.branch.get_commit_builder([rev_id])
2843
 
        list(builder.record_iter_changes(preview, rev_id, tt.iter_changes()))
2844
 
        builder.finish_inventory()
2845
 
        rev2_id = builder.commit('rev2')
2846
 
        rev2_tree = tree.branch.repository.revision_tree(rev2_id)
2847
 
        self.assertEqual('contents', rev2_tree.get_file_text('file_id'))
2848
 
 
2849
 
    def test_ascii_limbo_paths(self):
2850
 
        self.requireFeature(tests.UnicodeFilenameFeature)
2851
 
        branch = self.make_branch('any')
2852
 
        tree = branch.repository.revision_tree(_mod_revision.NULL_REVISION)
2853
 
        tt = TransformPreview(tree)
2854
 
        self.addCleanup(tt.finalize)
2855
 
        foo_id = tt.new_directory('', ROOT_PARENT)
2856
 
        bar_id = tt.new_file(u'\u1234bar', foo_id, 'contents')
2857
 
        limbo_path = tt._limbo_name(bar_id)
2858
 
        self.assertEqual(limbo_path.encode('ascii', 'replace'), limbo_path)
2859
 
 
2860
 
 
2861
 
class FakeSerializer(object):
2862
 
    """Serializer implementation that simply returns the input.
2863
 
 
2864
 
    The input is returned in the order used by pack.ContainerPushParser.
2865
 
    """
2866
 
    @staticmethod
2867
 
    def bytes_record(bytes, names):
2868
 
        return names, bytes
2869
 
 
2870
 
 
2871
 
class TestSerializeTransform(tests.TestCaseWithTransport):
2872
 
 
2873
 
    _test_needs_features = [tests.UnicodeFilenameFeature]
2874
 
 
2875
 
    def get_preview(self, tree=None):
2876
 
        if tree is None:
2877
 
            tree = self.make_branch_and_tree('tree')
2878
 
        tt = TransformPreview(tree)
2879
 
        self.addCleanup(tt.finalize)
2880
 
        return tt
2881
 
 
2882
 
    def assertSerializesTo(self, expected, tt):
2883
 
        records = list(tt.serialize(FakeSerializer()))
2884
 
        self.assertEqual(expected, records)
2885
 
 
2886
 
    @staticmethod
2887
 
    def default_attribs():
2888
 
        return {
2889
 
            '_id_number': 1,
2890
 
            '_new_name': {},
2891
 
            '_new_parent': {},
2892
 
            '_new_executability': {},
2893
 
            '_new_id': {},
2894
 
            '_tree_path_ids': {'': 'new-0'},
2895
 
            '_removed_id': [],
2896
 
            '_removed_contents': [],
2897
 
            '_non_present_ids': {},
2898
 
            }
2899
 
 
2900
 
    def make_records(self, attribs, contents):
2901
 
        records = [
2902
 
            (((('attribs'),),), bencode.bencode(attribs))]
2903
 
        records.extend([(((n, k),), c) for n, k, c in contents])
2904
 
        return records
2905
 
 
2906
 
    def creation_records(self):
2907
 
        attribs = self.default_attribs()
2908
 
        attribs['_id_number'] = 3
2909
 
        attribs['_new_name'] = {
2910
 
            'new-1': u'foo\u1234'.encode('utf-8'), 'new-2': 'qux'}
2911
 
        attribs['_new_id'] = {'new-1': 'baz', 'new-2': 'quxx'}
2912
 
        attribs['_new_parent'] = {'new-1': 'new-0', 'new-2': 'new-0'}
2913
 
        attribs['_new_executability'] = {'new-1': 1}
2914
 
        contents = [
2915
 
            ('new-1', 'file', 'i 1\nbar\n'),
2916
 
            ('new-2', 'directory', ''),
2917
 
            ]
2918
 
        return self.make_records(attribs, contents)
2919
 
 
2920
 
    def test_serialize_creation(self):
2921
 
        tt = self.get_preview()
2922
 
        tt.new_file(u'foo\u1234', tt.root, 'bar', 'baz', True)
2923
 
        tt.new_directory('qux', tt.root, 'quxx')
2924
 
        self.assertSerializesTo(self.creation_records(), tt)
2925
 
 
2926
 
    def test_deserialize_creation(self):
2927
 
        tt = self.get_preview()
2928
 
        tt.deserialize(iter(self.creation_records()))
2929
 
        self.assertEqual(3, tt._id_number)
2930
 
        self.assertEqual({'new-1': u'foo\u1234',
2931
 
                          'new-2': 'qux'}, tt._new_name)
2932
 
        self.assertEqual({'new-1': 'baz', 'new-2': 'quxx'}, tt._new_id)
2933
 
        self.assertEqual({'new-1': tt.root, 'new-2': tt.root}, tt._new_parent)
2934
 
        self.assertEqual({'baz': 'new-1', 'quxx': 'new-2'}, tt._r_new_id)
2935
 
        self.assertEqual({'new-1': True}, tt._new_executability)
2936
 
        self.assertEqual({'new-1': 'file',
2937
 
                          'new-2': 'directory'}, tt._new_contents)
2938
 
        foo_limbo = open(tt._limbo_name('new-1'), 'rb')
2939
 
        try:
2940
 
            foo_content = foo_limbo.read()
2941
 
        finally:
2942
 
            foo_limbo.close()
2943
 
        self.assertEqual('bar', foo_content)
2944
 
 
2945
 
    def symlink_creation_records(self):
2946
 
        attribs = self.default_attribs()
2947
 
        attribs['_id_number'] = 2
2948
 
        attribs['_new_name'] = {'new-1': u'foo\u1234'.encode('utf-8')}
2949
 
        attribs['_new_parent'] = {'new-1': 'new-0'}
2950
 
        contents = [('new-1', 'symlink', u'bar\u1234'.encode('utf-8'))]
2951
 
        return self.make_records(attribs, contents)
2952
 
 
2953
 
    def test_serialize_symlink_creation(self):
2954
 
        self.requireFeature(tests.SymlinkFeature)
2955
 
        tt = self.get_preview()
2956
 
        tt.new_symlink(u'foo\u1234', tt.root, u'bar\u1234')
2957
 
        self.assertSerializesTo(self.symlink_creation_records(), tt)
2958
 
 
2959
 
    def test_deserialize_symlink_creation(self):
2960
 
        self.requireFeature(tests.SymlinkFeature)
2961
 
        tt = self.get_preview()
2962
 
        tt.deserialize(iter(self.symlink_creation_records()))
2963
 
        abspath = tt._limbo_name('new-1')
2964
 
        foo_content = osutils.readlink(abspath)
2965
 
        self.assertEqual(u'bar\u1234', foo_content)
2966
 
 
2967
 
    def make_destruction_preview(self):
2968
 
        tree = self.make_branch_and_tree('.')
2969
 
        self.build_tree([u'foo\u1234', 'bar'])
2970
 
        tree.add([u'foo\u1234', 'bar'], ['foo-id', 'bar-id'])
2971
 
        return self.get_preview(tree)
2972
 
 
2973
 
    def destruction_records(self):
2974
 
        attribs = self.default_attribs()
2975
 
        attribs['_id_number'] = 3
2976
 
        attribs['_removed_id'] = ['new-1']
2977
 
        attribs['_removed_contents'] = ['new-2']
2978
 
        attribs['_tree_path_ids'] = {
2979
 
            '': 'new-0',
2980
 
            u'foo\u1234'.encode('utf-8'): 'new-1',
2981
 
            'bar': 'new-2',
2982
 
            }
2983
 
        return self.make_records(attribs, [])
2984
 
 
2985
 
    def test_serialize_destruction(self):
2986
 
        tt = self.make_destruction_preview()
2987
 
        foo_trans_id = tt.trans_id_tree_file_id('foo-id')
2988
 
        tt.unversion_file(foo_trans_id)
2989
 
        bar_trans_id = tt.trans_id_tree_file_id('bar-id')
2990
 
        tt.delete_contents(bar_trans_id)
2991
 
        self.assertSerializesTo(self.destruction_records(), tt)
2992
 
 
2993
 
    def test_deserialize_destruction(self):
2994
 
        tt = self.make_destruction_preview()
2995
 
        tt.deserialize(iter(self.destruction_records()))
2996
 
        self.assertEqual({u'foo\u1234': 'new-1',
2997
 
                          'bar': 'new-2',
2998
 
                          '': tt.root}, tt._tree_path_ids)
2999
 
        self.assertEqual({'new-1': u'foo\u1234',
3000
 
                          'new-2': 'bar',
3001
 
                          tt.root: ''}, tt._tree_id_paths)
3002
 
        self.assertEqual(set(['new-1']), tt._removed_id)
3003
 
        self.assertEqual(set(['new-2']), tt._removed_contents)
3004
 
 
3005
 
    def missing_records(self):
3006
 
        attribs = self.default_attribs()
3007
 
        attribs['_id_number'] = 2
3008
 
        attribs['_non_present_ids'] = {
3009
 
            'boo': 'new-1',}
3010
 
        return self.make_records(attribs, [])
3011
 
 
3012
 
    def test_serialize_missing(self):
3013
 
        tt = self.get_preview()
3014
 
        boo_trans_id = tt.trans_id_file_id('boo')
3015
 
        self.assertSerializesTo(self.missing_records(), tt)
3016
 
 
3017
 
    def test_deserialize_missing(self):
3018
 
        tt = self.get_preview()
3019
 
        tt.deserialize(iter(self.missing_records()))
3020
 
        self.assertEqual({'boo': 'new-1'}, tt._non_present_ids)
3021
 
 
3022
 
    def make_modification_preview(self):
3023
 
        LINES_ONE = 'aa\nbb\ncc\ndd\n'
3024
 
        LINES_TWO = 'z\nbb\nx\ndd\n'
3025
 
        tree = self.make_branch_and_tree('tree')
3026
 
        self.build_tree_contents([('tree/file', LINES_ONE)])
3027
 
        tree.add('file', 'file-id')
3028
 
        return self.get_preview(tree), LINES_TWO
3029
 
 
3030
 
    def modification_records(self):
3031
 
        attribs = self.default_attribs()
3032
 
        attribs['_id_number'] = 2
3033
 
        attribs['_tree_path_ids'] = {
3034
 
            'file': 'new-1',
3035
 
            '': 'new-0',}
3036
 
        attribs['_removed_contents'] = ['new-1']
3037
 
        contents = [('new-1', 'file',
3038
 
                     'i 1\nz\n\nc 0 1 1 1\ni 1\nx\n\nc 0 3 3 1\n')]
3039
 
        return self.make_records(attribs, contents)
3040
 
 
3041
 
    def test_serialize_modification(self):
3042
 
        tt, LINES = self.make_modification_preview()
3043
 
        trans_id = tt.trans_id_file_id('file-id')
3044
 
        tt.delete_contents(trans_id)
3045
 
        tt.create_file(LINES, trans_id)
3046
 
        self.assertSerializesTo(self.modification_records(), tt)
3047
 
 
3048
 
    def test_deserialize_modification(self):
3049
 
        tt, LINES = self.make_modification_preview()
3050
 
        tt.deserialize(iter(self.modification_records()))
3051
 
        self.assertFileEqual(LINES, tt._limbo_name('new-1'))
3052
 
 
3053
 
    def make_kind_change_preview(self):
3054
 
        LINES = 'a\nb\nc\nd\n'
3055
 
        tree = self.make_branch_and_tree('tree')
3056
 
        self.build_tree(['tree/foo/'])
3057
 
        tree.add('foo', 'foo-id')
3058
 
        return self.get_preview(tree), LINES
3059
 
 
3060
 
    def kind_change_records(self):
3061
 
        attribs = self.default_attribs()
3062
 
        attribs['_id_number'] = 2
3063
 
        attribs['_tree_path_ids'] = {
3064
 
            'foo': 'new-1',
3065
 
            '': 'new-0',}
3066
 
        attribs['_removed_contents'] = ['new-1']
3067
 
        contents = [('new-1', 'file',
3068
 
                     'i 4\na\nb\nc\nd\n\n')]
3069
 
        return self.make_records(attribs, contents)
3070
 
 
3071
 
    def test_serialize_kind_change(self):
3072
 
        tt, LINES = self.make_kind_change_preview()
3073
 
        trans_id = tt.trans_id_file_id('foo-id')
3074
 
        tt.delete_contents(trans_id)
3075
 
        tt.create_file(LINES, trans_id)
3076
 
        self.assertSerializesTo(self.kind_change_records(), tt)
3077
 
 
3078
 
    def test_deserialize_kind_change(self):
3079
 
        tt, LINES = self.make_kind_change_preview()
3080
 
        tt.deserialize(iter(self.kind_change_records()))
3081
 
        self.assertFileEqual(LINES, tt._limbo_name('new-1'))
3082
 
 
3083
 
    def make_add_contents_preview(self):
3084
 
        LINES = 'a\nb\nc\nd\n'
3085
 
        tree = self.make_branch_and_tree('tree')
3086
 
        self.build_tree(['tree/foo'])
3087
 
        tree.add('foo')
3088
 
        os.unlink('tree/foo')
3089
 
        return self.get_preview(tree), LINES
3090
 
 
3091
 
    def add_contents_records(self):
3092
 
        attribs = self.default_attribs()
3093
 
        attribs['_id_number'] = 2
3094
 
        attribs['_tree_path_ids'] = {
3095
 
            'foo': 'new-1',
3096
 
            '': 'new-0',}
3097
 
        contents = [('new-1', 'file',
3098
 
                     'i 4\na\nb\nc\nd\n\n')]
3099
 
        return self.make_records(attribs, contents)
3100
 
 
3101
 
    def test_serialize_add_contents(self):
3102
 
        tt, LINES = self.make_add_contents_preview()
3103
 
        trans_id = tt.trans_id_tree_path('foo')
3104
 
        tt.create_file(LINES, trans_id)
3105
 
        self.assertSerializesTo(self.add_contents_records(), tt)
3106
 
 
3107
 
    def test_deserialize_add_contents(self):
3108
 
        tt, LINES = self.make_add_contents_preview()
3109
 
        tt.deserialize(iter(self.add_contents_records()))
3110
 
        self.assertFileEqual(LINES, tt._limbo_name('new-1'))
3111
 
 
3112
 
    def test_get_parents_lines(self):
3113
 
        LINES_ONE = 'aa\nbb\ncc\ndd\n'
3114
 
        LINES_TWO = 'z\nbb\nx\ndd\n'
3115
 
        tree = self.make_branch_and_tree('tree')
3116
 
        self.build_tree_contents([('tree/file', LINES_ONE)])
3117
 
        tree.add('file', 'file-id')
3118
 
        tt = self.get_preview(tree)
3119
 
        trans_id = tt.trans_id_tree_path('file')
3120
 
        self.assertEqual((['aa\n', 'bb\n', 'cc\n', 'dd\n'],),
3121
 
            tt._get_parents_lines(trans_id))
3122
 
 
3123
 
    def test_get_parents_texts(self):
3124
 
        LINES_ONE = 'aa\nbb\ncc\ndd\n'
3125
 
        LINES_TWO = 'z\nbb\nx\ndd\n'
3126
 
        tree = self.make_branch_and_tree('tree')
3127
 
        self.build_tree_contents([('tree/file', LINES_ONE)])
3128
 
        tree.add('file', 'file-id')
3129
 
        tt = self.get_preview(tree)
3130
 
        trans_id = tt.trans_id_tree_path('file')
3131
 
        self.assertEqual((LINES_ONE,),
3132
 
            tt._get_parents_texts(trans_id))