~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

Rework test_script a little bit.


Don't allow someone to request a stdin request to echo.
Echo never reads from stdin, it just echos its arguments.
You use 'cat' if you want to read from stdin.

A few other fixes because the tests were using filenames
that are actually illegal on Windows, rather than just
nonexistant.


Change the exception handling for commands so that
unknown errors don't get silently squashed and then
turn into hard-to-debug errors later.

test_script now passes on Windows.

Show diffs side-by-side

added added

removed removed

Lines of Context:
474
474
        self.assertFinished(client)
475
475
 
476
476
 
 
477
class TestBzrDirOpen(TestRemote):
 
478
 
 
479
    def make_fake_client_and_transport(self, path='quack'):
 
480
        transport = MemoryTransport()
 
481
        transport.mkdir(path)
 
482
        transport = transport.clone(path)
 
483
        client = FakeClient(transport.base)
 
484
        return client, transport
 
485
 
 
486
    def test_absent(self):
 
487
        client, transport = self.make_fake_client_and_transport()
 
488
        client.add_expected_call(
 
489
            'BzrDir.open_2.1', ('quack/',), 'success', ('no',))
 
490
        self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
 
491
                remote.RemoteBzrDirFormat(), _client=client, _force_probe=True)
 
492
        self.assertFinished(client)
 
493
 
 
494
    def test_present_without_workingtree(self):
 
495
        client, transport = self.make_fake_client_and_transport()
 
496
        client.add_expected_call(
 
497
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'no'))
 
498
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
499
            _client=client, _force_probe=True)
 
500
        self.assertIsInstance(bd, RemoteBzrDir)
 
501
        self.assertFalse(bd.has_workingtree())
 
502
        self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
 
503
        self.assertFinished(client)
 
504
 
 
505
    def test_present_with_workingtree(self):
 
506
        client, transport = self.make_fake_client_and_transport()
 
507
        client.add_expected_call(
 
508
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'yes'))
 
509
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
510
            _client=client, _force_probe=True)
 
511
        self.assertIsInstance(bd, RemoteBzrDir)
 
512
        self.assertTrue(bd.has_workingtree())
 
513
        self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
 
514
        self.assertFinished(client)
 
515
 
 
516
    def test_backwards_compat(self):
 
517
        client, transport = self.make_fake_client_and_transport()
 
518
        client.add_expected_call(
 
519
            'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
 
520
        client.add_expected_call(
 
521
            'BzrDir.open', ('quack/',), 'success', ('yes',))
 
522
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
523
            _client=client, _force_probe=True)
 
524
        self.assertIsInstance(bd, RemoteBzrDir)
 
525
        self.assertFinished(client)
 
526
 
 
527
 
477
528
class TestBzrDirOpenBranch(TestRemote):
478
529
 
479
530
    def test_backwards_compat(self):
689
740
        # fallback all the way to the first version.
690
741
        reference_format = self.get_repo_format()
691
742
        network_name = reference_format.network_name()
692
 
        client = FakeClient('bzr://example.com/')
 
743
        server_url = 'bzr://example.com/'
 
744
        self.permit_url(server_url)
 
745
        client = FakeClient(server_url)
693
746
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
694
747
        client.add_unknown_method_response('BzrDir.find_repositoryV2')
695
748
        client.add_success_response('ok', '', 'no', 'no')
701
754
            reference_format.get_format_string(), 'ok')
702
755
        # PackRepository wants to do a stat
703
756
        client.add_success_response('stat', '0', '65535')
704
 
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
 
757
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
705
758
            _client=client)
706
759
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
707
760
            _client=client)
721
774
        # fallback to find_repositoryV2
722
775
        reference_format = self.get_repo_format()
723
776
        network_name = reference_format.network_name()
724
 
        client = FakeClient('bzr://example.com/')
 
777
        server_url = 'bzr://example.com/'
 
778
        self.permit_url(server_url)
 
779
        client = FakeClient(server_url)
725
780
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
726
781
        client.add_success_response('ok', '', 'no', 'no', 'no')
727
782
        # A real repository instance will be created to determine the network
732
787
            reference_format.get_format_string(), 'ok')
733
788
        # PackRepository wants to do a stat
734
789
        client.add_success_response('stat', '0', '65535')
735
 
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
 
790
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
736
791
            _client=client)
737
792
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
738
793
            _client=client)
1999
2054
    def test_allows_new_revisions(self):
2000
2055
        """get_parent_map's results can be updated by commit."""
2001
2056
        smart_server = server.SmartTCPServer_for_testing()
2002
 
        smart_server.setUp()
2003
 
        self.addCleanup(smart_server.tearDown)
 
2057
        self.start_server(smart_server)
2004
2058
        self.make_branch('branch')
2005
2059
        branch = Branch.open(smart_server.get_url() + '/branch')
2006
2060
        tree = branch.create_checkout('tree', lightweight=True)
2859
2913
        stacked_branch.set_stacked_on_url('../base')
2860
2914
        # start a server looking at this
2861
2915
        smart_server = server.SmartTCPServer_for_testing()
2862
 
        smart_server.setUp()
2863
 
        self.addCleanup(smart_server.tearDown)
 
2916
        self.start_server(smart_server)
2864
2917
        remote_bzrdir = BzrDir.open(smart_server.get_url() + '/stacked')
2865
2918
        # can get its branch and repository
2866
2919
        remote_branch = remote_bzrdir.open_branch()
3021
3074
        # Create a smart server that publishes whatever the backing VFS server
3022
3075
        # does.
3023
3076
        self.smart_server = server.SmartTCPServer_for_testing()
3024
 
        self.smart_server.setUp(self.get_server())
3025
 
        self.addCleanup(self.smart_server.tearDown)
 
3077
        self.start_server(self.smart_server, self.get_server())
3026
3078
        # Log all HPSS calls into self.hpss_calls.
3027
3079
        _SmartClient.hooks.install_named_hook(
3028
3080
            'call', self.capture_hpss_call, None)