~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_dirstate.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests of the dirstate functionality being built for WorkingTreeFormat4."""
18
18
 
19
19
import os
 
20
import tempfile
20
21
 
21
22
from bzrlib import (
 
23
    controldir,
22
24
    dirstate,
23
25
    errors,
24
26
    inventory,
25
27
    memorytree,
26
28
    osutils,
27
29
    revision as _mod_revision,
 
30
    revisiontree,
28
31
    tests,
29
 
    )
30
 
from bzrlib.tests import test_osutils
 
32
    workingtree_4,
 
33
    )
 
34
from bzrlib.tests import (
 
35
    features,
 
36
    test_osutils,
 
37
    )
31
38
from bzrlib.tests.scenarios import load_tests_apply_scenarios
32
39
 
33
40
 
57
64
    _native_to_unicode = None # Not used yet
58
65
 
59
66
    def setUp(self):
60
 
        tests.TestCaseWithTransport.setUp(self)
61
 
 
 
67
        super(TestCaseWithDirState, self).setUp()
62
68
        self.overrideAttr(osutils,
63
69
                          '_selected_dir_reader', self._dir_reader_class())
64
70
 
592
598
 
593
599
            # The dirblock has been updated
594
600
            self.assertEqual(st.st_size, entry[1][0][2])
595
 
            self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
 
601
            self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
596
602
                             state._dirblock_state)
597
603
 
598
604
            del entry
625
631
            sha1sum = dirstate.update_entry(state, entry, 'a-file', st)
626
632
            self.assertEqual('ecc5374e9ed82ad3ea3b4d452ea995a5fd3e70e3',
627
633
                             sha1sum)
628
 
            self.assertEqual(dirstate.DirState.IN_MEMORY_MODIFIED,
 
634
            self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
629
635
                             state._dirblock_state)
630
636
 
631
637
            # Now, before we try to save, grab another dirstate, and take out a
748
754
    def test_set_state_from_inventory_no_content_no_parents(self):
749
755
        # setting the current inventory is a slow but important api to support.
750
756
        tree1, revid1 = self.make_minimal_tree()
751
 
        inv = tree1.inventory
 
757
        inv = tree1.root_inventory
752
758
        root_id = inv.path2id('')
753
759
        expected_result = [], [
754
760
            (('', '', root_id), [
769
775
 
770
776
    def test_set_state_from_scratch_no_parents(self):
771
777
        tree1, revid1 = self.make_minimal_tree()
772
 
        inv = tree1.inventory
 
778
        inv = tree1.root_inventory
773
779
        root_id = inv.path2id('')
774
780
        expected_result = [], [
775
781
            (('', '', root_id), [
790
796
 
791
797
    def test_set_state_from_scratch_identical_parent(self):
792
798
        tree1, revid1 = self.make_minimal_tree()
793
 
        inv = tree1.inventory
 
799
        inv = tree1.root_inventory
794
800
        root_id = inv.path2id('')
795
801
        rev_tree1 = tree1.branch.repository.revision_tree(revid1)
796
802
        d_entry = ('d', '', 0, False, dirstate.DirState.NULLSTAT)
848
854
                tree._dirstate._get_entry(0, 'foo-id'))
849
855
 
850
856
            # extract the inventory, and add something to it
851
 
            inv = tree._get_inventory()
 
857
            inv = tree._get_root_inventory()
852
858
            # should see the file we poked in...
853
859
            self.assertTrue(inv.has_id('foo-id'))
854
860
            self.assertTrue(inv.has_filename('foo'))
884
890
                      ['a-id', 'b-id', 'a-b-id', 'foo-id', 'bar-id'])
885
891
            tree1.commit('rev1', rev_id='rev1')
886
892
            root_id = tree1.get_root_id()
887
 
            inv = tree1.inventory
 
893
            inv = tree1.root_inventory
888
894
        finally:
889
895
            tree1.unlock()
890
896
        expected_result1 = [('', '', root_id, 'd'),
1204
1210
        # The most trivial addition of a symlink when there are no parents and
1205
1211
        # its in the root and all data about the file is supplied
1206
1212
        # bzr doesn't support fake symlinks on windows, yet.
1207
 
        self.requireFeature(tests.SymlinkFeature)
 
1213
        self.requireFeature(features.SymlinkFeature)
1208
1214
        os.symlink(target, link_name)
1209
1215
        stat = os.lstat(link_name)
1210
1216
        expected_entries = [
1235
1241
        self._test_add_symlink_to_root_no_parents_all_data('a link', 'target')
1236
1242
 
1237
1243
    def test_add_symlink_unicode_to_root_no_parents_all_data(self):
1238
 
        self.requireFeature(tests.UnicodeFilenameFeature)
 
1244
        self.requireFeature(features.UnicodeFilenameFeature)
1239
1245
        self._test_add_symlink_to_root_no_parents_all_data(
1240
1246
            u'\N{Euro Sign}link', u'targ\N{Euro Sign}et')
1241
1247
 
1318
1324
        try:
1319
1325
            tree1.add(['b'], ['b-id'])
1320
1326
            root_id = tree1.get_root_id()
1321
 
            inv = tree1.inventory
 
1327
            inv = tree1.root_inventory
1322
1328
            state = dirstate.DirState.initialize('dirstate')
1323
1329
            try:
1324
1330
                # Set the initial state with 'b'
1339
1345
            tree1.unlock()
1340
1346
 
1341
1347
 
 
1348
class TestDirStateHashUpdates(TestCaseWithDirState):
 
1349
 
 
1350
    def do_update_entry(self, state, path):
 
1351
        entry = state._get_entry(0, path_utf8=path)
 
1352
        stat = os.lstat(path)
 
1353
        return dirstate.update_entry(state, entry, os.path.abspath(path), stat)
 
1354
 
 
1355
    def _read_state_content(self, state):
 
1356
        """Read the content of the dirstate file.
 
