~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-07-06 03:15:29 UTC
  • mfrom: (1711.2.78 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060706031529-e189d8c3f42076be
(jam) allow plugins to include benchmarks

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005 by Canonical Ltd
2
2
#
3
3
# Authors:
4
4
#   Johan Rydberg <jrydberg@gnu.org>
7
7
# it under the terms of the GNU General Public License as published by
8
8
# the Free Software Foundation; either version 2 of the License, or
9
9
# (at your option) any later version.
10
 
#
 
10
 
11
11
# This program is distributed in the hope that it will be useful,
12
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
14
# GNU General Public License for more details.
15
 
#
 
15
 
16
16
# You should have received a copy of the GNU General Public License
17
17
# along with this program; if not, write to the Free Software
18
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
24
from StringIO import StringIO
25
25
 
26
26
import bzrlib
27
 
from bzrlib import (
28
 
    errors,
29
 
    osutils,
30
 
    progress,
31
 
    )
 
27
import bzrlib.errors as errors
32
28
from bzrlib.errors import (
33
29
                           RevisionNotPresent, 
34
30
                           RevisionAlreadyPresent,
141
137
        except NotImplementedError:
142
138
            pass
143
139
 
144
 
    def test_add_reserved(self):
145
 
        vf = self.get_file()
146
 
        self.assertRaises(errors.ReservedId,
147
 
            vf.add_lines, 'a:', [], ['a\n', 'b\n', 'c\n'])
148
 
 
149
 
        self.assertRaises(errors.ReservedId,
150
 
            vf.add_delta, 'a:', [], None, 'sha1', False, ((0, 0, 0, []),))
151
 
 
152
 
    def test_get_reserved(self):
153
 
        vf = self.get_file()
154
 
        self.assertRaises(errors.ReservedId, vf.get_delta, 'b:')
155
 
        self.assertRaises(errors.ReservedId, vf.get_texts, ['b:'])
156
 
        self.assertRaises(errors.ReservedId, vf.get_lines, 'b:')
157
 
        self.assertRaises(errors.ReservedId, vf.get_text, 'b:')
158
 
 
159
140
    def test_get_delta(self):
160
141
        f = self.get_file()
161
142
        sha1s = self._setup_for_deltas(f)
214
195
        self.assertEqual(expected_delta, deltas['noeol'])
215
196
        # smoke tests for eol support - two noeol in a row same content
216
197
        expected_deltas = (('noeol', '3ad7ee82dbd8f29ecba073f96e43e414b3f70a4d', True, 
217
 
                          [(0, 1, 2, [('noeolsecond', 'line\n'), ('noeolsecond', 'line\n')])]),
 
198
                          [(0, 1, 2, [(u'noeolsecond', 'line\n'), (u'noeolsecond', 'line\n')])]),
218
199
                          ('noeol', '3ad7ee82dbd8f29ecba073f96e43e414b3f70a4d', True, 
219
200
                           [(0, 0, 1, [('noeolsecond', 'line\n')]), (1, 1, 0, [])]))
220
201
        self.assertEqual(['line\n', 'line'], f.get_lines('noeolsecond'))
221
202
        self.assertTrue(deltas['noeolsecond'] in expected_deltas)
222
203
        # two no-eol in a row, different content
223
204
        expected_delta = ('noeolsecond', '8bb553a84e019ef1149db082d65f3133b195223b', True, 
224
 
                          [(1, 2, 1, [('noeolnotshared', 'phone\n')])])
 
205
                          [(1, 2, 1, [(u'noeolnotshared', 'phone\n')])])
225
206
        self.assertEqual(['line\n', 'phone'], f.get_lines('noeolnotshared'))
226
207
        self.assertEqual(expected_delta, deltas['noeolnotshared'])
227
208
        # eol folling a no-eol with content change
228
209
        expected_delta = ('noeol', 'a61f6fb6cfc4596e8d88c34a308d1e724caf8977', False, 
229
 
                          [(0, 1, 1, [('eol', 'phone\n')])])
 
210
                          [(0, 1, 1, [(u'eol', 'phone\n')])])
230
211
        self.assertEqual(['phone\n'], f.get_lines('eol'))
231
212
        self.assertEqual(expected_delta, deltas['eol'])
232
213
        # eol folling a no-eol with content change
233
214
        expected_delta = ('noeol', '6bfa09d82ce3e898ad4641ae13dd4fdb9cf0d76b', False, 
234
 
                          [(0, 1, 1, [('eolline', 'line\n')])])
 
215
                          [(0, 1, 1, [(u'eolline', 'line\n')])])
235
216
        self.assertEqual(['line\n'], f.get_lines('eolline'))
236
217
        self.assertEqual(expected_delta, deltas['eolline'])
237
218
        # eol with no parents
238
219
        expected_delta = (None, '264f39cab871e4cfd65b3a002f7255888bb5ed97', True, 
239
 
                          [(0, 0, 1, [('noeolbase', 'line\n')])])
 
220
                          [(0, 0, 1, [(u'noeolbase', 'line\n')])])
