/brz/remove-bazaar

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

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_inv.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-10-03 05:04:42 UTC
  • mfrom: (2776.4.19 commit)
  • Revision ID: pqm@pqm.ubuntu.com-20071003050442-e0x9ofdfo0hwxnal
(robertc) Move serialisation of inventory entries into CommitBuilder. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
        self.assertEqual(len(wt.inventory), 1)
44
44
 
45
45
 
46
 
class TestSnapshot(TestCaseWithWorkingTree):
47
 
 
48
 
    def setUp(self):
49
 
        # for full testing we'll need a branch
50
 
        # with a subdir to test parent changes.
51
 
        # and a file, link and dir under that.
52
 
        # but right now I only need one attribute
53
 
        # to change, and then test merge patterns
54
 
        # with fake parent entries.
55
 
        super(TestSnapshot, self).setUp()
56
 
        self.wt = self.make_branch_and_tree('.')
57
 
        self.branch = self.wt.branch
58
 
        self.build_tree(['subdir/', 'subdir/file'], line_endings='binary')
59
 
        self.wt.add(['subdir', 'subdir/file'],
60
 
                                       ['dirid', 'fileid'])
61
 
        self.wt.commit('message_1', rev_id = '1')
62
 
        self.tree_1 = self.branch.repository.revision_tree('1')
63
 
        self.inv_1 = self.branch.repository.get_inventory('1')
64
 
        self.file_1 = self.inv_1['fileid']
65
 
        self.wt.lock_write()
66
 
        self.addCleanup(self.wt.unlock)
67
 
        self.file_active = self.wt.inventory['fileid']
68
 
        self.builder = self.branch.get_commit_builder([], timestamp=time.time(), revision_id='2')
69
 
 
70
 
    def test_snapshot_new_revision(self):
71
 
        # This tests that a simple commit with no parents makes a new
72
 
        # revision value in the inventory entry
73
 
        self.file_active.snapshot('2', 'subdir/file', {}, self.wt, self.builder)
74
 
        # expected outcome - file_1 has a revision id of '2', and we can get
75
 
        # its text of 'file contents' out of the weave.
76
 
        self.assertEqual(self.file_1.revision, '1')
77
 
        self.assertEqual(self.file_active.revision, '2')
78
 
        # this should be a separate test probably, but lets check it once..
79
 
        lines = self.branch.repository.weave_store.get_weave(
80
 
            'fileid', 
81
 
            self.branch.repository.get_transaction()).get_lines('2')
82
 
        self.assertEqual(lines, ['contents of subdir/file\n'])
83
 
        self.wt.branch.repository.commit_write_group()
84
 
 
85
 
    def test_snapshot_unchanged(self):
86
 
        #This tests that a simple commit does not make a new entry for
87
 
        # an unchanged inventory entry
88
 
        self.file_active.snapshot('2', 'subdir/file', {'1':self.file_1},
89
 
                                  self.wt, self.builder)
90
 
        self.assertEqual(self.file_1.revision, '1')
91
 
        self.assertEqual(self.file_active.revision, '1')
92
 
        vf = self.branch.repository.weave_store.get_weave(
93
 
            'fileid', 
94
 
            self.branch.repository.get_transaction())
95
 
        self.assertRaises(errors.RevisionNotPresent,
96
 
                          vf.get_lines,
97
 
                          '2')
98
 
        self.wt.branch.repository.commit_write_group()
99
 
 
100
 
    def test_snapshot_merge_identical_different_revid(self):
101
 
        # This tests that a commit with two identical parents, one of which has
102
 
        # a different revision id, results in a new revision id in the entry.
103
 
        # 1->other, commit a merge of other against 1, results in 2.
104
 
        other_ie = inventory.InventoryFile('fileid', 'newname', self.file_1.parent_id)
105
 
        other_ie = inventory.InventoryFile('fileid', 'file', self.file_1.parent_id)
106
 
        other_ie.revision = '1'
107
 
        other_ie.text_sha1 = self.file_1.text_sha1
108
 
        other_ie.text_size = self.file_1.text_size
109
 
        self.assertEqual(self.file_1, other_ie)
110
 
        other_ie.revision = 'other'
111
 
        self.assertNotEqual(self.file_1, other_ie)
112
 
        versionfile = self.branch.repository.weave_store.get_weave(
113
 
            'fileid', self.branch.repository.get_transaction())
114
 
        versionfile.clone_text('other', '1', ['1'])
115
 
        self.file_active.snapshot('2', 'subdir/file', 
116
 
                                  {'1':self.file_1, 'other':other_ie},
117
 
                                  self.wt, self.builder)
118
 
        self.assertEqual(self.file_active.revision, '2')
119
 
        self.wt.branch.repository.commit_write_group()
120
 
 
121
 
    def test_snapshot_changed(self):
122
 
        # This tests that a commit with one different parent results in a new
123
 
        # revision id in the entry.
124
 
        self.wt.rename_one('subdir/file', 'subdir/newname')
125
 
        self.file_active = self.wt.inventory['fileid']
126
 
        self.file_active.snapshot('2', 'subdir/newname', {'1':self.file_1}, 
127
 
                                  self.wt, self.builder)
128
 
        # expected outcome - file_1 has a revision id of '2'
129
 
        self.assertEqual(self.file_active.revision, '2')
130
 
        self.wt.branch.repository.commit_write_group()
131
 
 
132
 
 
133
46
class TestApplyInventoryDelta(TestCaseWithWorkingTree):
134
47
 
135
48
    def test_add(self):