1357
 
 
1358
        On Windows when one process locks a file, you can't even open() the
 
1359
        file in another process (to read it). So we go directly to
 
1360
        state._state_file. This should always be the exact disk representation,
 
1361
        so it is reasonable to do so.
 
1362
        DirState also always seeks before reading, so it doesn't matter if we
 
1363
        bump the file pointer.
 
1364
        """
 
1365
        state._state_file.seek(0)
 
1366
        return state._state_file.read()
 
1367
 
 
1368
    def test_worth_saving_limit_avoids_writing(self):
 
1369
        tree = self.make_branch_and_tree('.')
 
1370
        self.build_tree(['c', 'd'])
 
1371
        tree.lock_write()
 
1372
        tree.add(['c', 'd'], ['c-id', 'd-id'])
 
1373
        tree.commit('add c and d')
 
1374
        state = InstrumentedDirState.on_file(tree.current_dirstate()._filename,
 
1375
                                             worth_saving_limit=2)
 
1376
        tree.unlock()
 
1377
        state.lock_write()
 
1378
        self.addCleanup(state.unlock)
 
1379
        state._read_dirblocks_if_needed()
 
1380
        state.adjust_time(+20) # Allow things to be cached
 
1381
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
 
1382
                         state._dirblock_state)
 
1383
        content = self._read_state_content(state)
 
1384
        self.do_update_entry(state, 'c')
 
1385
        self.assertEqual(1, len(state._known_hash_changes))
 
1386
        self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
 
1387
                         state._dirblock_state)
 
1388
        state.save()
 
1389
        # It should not have set the state to IN_MEMORY_UNMODIFIED because the
 
1390
        # hash values haven't been written out.
 
1391
        self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
 
1392
                         state._dirblock_state)
 
1393
        self.assertEqual(content, self._read_state_content(state))
 
1394
        self.assertEqual(dirstate.DirState.IN_MEMORY_HASH_MODIFIED,
 
1395
                         state._dirblock_state)
 
1396
        self.do_update_entry(state, 'd')
 
1397
        self.assertEqual(2, len(state._known_hash_changes))
 
1398
        state.save()
 
1399
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
 
1400
                         state._dirblock_state)
 
1401
        self.assertEqual(0, len(state._known_hash_changes))
 
1402
 
 
1403
 
1342
1404
class TestGetLines(TestCaseWithDirState):
1343
1405
 
1344
1406
    def test_get_line_with_2_rows(self):
1737
1799
class InstrumentedDirState(dirstate.DirState):
1738
1800
    """An DirState with instrumented sha1 functionality."""
1739
1801
 
1740
 
    def __init__(self, path, sha1_provider):
1741
 
        super(InstrumentedDirState, self).__init__(path, sha1_provider)
 
1802
    def __init__(self, path, sha1_provider, worth_saving_limit=0):
 
1803
        super(InstrumentedDirState, self).__init__(path, sha1_provider,
 
1804
            worth_saving_limit=worth_saving_limit)
1742
1805
        self._time_offset = 0
1743
1806
        self._log = []
1744
1807
        # member is dynamically set in DirState.__init__ to turn on trace
2145
2208
class TestDirstateTreeReference(TestCaseWithDirState):
2146
2209
 
2147
2210
    def test_reference_revision_is_none(self):
2148
 
        tree = self.make_branch_and_tree('tree', format='dirstate-with-subtree')
 
2211
        tree = self.make_branch_and_tree('tree', format='development-subtree')
2149
2212
        subtree = self.make_branch_and_tree('tree/subtree',
2150
 
                            format='dirstate-with-subtree')
 
2213
                            format='development-subtree')
2151
2214
        subtree.set_root_id('subtree')
2152
2215
        tree.add_reference(subtree)
2153
2216
        tree.add('subtree')
2373
2436
        self.assertTrue(len(statvalue) >= 10)
2374
2437
        self.assertEqual(len(text), statvalue.st_size)
2375
2438
        self.assertEqual(expected_sha, sha1)
 
2439
 
 
2440
 
 
2441
class _Repo(object):
 
2442
    """A minimal api to get InventoryRevisionTree to work."""
 
2443
 
 
2444
    def __init__(self):
 
2445
        default_format = controldir.format_registry.make_bzrdir('default')
 
2446
        self._format = default_format.repository_format
 
2447
 
 
2448
    def lock_read(self):
 
2449
        pass
 
2450
 
 
2451
    def unlock(self):
 
2452
        pass
 
2453
 
 
2454
 
 
2455
class TestUpdateBasisByDelta(tests.TestCase):
 
2456
 
 
2457
    def path_to_ie(self, path, file_id, rev_id, dir_ids):
 
2458
        if path.endswith('/'):
 
2459
            is_dir = True
 
2460
            path = path[:-1]
 
2461
        else:
 
2462
            is_dir = False
 
2463
        dirname, basename = osutils.split(path)
 
2464
        try:
 
2465
            dir_id = dir_ids[dirname]
 
2466
        except KeyError:
 
2467
            dir_id = osutils.basename(dirname) + '-id'
 
2468
        if is_dir:
 
2469
            ie = inventory.InventoryDirectory(file_id, basename, dir_id)
 
2470
            dir_ids[path] = file_id
 
2471
        else:
 
2472
            ie = inventory.InventoryFile(file_id, basename, dir_id)
 
2473
            ie.text_size = 0
 
2474
            ie.text_sha1 = ''
 
2475
        ie.revision = rev_id
 
2476
        return ie
 
2477
 
 
2478
    def create_tree_from_shape(self, rev_id, shape):
 
2479
        dir_ids = {'': 'root-id'}
 
2480
        inv = inventory.Inventory('root-id', rev_id)
 
2481
        for info in shape:
 
2482
            if len(info) == 2:
 
2483
                path, file_id = info
 
2484
                ie_rev_id = rev_id
 
2485
            else:
 
2486
                path, file_id, ie_rev_id = info
 
2487
            if path == '':
 
2488
                # Replace the root entry
 
2489
                del inv._byid[inv.root.file_id]
 
2490
                inv.root.file_id = file_id
 
2491
                inv._byid[file_id] = inv.root
 
2492
                dir_ids[''] = file_id
 
2493
                continue
 
2494
            inv.add(self.path_to_ie(path, file_id, ie_rev_id, dir_ids))
 
2495
        return revisiontree.InventoryRevisionTree(_Repo(), inv, rev_id)
 
2496
 
 
2497
    def create_empty_dirstate(self):
 
2498
        fd, path = tempfile.mkstemp(prefix='bzr-dirstate')
 
2499
        self.addCleanup(os.remove, path)
 
2500
        os.close(fd)
 
2501
        state = dirstate.DirState.initialize(path)
 
2502
        self.addCleanup(state.unlock)
 
2503
        return state
 
2504
 
 
2505
    def create_inv_delta(self, delta, rev_id):
 
2506
        """Translate a 'delta shape' into an actual InventoryDelta"""
 
2507
        dir_ids = {'': 'root-id'}
 
2508
        inv_delta = []
 
2509
        for old_path, new_path, file_id in delta:
 
2510
            if old_path is not None and old_path.endswith('/'):
 
2511
                # Don't have to actually do anything for this, because only
 
2512
                # new_path creates InventoryEntries
 
2513
                old_path = old_path[:-1]
 
2514
            if new_path is None: # Delete
 
2515
                inv_delta.append((old_path, None, file_id, None))
 
2516
                continue
 
2517
            ie = self.path_to_ie(new_path, file_id, rev_id, dir_ids)
 
2518
            inv_delta.append((old_path, new_path, file_id, ie))
 
2519
        return inv_delta
 
2520
 
 
2521
    def assertUpdate(self, active, basis, target):
 
2522
        """Assert that update_basis_by_delta works how we want.
 