240
221
        self.assertEqual(['line'], f.get_lines('noeolbase'))
241
222
        self.assertEqual(expected_delta, deltas['noeolbase'])
242
223
        # eol with two parents, in inverse insertion order
243
224
        expected_deltas = (('noeolbase', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
244
 
                            [(0, 1, 1, [('eolbeforefirstparent', 'line\n')])]),
 
225
                            [(0, 1, 1, [(u'eolbeforefirstparent', 'line\n')])]),
245
226
                           ('noeolbase', '264f39cab871e4cfd65b3a002f7255888bb5ed97', True,
246
 
                            [(0, 1, 1, [('eolbeforefirstparent', 'line\n')])]))
 
227
                            [(0, 1, 1, [(u'eolbeforefirstparent', 'line\n')])]))
247
228
        self.assertEqual(['line'], f.get_lines('eolbeforefirstparent'))
248
229
        #self.assertTrue(deltas['eolbeforefirstparent'] in expected_deltas)
249
230
 
384
365
        self.assertRaises(RevisionNotPresent,
385
366
            f.get_ancestry, ['rM', 'rX'])
386
367
 
387
 
        self.assertEqual(set(f.get_ancestry('rM')),
388
 
            set(f.get_ancestry('rM', topo_sorted=False)))
389
 
 
390
368
    def test_mutate_after_finish(self):
391
369
        f = self.get_file()
392
370
        f.transaction_finished()
565
543
        # versions in the weave 
566
544
        # the ordering here is to make a tree so that dumb searches have
567
545
        # more changes to muck up.
568
 
 
569
 
        class InstrumentedProgress(progress.DummyProgress):
570
 
 
571
 
            def __init__(self):
572
 
 
573
 
                progress.DummyProgress.__init__(self)
574
 
                self.updates = []
575
 
 
576
 
            def update(self, msg=None, current=None, total=None):
577
 
                self.updates.append((msg, current, total))
578
 
 
579
546
        vf = self.get_file()
580
547
        # add a base to get included
581
548
        vf.add_lines('base', [], ['base\n'])
589
556
        vf.add_lines('otherchild',
590
557
                     ['lancestor', 'base'],
591
558
                     ['base\n', 'lancestor\n', 'otherchild\n'])
592
 
        def iter_with_versions(versions, expected):
 
559
        def iter_with_versions(versions):
593
560
            # now we need to see what lines are returned, and how often.
594
561
            lines = {'base\n':0,
595
562
                     'lancestor\n':0,
597
564
                     'child\n':0,
598
565
                     'otherchild\n':0,
599
566
                     }
600
 
            progress = InstrumentedProgress()
601
567
            # iterate over the lines
602
 
            for line in vf.iter_lines_added_or_present_in_versions(versions, 
603
 
                pb=progress):
 
568
            for line in vf.iter_lines_added_or_present_in_versions(versions):
604
569
                lines[line] += 1
605
 
            if []!= progress.updates: 
606
 
                self.assertEqual(expected, progress.updates)
607
570
            return lines
608
 
        lines = iter_with_versions(['child', 'otherchild'],
609
 
                                   [('Walking content.', 0, 2),
610
 
                                    ('Walking content.', 1, 2),
611
 
                                    ('Walking content.', 2, 2)])
 
571
        lines = iter_with_versions(['child', 'otherchild'])
612
572
        # we must see child and otherchild
613
573
        self.assertTrue(lines['child\n'] > 0)
614
574
        self.assertTrue(lines['otherchild\n'] > 0)
615
575
        # we dont care if we got more than that.
616
576
        
617
577
        # test all lines
618
 
        lines = iter_with_versions(None, [('Walking content.', 0, 5),
619
 
                                          ('Walking content.', 1, 5),
620
 
                                          ('Walking content.', 2, 5),
621
 
                                          ('Walking content.', 3, 5),
622
 
                                          ('Walking content.', 4, 5),
623
 
                                          ('Walking content.', 5, 5)])
 
578
        lines = iter_with_versions(None)
624
579
        # all lines must be seen at least once
625
580
        self.assertTrue(lines['base\n'] > 0)
626
581
        self.assertTrue(lines['lancestor\n'] > 0)
672
627
        # add_lines_with_ghosts api.
673
628
        vf = self.get_file()
674
629
        # add a revision with ghost parents
675
 
        # The preferred form is utf8, but we should translate when needed
676
 
        parent_id_unicode = u'b\xbfse'
677
 
        parent_id_utf8 = parent_id_unicode.encode('utf8')
678
630
        try:
679
 
            vf.add_lines_with_ghosts('notbxbfse', [parent_id_utf8], [])
 
631
            vf.add_lines_with_ghosts(u'notbxbfse', [u'b\xbfse'], [])
680
632
        except NotImplementedError:
681
633
            # check the other ghost apis are also not implemented
682
634
            self.assertRaises(NotImplementedError, vf.has_ghost, 'foo')
