~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_versionedfile.py

  • Committer: John Arbash Meinel
  • Date: 2009-09-22 02:18:24 UTC
  • mto: This revision was merged to the branch mainline in revision 4709.
  • Revision ID: john@arbash-meinel.com-20090922021824-j3en52uqoof7ym89
Remove some assert statements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2009 Canonical Ltd
2
2
#
3
3
# Authors:
4
4
#   Johan Rydberg <jrydberg@gnu.org>
31
31
    knit as _mod_knit,
32
32
    osutils,
33
33
    progress,
34
 
    transport,
35
34
    ui,
36
35
    )
37
36
from bzrlib.errors import (
57
56
    )
58
57
from bzrlib.tests.http_utils import TestCaseWithWebserver
59
58
from bzrlib.trace import mutter
 
59
from bzrlib.transport import get_transport
60
60
from bzrlib.transport.memory import MemoryTransport
61
61
from bzrlib.tsort import topo_sort
62
62
from bzrlib.tuned_gzip import GzipFile
734
734
        # the ordering here is to make a tree so that dumb searches have
735
735
        # more changes to muck up.
736
736
 
737
 
        class InstrumentedProgress(progress.ProgressTask):
 
737
        class InstrumentedProgress(progress.DummyProgress):
738
738
 
739
739
            def __init__(self):
740
 
                progress.ProgressTask.__init__(self)
 
740
 
 
741
                progress.DummyProgress.__init__(self)
741
742
                self.updates = []
742
743
 
743
744
            def update(self, msg=None, current=None, total=None):
849
850
        self.assertEquals(('references_ghost', 'line_c\n'), origins[2])
850
851
 
851
852
    def test_readonly_mode(self):
852
 
        t = transport.get_transport(self.get_url('.'))
 
853
        transport = get_transport(self.get_url('.'))
853
854
        factory = self.get_factory()
854
 
        vf = factory('id', t, 0777, create=True, access_mode='w')
855
 
        vf = factory('id', t, access_mode='r')
 
855
        vf = factory('id', transport, 0777, create=True, access_mode='w')
 
856
        vf = factory('id', transport, access_mode='r')
856
857
        self.assertRaises(errors.ReadOnlyError, vf.add_lines, 'base', [], [])