2523
 
 
2524
        Set up a DirState object with active_shape for tree 0, basis_shape for
 
2525
        tree 1. Then apply the delta from basis_shape to target_shape,
 
2526
        and assert that the DirState is still valid, and that its stored
 
2527
        content matches the target_shape.
 
2528
        """
 
2529
        active_tree = self.create_tree_from_shape('active', active)
 
2530
        basis_tree = self.create_tree_from_shape('basis', basis)
 
2531
        target_tree = self.create_tree_from_shape('target', target)
 
2532
        state = self.create_empty_dirstate()
 
2533
        state.set_state_from_scratch(active_tree.root_inventory,
 
2534
            [('basis', basis_tree)], [])
 
2535
        delta = target_tree.root_inventory._make_delta(
 
2536
            basis_tree.root_inventory)
 
2537
        state.update_basis_by_delta(delta, 'target')
 
2538
        state._validate()
 
2539
        dirstate_tree = workingtree_4.DirStateRevisionTree(state,
 
2540
            'target', _Repo())
 
2541
        # The target now that delta has been applied should match the
 
2542
        # RevisionTree
 
2543
        self.assertEqual([], list(dirstate_tree.iter_changes(target_tree)))
 
2544
        # And the dirblock state should be identical to the state if we created
 
2545
        # it from scratch.
 
2546
        state2 = self.create_empty_dirstate()
 
2547
        state2.set_state_from_scratch(active_tree.root_inventory,
 
2548
            [('target', target_tree)], [])
 
2549
        self.assertEqual(state2._dirblocks, state._dirblocks)
 
2550
        return state
 
2551
 
 
2552
    def assertBadDelta(self, active, basis, delta):
 
2553
        """Test that we raise InconsistentDelta when appropriate.
 