684
636
            self.assertRaises(NotImplementedError, vf.get_parents_with_ghosts, 'foo')
685
637
            self.assertRaises(NotImplementedError, vf.get_graph_with_ghosts)
686
638
            return
687
 
        vf = self.reopen_file()
688
639
        # test key graph related apis: getncestry, _graph, get_parents
689
640
        # has_version
690
641
        # - these are ghost unaware and must not be reflect ghosts
691
 
        self.assertEqual(['notbxbfse'], vf.get_ancestry('notbxbfse'))
692
 
        self.assertEqual([], vf.get_parents('notbxbfse'))
693
 
        self.assertEqual({'notbxbfse':[]}, vf.get_graph())
694
 
        self.assertFalse(self.callDeprecated([osutils._revision_id_warning],
695
 
                         vf.has_version, parent_id_unicode))
696
 
        self.assertFalse(vf.has_version(parent_id_utf8))
 
642
        self.assertEqual([u'notbxbfse'], vf.get_ancestry(u'notbxbfse'))
 
643
        self.assertEqual([], vf.get_parents(u'notbxbfse'))
 
644
        self.assertEqual({u'notbxbfse':[]}, vf.get_graph())
 
645
        self.assertFalse(vf.has_version(u'b\xbfse'))
697
646
        # we have _with_ghost apis to give us ghost information.
698
 
        self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry_with_ghosts(['notbxbfse']))
699
 
        self.assertEqual([parent_id_utf8], vf.get_parents_with_ghosts('notbxbfse'))
700
 
        self.assertEqual({'notbxbfse':[parent_id_utf8]}, vf.get_graph_with_ghosts())
701
 
        self.assertTrue(self.callDeprecated([osutils._revision_id_warning],
702
 
                        vf.has_ghost, parent_id_unicode))
703
 
        self.assertTrue(vf.has_ghost(parent_id_utf8))
 
647
        self.assertEqual([u'b\xbfse', u'notbxbfse'], vf.get_ancestry_with_ghosts([u'notbxbfse']))
 
648
        self.assertEqual([u'b\xbfse'], vf.get_parents_with_ghosts(u'notbxbfse'))
 
649
        self.assertEqual({u'notbxbfse':[u'b\xbfse']}, vf.get_graph_with_ghosts())
 
650
        self.assertTrue(vf.has_ghost(u'b\xbfse'))
704
651
        # if we add something that is a ghost of another, it should correct the
705
652
        # results of the prior apis
706
 
        self.callDeprecated([osutils._revision_id_warning],
707
 
                            vf.add_lines, parent_id_unicode, [], [])
708
 
        self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry(['notbxbfse']))
709
 
        self.assertEqual([parent_id_utf8], vf.get_parents('notbxbfse'))
710
 
        self.assertEqual({parent_id_utf8:[],
711
 
                          'notbxbfse':[parent_id_utf8],
 
653
        vf.add_lines(u'b\xbfse', [], [])
 
654
        self.assertEqual([u'b\xbfse', u'notbxbfse'], vf.get_ancestry([u'notbxbfse']))
 
655
        self.assertEqual([u'b\xbfse'], vf.get_parents(u'notbxbfse'))
 
656
        self.assertEqual({u'b\xbfse':[],
 
657
                          u'notbxbfse':[u'b\xbfse'],
712
658
                          },
713
659
                         vf.get_graph())
714
 
        self.assertTrue(self.callDeprecated([osutils._revision_id_warning],
715
 
                        vf.has_version, parent_id_unicode))
716
 
        self.assertTrue(vf.has_version(parent_id_utf8))
 
660
        self.assertTrue(vf.has_version(u'b\xbfse'))
717
661
        # we have _with_ghost apis to give us ghost information.
718
 
        self.assertEqual([parent_id_utf8, 'notbxbfse'], vf.get_ancestry_with_ghosts(['notbxbfse']))
719
 
        self.assertEqual([parent_id_utf8], vf.get_parents_with_ghosts('notbxbfse'))
720
 
        self.assertEqual({parent_id_utf8:[],
721
 
                          'notbxbfse':[parent_id_utf8],
 
662
        self.assertEqual([u'b\xbfse', u'notbxbfse'], vf.get_ancestry_with_ghosts([u'notbxbfse']))
 
663
        self.assertEqual([u'b\xbfse'], vf.get_parents_with_ghosts(u'notbxbfse'))
 
664
        self.assertEqual({u'b\xbfse':[],
 
665
                          u'notbxbfse':[u'b\xbfse'],
722
666
                          },
723
667
                         vf.get_graph_with_ghosts())
724
 
        self.assertFalse(self.callDeprecated([osutils._revision_id_warning],
725
 
                         vf.has_ghost, parent_id_unicode))
726
 
        self.assertFalse(vf.has_ghost(parent_id_utf8))
 
668
        self.assertFalse(vf.has_ghost(u'b\xbfse'))
727
669
 
728
670
    def test_add_lines_with_ghosts_after_normal_revs(self):
729
671
        # some versioned file formats allow lines to be added with parent