857
858
        self.assertRaises(errors.ReadOnlyError,
858
859
                          vf.add_lines_with_ghosts,
880
881
class TestWeave(TestCaseWithMemoryTransport, VersionedFileTestMixIn):
881
882
 
882
883
    def get_file(self, name='foo'):
883
 
        return WeaveFile(name, transport.get_transport(self.get_url('.')),
884
 
                         create=True,
885
 
                         get_scope=self.get_transaction)
 
884
        return WeaveFile(name, get_transport(self.get_url('.')), create=True,
 
885
            get_scope=self.get_transaction)
886
886
 
887
887
    def get_file_corrupted_text(self):
888
 
        w = WeaveFile('foo', transport.get_transport(self.get_url('.')),
889
 
                      create=True,
890
 
                      get_scope=self.get_transaction)
 
888
        w = WeaveFile('foo', get_transport(self.get_url('.')), create=True,
 
889
            get_scope=self.get_transaction)
891
890
        w.add_lines('v1', [], ['hello\n'])
892
891
        w.add_lines('v2', ['v1'], ['hello\n', 'there\n'])
893
892
 
921
920
        return w
922
921
 
923
922
    def reopen_file(self, name='foo', create=False):
924
 
        return WeaveFile(name, transport.get_transport(self.get_url('.')),
925
 
                         create=create,
926
 
                         get_scope=self.get_transaction)
 
923
        return WeaveFile(name, get_transport(self.get_url('.')), create=create,
 
924
            get_scope=self.get_transaction)
927
925
 
928
926
    def test_no_implicit_create(self):
929
927
        self.assertRaises(errors.NoSuchFile,
930
928
                          WeaveFile,
931
929
                          'foo',
932
 
                          transport.get_transport(self.get_url('.')),
 
930
                          get_transport(self.get_url('.')),
933
931
                          get_scope=self.get_transaction)
934
932
 
935
933
    def get_factory(self):
1002
1000
        # we should be able to read from http with a versioned file.
1003
1001
        vf = self.get_file()
1004
1002
        # try an empty file access
1005
 
        readonly_vf = self.get_factory()('foo', transport.get_transport(
1006
 
                self.get_readonly_url('.')))
 
1003
        readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
1007
1004
        self.assertEqual([], readonly_vf.versions())
1008
 
 
1009
 
    def test_readonly_http_works_with_feeling(self):
1010
 
        # we should be able to read from http with a versioned file.
1011
 
        vf = self.get_file()
1012
1005
        # now with feeling.
1013
1006
        vf.add_lines('1', [], ['a\n'])
1014
1007
        vf.add_lines('2', ['1'], ['b\n', 'a\n'])
1015
 
        readonly_vf = self.get_factory()('foo', transport.get_transport(
1016
 
                self.get_readonly_url('.')))
 
1008
        readonly_vf = self.get_factory()('foo', get_transport(self.get_readonly_url('.')))
1017
1009
        self.assertEqual(['1', '2'], vf.versions())
1018
 
        self.assertEqual(['1', '2'], readonly_vf.versions())
1019
1010
        for version in readonly_vf.versions():
1020
1011
            readonly_vf.get_lines(version)
1021
1012
 
1023
1014
class TestWeaveHTTP(TestCaseWithWebserver, TestReadonlyHttpMixin):
1024
1015
 
1025
1016
    def get_file(self):
1026
 
        return WeaveFile('foo', transport.get_transport(self.get_url('.')),
1027
 
                         create=True,
1028
 
                         get_scope=self.get_transaction)
 
1017
        return WeaveFile('foo', get_transport(self.get_url('.')), create=True,
 
1018
            get_scope=self.get_transaction)
1029
1019
 
1030
1020
    def get_factory(self):
1031
1021
        return WeaveFile
1275
1265
class TestWeaveMerge(TestCaseWithMemoryTransport, MergeCasesMixin):
1276
1266
 
1277
1267
    def get_file(self, name='foo'):
1278
 
        return WeaveFile(name, transport.get_transport(self.get_url('.')),
1279
 
                         create=True)
 
1268
        return WeaveFile(name, get_transport(self.get_url('.')), create=True)
1280
1269
 
1281
1270
    def log_contents(self, w):
1282
1271
        self.log('weave is:')
1481
1470
            transport.mkdir('.')
1482
1471
        files = self.factory(transport)
1483
1472
        if self.cleanup is not None:
1484
 
            self.addCleanup(self.cleanup, files)
 
1473
            self.addCleanup(lambda:self.cleanup(files))
1485
1474
        return files
1486
1475
 
1487
1476
    def get_simple_key(self, suffix):
1592
1581
        # All texts should be output.
1593
1582
        self.assertEqual(set(keys), seen)
1594
1583
 
1595
 
    def test_clear_cache(self):
1596
 
        files = self.get_versionedfiles()
1597
 
        files.clear_cache()
1598
 
 
1599
1584
    def test_construct(self):
1600
1585
        """Each parameterised test can be constructed on a transport."""
1601
1586
        files = self.get_versionedfiles()
2449
2434
        else:
2450
2435
            self.assertIdenticalVersionedFile(source, files)
2451
2436
 
2452
 
    def test_insert_record_stream_long_parent_chain_out_of_order(self):
2453
 
        """An out of order stream can either error or work."""
2454
 
        if not self.graph:
2455
 
            raise TestNotApplicable('ancestry info only relevant with graph.')
2456
 
        # Create a reasonably long chain of records based on each other, where
2457
 
        # most will be deltas.
2458
 
        source = self.get_versionedfiles('source')
2459
 
        parents = ()
2460
 
        keys = []
2461
 
        content = [('same same %d\n' % n) for n in range(500)]
2462
 
        for letter in 'abcdefghijklmnopqrstuvwxyz':
2463
 
            key = ('key-' + letter,)
2464
 
            if self.key_length == 2:
2465
 
                key = ('prefix',) + key
2466
 
            content.append('content for ' + letter + '\n')
2467
 
            source.add_lines(key, parents, content)
2468
 
            keys.append(key)
2469
 
            parents = (key,)
2470
 
        # Create a stream of these records, excluding the first record that the
2471
 
        # rest ultimately depend upon, and insert it into a new vf.
2472
 
        streams = []
2473
 
        for key in reversed(keys):
2474
 
            streams.append(source.get_record_stream([key], 'unordered', False))
2475
 
        deltas = chain(*streams[:-1])
2476
 
        files = self.get_versionedfiles()
2477
 
        try:
2478
 
            files.insert_record_stream(deltas)
2479
 
        except RevisionNotPresent:
2480
 
            # Must not have corrupted the file.
2481
 
            files.check()
2482
 
        else:
2483
 
            # Must only report either just the first key as a missing parent,
2484
 
            # no key as missing (for nodelta scenarios).
2485
 
            missing = set(files.get_missing_compression_parent_keys())
2486
 
            missing.discard(keys[0])
2487
 
            self.assertEqual(set(), missing)
2488
 
 
2489
2437
    def get_knit_delta_source(self):
2490
2438
        """Get a source that can produce a stream with knit delta records,
2491
2439
        regardless of this test's scenario.
2559
2507
        # the ordering here is to make a tree so that dumb searches have
2560
2508
        # more changes to muck up.
2561
2509
 
2562
 
        class InstrumentedProgress(progress.ProgressTask):
 
2510
        class InstrumentedProgress(progress.DummyProgress):
2563
2511
 
2564
2512
            def __init__(self):
2565
 
                progress.ProgressTask.__init__(self)
 
2513
 
 
2514
                progress.DummyProgress.__init__(self)
2566
2515
                self.updates = []
2567
2516
 
2568
2517
            def update(self, msg=None, current=None, total=None):