2554
 
 
2555
        :param active: The active tree shape
 
2556
        :param basis: The basis tree shape
 
2557
        :param delta: A description of the delta to apply. Similar to the form
 
2558
            for regular inventory deltas, but omitting the InventoryEntry.
 
2559
            So adding a file is: (None, 'path', 'file-id')
 
2560
            Adding a directory is: (None, 'path/', 'dir-id')
 
2561
            Renaming a dir is: ('old/', 'new/', 'dir-id')
 
2562
            etc.
 
2563
        """
 
2564
        active_tree = self.create_tree_from_shape('active', active)
 
2565
        basis_tree = self.create_tree_from_shape('basis', basis)
 
2566
        inv_delta = self.create_inv_delta(delta, 'target')
 
2567
        state = self.create_empty_dirstate()
 
2568
        state.set_state_from_scratch(active_tree.root_inventory,
 
2569
            [('basis', basis_tree)], [])
 
2570
        self.assertRaises(errors.InconsistentDelta,
 
2571
            state.update_basis_by_delta, inv_delta, 'target')
 
2572
        ## try:
 
2573
        ##     state.update_basis_by_delta(inv_delta, 'target')
 
2574
        ## except errors.InconsistentDelta, e:
 
2575
        ##     import pdb; pdb.set_trace()
 
2576
        ## else:
 
2577
        ##     import pdb; pdb.set_trace()
 
2578
        self.assertTrue(state._changes_aborted)
 
2579
 
 
2580
    def test_remove_file_matching_active_state(self):
 
2581
        state = self.assertUpdate(
 
2582
            active=[],
 
2583
            basis =[('file', 'file-id')],
 
2584
            target=[],
 
2585
            )
 
2586
 
 
2587
    def test_remove_file_present_in_active_state(self):
 
2588
        state = self.assertUpdate(
 
2589
            active=[('file', 'file-id')],
 
2590
            basis =[('file', 'file-id')],
 
2591
            target=[],
 
2592
            )
 
2593
 
 
2594
    def test_remove_file_present_elsewhere_in_active_state(self):
 
2595
        state = self.assertUpdate(
 
2596
            active=[('other-file', 'file-id')],
 
2597
            basis =[('file', 'file-id')],
 
2598
            target=[],
 
2599
            )
 
2600
 
 
2601
    def test_remove_file_active_state_has_diff_file(self):
 
2602
        state = self.assertUpdate(
 
2603
            active=[('file', 'file-id-2')],
 
2604
            basis =[('file', 'file-id')],
 
2605
            target=[],
 
2606
            )
 
2607
 
 
2608
    def test_remove_file_active_state_has_diff_file_and_file_elsewhere(self):
 
2609
        state = self.assertUpdate(
 
2610
            active=[('file', 'file-id-2'),
 
2611
                    ('other-file', 'file-id')],
 
2612
            basis =[('file', 'file-id')],
 
2613
            target=[],
 
2614
            )
 
2615
 
 
2616
    def test_add_file_matching_active_state(self):
 
2617
        state = self.assertUpdate(
 
2618
            active=[('file', 'file-id')],
 
2619
            basis =[],
 
2620
            target=[('file', 'file-id')],
 
2621
            )
 
2622
 
 
2623
    def test_add_file_in_empty_dir_not_matching_active_state(self):
 
2624
        state = self.assertUpdate(
 
2625
                active=[],
 
2626
                basis=[('dir/', 'dir-id')],
 
2627
                target=[('dir/', 'dir-id', 'basis'), ('dir/file', 'file-id')],
 
2628
                )
 
2629
 
 
2630
    def test_add_file_missing_in_active_state(self):
 
2631
        state = self.assertUpdate(
 
2632
            active=[],
 
2633
            basis =[],
 
2634
            target=[('file', 'file-id')],
 
2635
            )
 
2636
 
 
2637
    def test_add_file_elsewhere_in_active_state(self):
 
2638
        state = self.assertUpdate(
 
2639
            active=[('other-file', 'file-id')],
 
2640
            basis =[],
 
2641
            target=[('file', 'file-id')],
 
2642
            )
 
2643
 
 
2644
    def test_add_file_active_state_has_diff_file_and_file_elsewhere(self):
 
2645
        state = self.assertUpdate(
 
2646
            active=[('other-file', 'file-id'),
 
2647
                    ('file', 'file-id-2')],
 
2648
            basis =[],
 
2649
            target=[('file', 'file-id')],
 
2650
            )
 
2651
 
 
2652
    def test_rename_file_matching_active_state(self):
 
2653
        state = self.assertUpdate(
 
2654
            active=[('other-file', 'file-id')],
 
2655
            basis =[('file', 'file-id')],
 
2656
            target=[('other-file', 'file-id')],
 
2657
            )
 
2658
 
 
2659
    def test_rename_file_missing_in_active_state(self):
 
2660
        state = self.assertUpdate(
 
2661
            active=[],
 
2662
            basis =[('file', 'file-id')],
 
2663
            target=[('other-file', 'file-id')],
 
2664
            )
 
2665
 
 
2666
    def test_rename_file_present_elsewhere_in_active_state(self):
 
2667
        state = self.assertUpdate(
 
2668
            active=[('third', 'file-id')],
 
2669
            basis =[('file', 'file-id')],
 
2670
            target=[('other-file', 'file-id')],
 
2671
            )
 
2672
 
 
2673
    def test_rename_file_active_state_has_diff_source_file(self):
 
2674
        state = self.assertUpdate(
 
2675
            active=[('file', 'file-id-2')],
 
2676
            basis =[('file', 'file-id')],
 
2677
            target=[('other-file', 'file-id')],
 
2678
            )
 
2679
 
 
2680
    def test_rename_file_active_state_has_diff_target_file(self):
 
2681
        state = self.assertUpdate(
 
2682
            active=[('other-file', 'file-id-2')],
 
2683
            basis =[('file', 'file-id')],
 
2684
            target=[('other-file', 'file-id')],
 
2685
            )
 
2686
 
 
2687
    def test_rename_file_active_has_swapped_files(self):
 
2688
        state = self.assertUpdate(
 
2689
            active=[('file', 'file-id'),
 
2690
                    ('other-file', 'file-id-2')],
 
2691
            basis= [('file', 'file-id'),
 
2692
                    ('other-file', 'file-id-2')],
 
2693
            target=[('file', 'file-id-2'),
 
2694
                    ('other-file', 'file-id')])
 
2695
 
 
2696
    def test_rename_file_basis_has_swapped_files(self):
 
2697
        state = self.assertUpdate(
 
2698
            active=[('file', 'file-id'),
 
2699
                    ('other-file', 'file-id-2')],
 
2700
            basis= [('file', 'file-id-2'),
 
2701
                    ('other-file', 'file-id')],
 
2702
            target=[('file', 'file-id'),
 
2703
                    ('other-file', 'file-id-2')])
 
2704
 
 
2705
    def test_rename_directory_with_contents(self):
 
2706
        state = self.assertUpdate( # active matches basis
 
2707
            active=[('dir1/', 'dir-id'),
 
2708
                    ('dir1/file', 'file-id')],
 
2709
            basis= [('dir1/', 'dir-id'),
 
2710
                    ('dir1/file', 'file-id')],
 
2711
            target=[('dir2/', 'dir-id'),
 
2712
                    ('dir2/file', 'file-id')])
 
2713
        state = self.assertUpdate( # active matches target
 
2714
            active=[('dir2/', 'dir-id'),
 
2715
                    ('dir2/file', 'file-id')],
 
2716
            basis= [('dir1/', 'dir-id'),
 
2717
                    ('dir1/file', 'file-id')],
 
2718
            target=[('dir2/', 'dir-id'),
 
2719
                    ('dir2/file', 'file-id')])
 
2720
        state = self.assertUpdate( # active empty
 
2721
            active=[],
 
2722
            basis= [('dir1/', 'dir-id'),
 
2723
                    ('dir1/file', 'file-id')],
 
2724
            target=[('dir2/', 'dir-id'),
 
2725
                    ('dir2/file', 'file-id')])
 
2726
        state = self.assertUpdate( # active present at other location
 
2727
            active=[('dir3/', 'dir-id'),
 
2728
                    ('dir3/file', 'file-id')],
 
2729
            basis= [('dir1/', 'dir-id'),
 
2730
                    ('dir1/file', 'file-id')],
 
2731
            target=[('dir2/', 'dir-id'),
 
2732
                    ('dir2/file', 'file-id')])
 
2733
        state = self.assertUpdate( # active has different ids
 
2734
            active=[('dir1/', 'dir1-id'),
 
2735
                    ('dir1/file', 'file1-id'),
 
2736
                    ('dir2/', 'dir2-id'),
 
2737
                    ('dir2/file', 'file2-id')],
 
2738
            basis= [('dir1/', 'dir-id'),
 
2739
                    ('dir1/file', 'file-id')],
 
2740
            target=[('dir2/', 'dir-id'),
 
2741
                    ('dir2/file', 'file-id')])
 
2742
 
 
2743
    def test_invalid_file_not_present(self):
 
2744
        state = self.assertBadDelta(
 
2745
            active=[('file', 'file-id')],
 
2746
            basis= [('file', 'file-id')],
 
2747
            delta=[('other-file', 'file', 'file-id')])
 
2748
 
 
2749
    def test_invalid_new_id_same_path(self):
 
2750
        # The bad entry comes after
 
2751
        state = self.assertBadDelta(
 
2752
            active=[('file', 'file-id')],
 
2753
            basis= [('file', 'file-id')],
 
2754
            delta=[(None, 'file', 'file-id-2')])
 
2755
        # The bad entry comes first
 
2756
        state = self.assertBadDelta(
 
2757
            active=[('file', 'file-id-2')],
 
2758
            basis=[('file', 'file-id-2')],
 
2759
            delta=[(None, 'file', 'file-id')])
 
2760
 
 
2761
    def test_invalid_existing_id(self):
 
2762
        state = self.assertBadDelta(
 
2763
            active=[('file', 'file-id')],
 
2764
            basis= [('file', 'file-id')],
 
2765
            delta=[(None, 'file', 'file-id')])
 
2766
 
 
2767
    def test_invalid_parent_missing(self):
 
2768
        state = self.assertBadDelta(
 
2769
            active=[],
 
2770
            basis= [],
 
2771
            delta=[(None, 'path/path2', 'file-id')])
 
2772
        # Note: we force the active tree to have the directory, by knowing how
 
2773
        #       path_to_ie handles entries with missing parents
 
2774
        state = self.assertBadDelta(
 
2775
            active=[('path/', 'path-id')],
 
2776
            basis= [],
 
2777
            delta=[(None, 'path/path2', 'file-id')])
 
2778
        state = self.assertBadDelta(
 
2779
            active=[('path/', 'path-id'),
 
2780
                    ('path/path2', 'file-id')],
 
2781
            basis= [],
 
2782
            delta=[(None, 'path/path2', 'file-id')])
 
2783
 
 
2784
    def test_renamed_dir_same_path(self):
 
2785
        # We replace the parent directory, with another parent dir. But the C
 
2786
        # file doesn't look like it has been moved.
 
2787
        state = self.assertUpdate(# Same as basis
 
2788
            active=[('dir/', 'A-id'),
 
2789
                    ('dir/B', 'B-id')],
 
2790
            basis= [('dir/', 'A-id'),
 
2791
                    ('dir/B', 'B-id')],
 
2792
            target=[('dir/', 'C-id'),
 
2793
                    ('dir/B', 'B-id')])
 
2794
        state = self.assertUpdate(# Same as target
 
2795
            active=[('dir/', 'C-id'),
 
2796
                    ('dir/B', 'B-id')],
 
2797
            basis= [('dir/', 'A-id'),
 
2798
                    ('dir/B', 'B-id')],
 
2799
            target=[('dir/', 'C-id'),
 
2800
                    ('dir/B', 'B-id')])
 
2801
        state = self.assertUpdate(# empty active
 
2802
            active=[],
 
2803
            basis= [('dir/', 'A-id'),
 
2804
                    ('dir/B', 'B-id')],
 
2805
            target=[('dir/', 'C-id'),
 
2806
                    ('dir/B', 'B-id')])
 
2807
        state = self.assertUpdate(# different active
 
2808
            active=[('dir/', 'D-id'),
 
2809
                    ('dir/B', 'B-id')],
 
2810
            basis= [('dir/', 'A-id'),
 
2811
                    ('dir/B', 'B-id')],
 
2812
            target=[('dir/', 'C-id'),
 
2813
                    ('dir/B', 'B-id')])
 
2814
 
 
2815
    def test_parent_child_swap(self):
 
2816
        state = self.assertUpdate(# Same as basis
 
2817
            active=[('A/', 'A-id'),
 
2818
                    ('A/B/', 'B-id'),
 
2819
                    ('A/B/C', 'C-id')],
 
2820
            basis= [('A/', 'A-id'),
 
2821
                    ('A/B/', 'B-id'),
 
2822
                    ('A/B/C', 'C-id')],
 
2823
            target=[('A/', 'B-id'),
 
2824
                    ('A/B/', 'A-id'),
 
2825
                    ('A/B/C', 'C-id')])
 
2826
        state = self.assertUpdate(# Same as target
 
2827
            active=[('A/', 'B-id'),
 
2828
                    ('A/B/', 'A-id'),
 
2829
                    ('A/B/C', 'C-id')],
 
2830
            basis= [('A/', 'A-id'),
 
2831
                    ('A/B/', 'B-id'),
 
2832
                    ('A/B/C', 'C-id')],
 
2833
            target=[('A/', 'B-id'),
 
2834
                    ('A/B/', 'A-id'),
 
2835
                    ('A/B/C', 'C-id')])
 
2836
        state = self.assertUpdate(# empty active
 
2837
            active=[],
 
2838
            basis= [('A/', 'A-id'),
 
2839
                    ('A/B/', 'B-id'),
 
2840
                    ('A/B/C', 'C-id')],
 
2841
            target=[('A/', 'B-id'),
 
2842
                    ('A/B/', 'A-id'),
 
2843
                    ('A/B/C', 'C-id')])
 
2844
        state = self.assertUpdate(# different active
 
2845
            active=[('D/', 'A-id'),
 
2846
                    ('D/E/', 'B-id'),
 
2847
                    ('F', 'C-id')],
 
2848
            basis= [('A/', 'A-id'),
 
2849
                    ('A/B/', 'B-id'),
 
2850
                    ('A/B/C', 'C-id')],
 
2851
            target=[('A/', 'B-id'),
 
2852
                    ('A/B/', 'A-id'),
 
2853
                    ('A/B/C', 'C-id')])
 
2854
 
 
2855
    def test_change_root_id(self):
 
2856
        state = self.assertUpdate( # same as basis
 
2857
            active=[('', 'root-id'),
 
2858
                    ('file', 'file-id')],
 
2859
            basis= [('', 'root-id'),
 
2860
                    ('file', 'file-id')],
 
2861
            target=[('', 'target-root-id'),
 
2862
                    ('file', 'file-id')])
 
2863
        state = self.assertUpdate( # same as target
 
2864
            active=[('', 'target-root-id'),
 
2865
                    ('file', 'file-id')],
 
2866
            basis= [('', 'root-id'),
 
2867
                    ('file', 'file-id')],
 
2868
            target=[('', 'target-root-id'),
 
2869
                    ('file', 'root-id')])
 
2870
        state = self.assertUpdate( # all different
 
2871
            active=[('', 'active-root-id'),
 
2872
                    ('file', 'file-id')],
 
2873
            basis= [('', 'root-id'),
 
2874
                    ('file', 'file-id')],
 
2875
            target=[('', 'target-root-id'),
 
2876
                    ('file', 'root-id')])
 
2877
 
 
2878
    def test_change_file_absent_in_active(self):
 
2879
        state = self.assertUpdate(
 
2880
            active=[],
 
2881
            basis= [('file', 'file-id')],
 
2882
            target=[('file', 'file-id')])
 
2883
 
 
2884
    def test_invalid_changed_file(self):
 
2885
        state = self.assertBadDelta( # Not present in basis
 
2886
            active=[('file', 'file-id')],
 
2887
            basis= [],
 
2888
            delta=[('file', 'file', 'file-id')])
 
2889
        state = self.assertBadDelta( # present at another location in basis
 
2890
            active=[('file', 'file-id')],
 
2891
            basis= [('other-file', 'file-id')],
 
2892
            delta=[('file', 'file', 'file-id')])