~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1038
1038
        return RemoteBranch(bzrdir, repo, _client=client, format=format)
1039
1039
 
1040
1040
 
 
1041
class TestBranchBreakLock(RemoteBranchTestCase):
 
1042
 
 
1043
    def test_break_lock(self):
 
1044
        transport_path = 'quack'
 
1045
        transport = MemoryTransport()
 
1046
        client = FakeClient(transport.base)
 
1047
        client.add_expected_call(
 
1048
            'Branch.get_stacked_on_url', ('quack/',),
 
1049
            'error', ('NotStacked',))
 
1050
        client.add_expected_call(
 
1051
            'Branch.break_lock', ('quack/',),
 
1052
            'success', ('ok',))
 
1053
        transport.mkdir('quack')
 
1054
        transport = transport.clone('quack')
 
1055
        branch = self.make_remote_branch(transport, client)
 
1056
        branch.break_lock()
 
1057
        self.assertFinished(client)
 
1058
 
 
1059
 
1041
1060
class TestBranchGetPhysicalLockStatus(RemoteBranchTestCase):
1042
1061
 
1043
1062
    def test_get_physical_lock_status_yes(self):
1994
2013
        self.assertFinished(client)
1995
2014
 
1996
2015
 
 
2016
class TestBranchRevisionIdToRevno(RemoteBranchTestCase):
 
2017
 
 
2018
    def test_simple(self):
 
2019
        transport = MemoryTransport()
 
2020
        client = FakeClient(transport.base)
 
2021
        client.add_expected_call(
 
2022
            'Branch.get_stacked_on_url', ('quack/',),
 
2023
            'error', ('NotStacked',),)
 
2024
        client.add_expected_call(
 
2025
            'Branch.revision_id_to_revno', ('quack/', 'null:'),
 
2026
            'success', ('ok', '0',),)
 
2027
        client.add_expected_call(
 
2028
            'Branch.revision_id_to_revno', ('quack/', 'unknown'),
 
2029
            'error', ('NoSuchRevision', 'unknown',),)
 
2030
        transport.mkdir('quack')
 
2031
        transport = transport.clone('quack')
 
2032
        branch = self.make_remote_branch(transport, client)
 
2033
        self.assertEquals(0, branch.revision_id_to_revno('null:'))
 
2034
        self.assertRaises(errors.NoSuchRevision,
 
2035
            branch.revision_id_to_revno, 'unknown')
 
2036
        self.assertFinished(client)
 
2037
 
 
2038
    def test_dotted(self):
 
2039
        transport = MemoryTransport()
 
2040
        client = FakeClient(transport.base)
 
2041
        client.add_expected_call(
 
2042
            'Branch.get_stacked_on_url', ('quack/',),
 
2043
            'error', ('NotStacked',),)
 
2044
        client.add_expected_call(
 
2045
            'Branch.revision_id_to_revno', ('quack/', 'null:'),
 
2046
            'success', ('ok', '0',),)
 
2047
        client.add_expected_call(
 
2048
            'Branch.revision_id_to_revno', ('quack/', 'unknown'),
 
2049
            'error', ('NoSuchRevision', 'unknown',),)
 
2050
        transport.mkdir('quack')
 
2051
        transport = transport.clone('quack')
 
2052
        branch = self.make_remote_branch(transport, client)
 
2053
        self.assertEquals((0, ), branch.revision_id_to_dotted_revno('null:'))
 
2054
        self.assertRaises(errors.NoSuchRevision,
 
2055
            branch.revision_id_to_dotted_revno, 'unknown')
 
2056
        self.assertFinished(client)
 
2057
 
 
2058
 
1997
2059
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
1998
2060
 
1999
2061
    def test__get_config(self):
2156
2218
            remote_repo_format.get_format_description())
2157
2219
 
2158
2220
 
 
2221
class TestRepositoryAllRevisionIds(TestRemoteRepository):
 
2222
 
 
2223
    def test_empty(self):
 
2224
        transport_path = 'quack'
 
2225
        repo, client = self.setup_fake_client_and_repository(transport_path)
 
2226
        client.add_success_response_with_body('', 'ok')
 
2227
        self.assertEquals([], repo.all_revision_ids())
 
