def test_pull(self): # Make sure we can pull from paths that can't be encoded dirname1 = self.info['directory'] dirname2 = self.info['directory'] + '2' url1 = urlutils.local_path_to_url(dirname1) url2 = urlutils.local_path_to_url(dirname2) out_bzrdir = self.wt.bzrdir.sprout(url1) out_bzrdir.sprout(url2) self.build_tree_contents( [(osutils.pathjoin(dirname1, "a"), 'different text\n')]) self.wt.commit('mod a') txt = self.run_bzr_decode('pull', working_dir=dirname2) expected = osutils.pathjoin(osutils.getcwd(), dirname1) self.assertEqual(u'Using saved parent location: %s/\n' 'No revisions or tags to pull.\n' % (expected,), txt) self.build_tree_contents( [(osutils.pathjoin(dirname1, 'a'), 'and yet more\n')]) self.wt.commit(u'modifying a by ' + self.info['committer']) # We should be able to pull, even if our encoding is bad self.run_bzr_decode('pull --verbose', encoding='ascii', working_dir=dirname2)
def test_pull(self): # Make sure we can pull from paths that can't be encoded dirname1 = self.info['directory'] dirname2 = self.info['directory'] + '2' url1 = urlutils.local_path_to_url(dirname1) url2 = urlutils.local_path_to_url(dirname2) out_bzrdir = self.wt.bzrdir.sprout(url1) out_bzrdir.sprout(url2) self.build_tree_contents( [(osutils.pathjoin(dirname1, "a"), 'different text\n')]) self.wt.commit('mod a') txt = self.run_bzr_decode('pull', working_dir=dirname2) expected = osutils.pathjoin(osutils.getcwd(), dirname1) self.assertEqual(u'Using saved location: %s/\n' 'No revisions to pull.\n' % (expected,), txt) self.build_tree_contents( [(osutils.pathjoin(dirname1, 'a'), 'and yet more\n')]) self.wt.commit(u'modifying a by ' + self.info['committer']) # We should be able to pull, even if our encoding is bad self.run_bzr_decode('pull --verbose', encoding='ascii', working_dir=dirname2)
def test_get_base_path(self): """cmd_serve will turn the --directory option into a LocalTransport (optionally decorated with 'readonly+'). BzrServerFactory can determine the original --directory from that transport. """ # URLs always include the trailing slash, and get_base_path returns it base_dir = osutils.abspath('/a/b/c') + '/' base_url = urlutils.local_path_to_url(base_dir) + '/' # Define a fake 'protocol' to capture the transport that cmd_serve # passes to serve_bzr. def capture_transport(transport, host, port, inet, timeout): self.bzr_serve_transport = transport cmd = builtins.cmd_serve() # Read-only cmd.run(directory=base_dir, protocol=capture_transport) server_maker = BzrServerFactory() self.assertEqual( 'readonly+%s' % base_url, self.bzr_serve_transport.base) self.assertEqual( base_dir, server_maker.get_base_path(self.bzr_serve_transport)) # Read-write cmd.run(directory=base_dir, protocol=capture_transport, allow_writes=True) server_maker = BzrServerFactory() self.assertEqual(base_url, self.bzr_serve_transport.base) self.assertEqual(base_dir, server_maker.get_base_path(self.bzr_serve_transport)) # Read-only, from a URL cmd.run(directory=base_url, protocol=capture_transport) server_maker = BzrServerFactory() self.assertEqual( 'readonly+%s' % base_url, self.bzr_serve_transport.base) self.assertEqual( base_dir, server_maker.get_base_path(self.bzr_serve_transport))
def test_dot(self): # This test will fail if getcwd is not ascii os.mkdir('mytest') os.chdir('mytest') url = urlutils.local_path_to_url('.') self.assertEndsWith(url, '/mytest')
def test_open_containing(self): branch = self.make_branch_and_tree('.').branch local_base = urlutils.local_path_from_url(branch.base) # Empty opens '.' wt, relpath = WorkingTree.open_containing() self.assertEqual('', relpath) self.assertEqual(wt.basedir + '/', local_base) # '.' opens this dir wt, relpath = WorkingTree.open_containing(u'.') self.assertEqual('', relpath) self.assertEqual(wt.basedir + '/', local_base) # './foo' finds '.' and a relpath of 'foo' wt, relpath = WorkingTree.open_containing('./foo') self.assertEqual('foo', relpath) self.assertEqual(wt.basedir + '/', local_base) # abspath(foo) finds '.' and relpath of 'foo' wt, relpath = WorkingTree.open_containing('./foo') wt, relpath = WorkingTree.open_containing(getcwd() + '/foo') self.assertEqual('foo', relpath) self.assertEqual(wt.basedir + '/', local_base) # can even be a url: finds '.' and relpath of 'foo' wt, relpath = WorkingTree.open_containing('./foo') wt, relpath = WorkingTree.open_containing( urlutils.local_path_to_url(getcwd() + '/foo')) self.assertEqual('foo', relpath) self.assertEqual(wt.basedir + '/', local_base)
def __init__(self, base, userID): """Set the base path where files will be stored.""" self.user = anvillib.acls.UserFS(userID) if not base.startswith('file://'): symbol_versioning.warn( "Instantiating AnvLocalTransport with a filesystem path" " is deprecated as of bzr 0.8." " Please use bzrlib.transport.get_transport()" " or pass in a file:// url.", DeprecationWarning, stacklevel=2 ) base = urlutils.local_path_to_url(base) if base[-1] != '/': base = base + '/' # Special case : windows has no "root", but does have # multiple lettered drives inside it. #240910 if sys.platform == 'win32' and base == 'file:///': base = '' self._local_base = '' super(AnvLocalTransport, self).__init__(base) return super(AnvLocalTransport, self).__init__(base) self._local_base = urlutils.local_path_from_url(base)
def setUp(self): TestCaseInTempDir.setUp(self) self.server = self.VirtualServer( FatLocalTransport(local_path_to_url('.'))) self.server.start_server() self.addCleanup(self.server.stop_server) self.transport = get_transport(self.server.get_url())
def test_unbind_format_6_bzrdir(self): # bind on a format 6 bzrdir should error out,err = self.run_bzr('unbind', retcode=3) self.assertEqual('', out) cwd = urlutils.local_path_to_url(getcwd()) self.assertEqual('bzr: ERROR: To use this feature you must ' 'upgrade your branch at %s/.\n' % cwd, err)
def test_branch_standalone(self): shared_repo = self.make_repository('repo', shared=True) self.example_branch('source') self.run_bzr('branch --standalone source repo/target') b = branch.Branch.open('repo/target') expected_repo_path = os.path.abspath('repo/target/.bzr/repository') self.assertEqual(strip_trailing_slash(b.repository.base), strip_trailing_slash(local_path_to_url(expected_repo_path)))
def test_with_url_and_segment_parameters(self): url = urlutils.local_path_to_url(self.test_dir) + ",branch=foo" t = transport.get_transport_from_url(url) self.assertIsInstance(t, local.LocalTransport) self.assertEqual(t.base.rstrip("/"), url) with open(os.path.join(self.test_dir, "afile"), 'w') as f: f.write("data") self.assertTrue(t.has("afile"))
class FooService(object): """A directory service that maps the name to a FILE url""" # eg 'file:///foo' on Unix, or 'file:///C:/foo' on Windows base = urlutils.local_path_to_url('/foo') def look_up(self, name, url): return self.base + name
def test_with_url_and_segment_parameters(self): url = urlutils.local_path_to_url(self.test_dir)+",branch=foo" t = transport.get_transport_from_url(url) self.assertIsInstance(t, local.LocalTransport) self.assertEquals(t.base.rstrip("/"), url) with open(os.path.join(self.test_dir, "afile"), 'w') as f: f.write("data") self.assertTrue(t.has("afile"))
def test_from_colocated(self): """Branch from a colocated branch into a regular branch.""" tree = self.example_branch('a', format='development-colo') tree.bzrdir.create_branch(name='somecolo') out, err = self.run_bzr('branch %s,branch=somecolo' % local_path_to_url('a')) self.assertEqual('', out) self.assertEqual('Branched 0 revisions.\n', err) self.assertPathExists("somecolo")
def test_bind_format_6_bzrdir(self): # bind on a format 6 bzrdir should error out,err = self.run_bzr('bind ../master', retcode=3) self.assertEqual('', out) # TODO: jam 20060427 Probably something like this really should # print out the actual path, rather than the URL cwd = urlutils.local_path_to_url(getcwd()) self.assertEqual('bzr: ERROR: To use this feature you must ' 'upgrade your branch at %s/.\n' % cwd, err)
def test_commandline(self): tbird = mail_client.Thunderbird(None) commandline = tbird._get_compose_commandline(None, None, 'file%') self.assertEqual(['-compose', "attachment='%s'" % urlutils.local_path_to_url('file%')], commandline) commandline = tbird._get_compose_commandline('*****@*****.**', 'Hi there!', None) self.assertEqual(['-compose', "subject='Hi there!'," "to='*****@*****.**'"], commandline)
def test_pull_dash_d(self): self.example_branch('a') self.make_branch_and_tree('b') self.make_branch_and_tree('c') # pull into that branch self.run_bzr('pull -d b a') # pull into a branch specified by a url c_url = urlutils.local_path_to_url('c') self.assertStartsWith(c_url, 'file://') self.run_bzr(['pull', '-d', c_url, 'a'])
def test_commandline_is_8bit(self): # test for bug #139318 tbird = mail_client.Thunderbird(None) cmdline = tbird._get_compose_commandline(u'*****@*****.**', u'Hi there!', u'file%') self.assertEqual(['-compose', ("attachment='%s'," % urlutils.local_path_to_url('file%')) + "subject='Hi there!',to='*****@*****.**'", ], cmdline) for item in cmdline: self.assertFalse(isinstance(item, unicode), 'Command-line item %r is unicode!' % item)
def test_commandline(self): tbird = mail_client.Thunderbird(None) commandline = tbird._get_compose_commandline(None, None, 'file%') self.assertEqual([ '-compose', "attachment='%s'" % urlutils.local_path_to_url('file%') ], commandline) commandline = tbird._get_compose_commandline('*****@*****.**', 'Hi there!', None) self.assertEqual( ['-compose', "subject='Hi there!'," "to='*****@*****.**'"], commandline)
def test_root(self): dirname = self.info['directory'] url = urlutils.local_path_to_url(dirname) self.run_bzr_decode('root') self.wt.bzrdir.sprout(url) txt = self.run_bzr_decode('root', working_dir=dirname) self.assertTrue(txt.endswith(dirname+'\n')) txt = self.run_bzr_decode('root', encoding='ascii', fail=True, working_dir=dirname)
def test_root(self): dirname = self.info['directory'] url = urlutils.local_path_to_url(dirname) self.run_bzr_decode('root') self.wt.bzrdir.sprout(url) txt = self.run_bzr_decode('root', working_dir=dirname) self.failUnless(txt.endswith(dirname+'\n')) txt = self.run_bzr_decode('root', encoding='ascii', fail=True, working_dir=dirname)
def _get_compose_commandline(self, to, subject, attach_path): """See ExternalMailClient._get_compose_commandline""" message_options = {} if to is not None: message_options['to'] = self._encode_safe(to) if subject is not None: message_options['subject'] = self._encode_safe(subject) if attach_path is not None: message_options['attachment'] = urlutils.local_path_to_url( attach_path) options_list = ["%s='%s'" % (k, v) for k, v in sorted(message_options.iteritems())] return ['-compose', ','.join(options_list)]
def test_commandline_is_8bit(self): # test for bug #139318 tbird = mail_client.Thunderbird(None) cmdline = tbird._get_compose_commandline(u'*****@*****.**', u'Hi there!', u'file%') self.assertEqual([ '-compose', ("attachment='%s'," % urlutils.local_path_to_url('file%')) + "subject='Hi there!',to='*****@*****.**'", ], cmdline) for item in cmdline: self.assertFalse(isinstance(item, unicode), 'Command-line item %r is unicode!' % item)
def test_uncommittedchanges_display_url(self): """The display_url of UncommittedChanges errors should be serialised""" self.requireFeature(compatibility.UnicodeFilenameFeature) path = u"\u1234" class FakeTree(object): def __init__(self, url): self.user_url = url attrs = self.check_exception_instance( errors.UncommittedChanges( FakeTree(urlutils.local_path_to_url(path)))) self.assertIsSameRealPath( path, urlutils.local_path_from_url(attrs["display_url"]))
def _get_compose_commandline(self, to, subject, attach_path): """See ExternalMailClient._get_compose_commandline""" message_options = {} if to is not None: message_options['to'] = self._encode_safe(to) if subject is not None: message_options['subject'] = self._encode_safe(subject) if attach_path is not None: message_options['attachment'] = urlutils.local_path_to_url( attach_path) options_list = [ "%s='%s'" % (k, v) for k, v in sorted(message_options.iteritems()) ] return ['-compose', ','.join(options_list)]
def run(self, user_id, port=None, inet=False, directory=None, codehosting_endpoint_url=None, protocol=None): allow_writes = True from bzrlib import transport if directory is None: directory = os.getcwd() if protocol is None: protocol = transport.transport_server_registry.get() host, port = self.get_host_and_port(port) url = urlutils.local_path_to_url(directory) if not allow_writes: url = 'readonly+' + url t = AnvLocalTransport(url, user_id) protocol(t, host, port, inet)
def _initialize_bazaar_server(self, directory, server_port): from bzrlib import urlutils from bzrlib.transport import get_transport from bzrlib.transport.chroot import ChrootServer url = urlutils.local_path_to_url(directory) url = 'readonly+' + url print url chroot_server = ChrootServer(get_transport(url)) chroot_server.setUp() t = get_transport(chroot_server.get_url()) print chroot_server.get_url() self._bazaar_server = SmartTCPServer( t, 'localhost', server_port) self._bazaar_server.start_background_thread()
def test_branch_keeps_signatures(self): wt = self.make_branch_and_tree('source') wt.commit('A', allow_pointless=True, rev_id='A') repo = wt.branch.repository repo.lock_write() repo.start_write_group() repo.sign_revision('A', gpg.LoopbackGPGStrategy(None)) repo.commit_write_group() repo.unlock() #FIXME: clone should work to urls, # wt.clone should work to disks. self.build_tree(['target/']) d2 = repo.bzrdir.clone(urlutils.local_path_to_url('target')) self.assertEqual(repo.get_signature_text('A'), d2.open_repository().get_signature_text('A'))
def make_app(root, prefix, path_var='REQUEST_URI', readonly=True): """Convenience function to construct a WSGI bzr smart server. :param root: a local path that requests will be relative to. :param prefix: See RelpathSetter. :param path_var: See RelpathSetter. """ local_url = local_path_to_url(root) if readonly: base_transport = get_transport('readonly+' + local_url) else: base_transport = get_transport(local_url) app = SmartWSGIApp(base_transport, prefix) app = RelpathSetter(app, '', path_var) return app
def test_clone_preserves_signatures(self): wt = self.make_branch_and_tree('source') wt.commit('A', allow_pointless=True, rev_id='A') repo = wt.branch.repository repo.lock_write() repo.start_write_group() repo.sign_revision('A', gpg.LoopbackGPGStrategy(None)) repo.commit_write_group() repo.unlock() #FIXME: clone should work to urls, # wt.clone should work to disks. self.build_tree(['target/']) d2 = repo.bzrdir.clone(urlutils.local_path_to_url('target')) self.assertEqual(repo.get_signature_text('A'), d2.open_repository().get_signature_text('A'))
def test_non_ascii(self): if win32utils.winver == 'Windows 98': raise TestSkipped('Windows 98 cannot handle unicode filenames') try: os.mkdir(u'dod\xe9') except UnicodeError: raise TestSkipped('cannot create unicode directory') os.chdir(u'dod\xe9') # On Mac OSX this directory is actually: # u'/dode\u0301' => '/dode\xcc\x81 # but we should normalize it back to # u'/dod\xe9' => '/dod\xc3\xa9' url = urlutils.local_path_to_url('.') self.assertEndsWith(url, '/dod%C3%A9')
def __init__(self): """Initialize the server. We register ourselves with the scheme lp-testing=${id(self)}:/// using an in-memory XML-RPC client and backed onto a LocalTransport. """ frontend = InMemoryFrontend() branchfs = frontend.getCodehostingEndpoint() branch = frontend.getLaunchpadObjectFactory().makeAnyBranch() self._branch_path = branch.unique_name # XXX: JonathanLange bug=276972 2008-10-07: This should back on to a # MemoryTransport, but a bug in Bazaar's implementation makes it # unreliable for tests that involve particular errors. LaunchpadInternalServer.__init__( self, 'lp-testing-%s:///' % id(self), DeferredBlockingProxy(branchfs), LocalTransport(local_path_to_url('.'))) self._chroot_servers = []
def abspath(self, relpath): """Return the full url to the given relative URL.""" # TODO: url escape the result. RBC 20060523. # jam 20060426 Using normpath on the real path, because that ensures # proper handling of stuff like relpath = self._anvilise_path(relpath) path = osutils.normpath(osutils.pathjoin( self._local_base, urlutils.unescape(relpath))) # on windows, our _local_base may or may not have a drive specified # (ie, it may be "/" or "c:/foo"). # If 'relpath' is '/' we *always* get back an abspath without # the drive letter - but if our transport already has a drive letter, # we want our abspaths to have a drive letter too - so handle that # here. if (sys.platform == "win32" and self._local_base[1:2] == ":" and path == '/'): path = self._local_base[:3] return urlutils.local_path_to_url(path)
def make_app(root, prefix, path_var='REQUEST_URI', readonly=True, load_plugins=True, enable_logging=True): """Convenience function to construct a WSGI bzr smart server. :param root: a local path that requests will be relative to. :param prefix: See RelpathSetter. :param path_var: See RelpathSetter. """ local_url = local_path_to_url(root) if readonly: base_transport = get_transport('readonly+' + local_url) else: base_transport = get_transport(local_url) if load_plugins: from bzrlib.plugin import load_plugins load_plugins() if enable_logging: import bzrlib.trace bzrlib.trace.enable_default_logging() app = SmartWSGIApp(base_transport, prefix) app = RelpathSetter(app, '', path_var) return app
def test_get_base_path(self): """cmd_serve will turn the --directory option into a LocalTransport (optionally decorated with 'readonly+'). BzrServerFactory can determine the original --directory from that transport. """ # URLs always include the trailing slash, and get_base_path returns it base_dir = osutils.abspath('/a/b/c') + '/' base_url = urlutils.local_path_to_url(base_dir) + '/' # Define a fake 'protocol' to capture the transport that cmd_serve # passes to serve_bzr. def capture_transport(transport, host, port, inet, timeout): self.bzr_serve_transport = transport cmd = builtins.cmd_serve() # Read-only cmd.run(directory=base_dir, protocol=capture_transport) server_maker = BzrServerFactory() self.assertEqual('readonly+%s' % base_url, self.bzr_serve_transport.base) self.assertEqual(base_dir, server_maker.get_base_path(self.bzr_serve_transport)) # Read-write cmd.run(directory=base_dir, protocol=capture_transport, allow_writes=True) server_maker = BzrServerFactory() self.assertEqual(base_url, self.bzr_serve_transport.base) self.assertEqual(base_dir, server_maker.get_base_path(self.bzr_serve_transport)) # Read-only, from a URL cmd.run(directory=base_url, protocol=capture_transport) server_maker = BzrServerFactory() self.assertEqual('readonly+%s' % base_url, self.bzr_serve_transport.base) self.assertEqual(base_dir, server_maker.get_base_path(self.bzr_serve_transport))
def test_get_transport_from_relpath(self): here = osutils.abspath('.') t = transport.get_transport('.') self.assertIsInstance(t, local.LocalTransport) self.assertEquals(t.base, urlutils.local_path_to_url('.') + '/')
def test_get_transport_from_local_url(self): here = osutils.abspath('.') here_url = urlutils.local_path_to_url(here) + '/' t = transport.get_transport(here_url) self.assertIsInstance(t, local.LocalTransport) self.assertEquals(t.base, here_url)
def test_get_transport_from_local_url(self): here = osutils.abspath('.') here_url = urlutils.local_path_to_url(here) + '/' t = get_transport(here_url) self.assertIsInstance(t, LocalTransport) self.assertEquals(t.base, here_url)
def setUp(self): TestCaseInTempDir.setUp(self) self.transport = FatLocalTransport(urlutils.local_path_to_url('.'))
def setUp(self): TestCaseInTempDir.setUp(self) SFTPTestMixin.setUp(self) transport = AsyncTransport( FatLocalTransport(urlutils.local_path_to_url('.'))) self.sftp_server = TransportSFTPServer(transport)
def test_with_url(self): url = urlutils.local_path_to_url(self.test_dir) t = transport.get_transport_from_url(url) self.assertIsInstance(t, local.LocalTransport) self.assertEquals(t.base.rstrip("/"), url)
def _get_transport_for_dir(directory): url = urlutils.local_path_to_url(directory) return FatLocalTransport(url)
def test_get_transport_from_abspath(self): here = osutils.abspath('.') t = transport.get_transport(here) self.assertIsInstance(t, local.LocalTransport) self.assertEqual(t.base, urlutils.local_path_to_url(here) + '/')
def test_get_transport_from_relpath(self): here = osutils.abspath('.') t = get_transport('.') self.assertIsInstance(t, LocalTransport) self.assertEquals(t.base, urlutils.local_path_to_url('.') + '/')
def get_url(self): """See Transport.Server.get_url.""" return "gio+" + urlutils.local_path_to_url('')
def assertParent(self, expected_parent, branch): """Verify that the parent is not None and is set correctly.""" actual_parent = branch.get_parent() self.assertIsSameRealPath(urlutils.local_path_to_url(expected_parent), branch.get_parent())