2228
        self.assertEqual(
 
2229
            [('call_expecting_body', 'Repository.all_revision_ids',
 
2230
             ('quack/',))],
 
2231
            client._calls)
 
2232
 
 
2233
    def test_with_some_content(self):
 
2234
        transport_path = 'quack'
 
2235
        repo, client = self.setup_fake_client_and_repository(transport_path)
 
2236
        client.add_success_response_with_body(
 
2237
            'rev1\nrev2\nanotherrev\n', 'ok')
 
2238
        self.assertEquals(["rev1", "rev2", "anotherrev"],
 
2239
            repo.all_revision_ids())
 
2240
        self.assertEqual(
 
2241
            [('call_expecting_body', 'Repository.all_revision_ids',
 
2242
             ('quack/',))],
 
2243
            client._calls)
 
2244
 
 
2245
 
2159
2246
class TestRepositoryGatherStats(TestRemoteRepository):
2160
2247
 
2161
2248
    def test_revid_none(self):
2214
2301
                         result)
2215
2302
 
2216
2303
 
 
2304
class TestRepositoryBreakLock(TestRemoteRepository):
 
2305
 
 
2306
    def test_break_lock(self):
 
2307
        transport_path = 'quack'
 
2308
        repo, client = self.setup_fake_client_and_repository(transport_path)
 
2309
        client.add_success_response('ok')
 
2310
        repo.break_lock()
 
2311
        self.assertEqual(
 
2312
            [('call', 'Repository.break_lock', ('quack/',))],
 
2313
            client._calls)
 
2314
 
 
2315
 
2217
2316
class TestRepositoryGetGraph(TestRemoteRepository):
2218
2317
 
2219
2318
    def test_get_graph(self):
3730
3829
        # interpretation
3731
3830
        self.make_master_and_checkout('mas~ter', 'checkout')
3732
3831
        self.assertUpdateSucceeds(self.bound_location.replace('%2E', '~', 1))
 
3832
 
 
3833
 
 
3834
class TestWithCustomErrorHandler(RemoteBranchTestCase):
 
3835
 
 
3836
    def test_no_context(self):
 
3837
        class OutOfCoffee(errors.BzrError):
 
3838
            """A dummy exception for testing."""
 
3839
 
 
3840
            def __init__(self, urgency):
 
3841
                self.urgency = urgency
 
3842
        remote.no_context_error_translators.register("OutOfCoffee",
 
3843
            lambda err: OutOfCoffee(err.error_args[0]))
 
3844
        transport = MemoryTransport()
 
3845
        client = FakeClient(transport.base)
 
3846
        client.add_expected_call(
 
3847
            'Branch.get_stacked_on_url', ('quack/',),
 
3848
            'error', ('NotStacked',))
 
3849
        client.add_expected_call(
 
3850
            'Branch.last_revision_info',
 
3851
            ('quack/',),
 
3852
            'error', ('OutOfCoffee', 'low'))
 
3853
        transport.mkdir('quack')
 
3854
        transport = transport.clone('quack')
 
3855
        branch = self.make_remote_branch(transport, client)
 
3856
        self.assertRaises(OutOfCoffee, branch.last_revision_info)
 
3857
        self.assertFinished(client)
 
3858
 
 
3859
    def test_with_context(self):
 
3860
        class OutOfTea(errors.BzrError):
 
3861
            def __init__(self, branch, urgency):
 
3862
                self.branch = branch
 
3863
                self.urgency = urgency
 
3864
        remote.error_translators.register("OutOfTea",
 
3865
            lambda err, find, path: OutOfTea(err.error_args[0],
 
3866
                find("branch")))
 
3867
        transport = MemoryTransport()
 
3868
        client = FakeClient(transport.base)
 
3869
        client.add_expected_call(
 
3870
            'Branch.get_stacked_on_url', ('quack/',),
 
3871
            'error', ('NotStacked',))
 
3872
        client.add_expected_call(
 
3873
            'Branch.last_revision_info',
 
3874
            ('quack/',),
 
3875
            'error', ('OutOfTea', 'low'))
 
3876
        transport.mkdir('quack')
 
3877
        transport = transport.clone('quack')
 
3878
        branch = self.make_remote_branch(transport, client)
 
3879
        self.assertRaises(OutOfTea, branch.last_revision_info)
 
3880
        self.assertFinished(client)