def find_invoking_python(): # roughly... use sys.executable if possible, then major ver variations- # look for python2.5, python2, then just python, for example # NOTE: sys.executable in unreliable if the interpreter is embedded global _invoking_python if _invoking_python is not None and os.path.exists(_invoking_python): return _invoking_python if os.path.exists(sys.executable): test_input = "oh hai" returncode, output = spawn_get_output( [sys.executable, '-c', 'print("%s")' % test_input], collect_fds=(1, 2)) if output and output[0].strip() == test_input: _invoking_python = sys.executable return _invoking_python chunks = list(str(x) for x in sys.version_info[:2]) for potential in (chunks, chunks[:-1], ''): try: command_name = 'python%s' % '.'.join(potential) _invoking_python = find_binary(command_name) return _invoking_python except CommandNotFound: continue raise CommandNotFound('python')
def find_invoking_python(): # roughly... use sys.executable if possible, then major ver variations- # look for python2.5, python2, then just python, for example if os.path.exists(sys.executable): return sys.executable chunks = list(str(x) for x in sys.version_info[:2]) for potential in (chunks, chunks[:-1], ''): try: command_name = 'python%s' % '.'.join(potential) return find_binary(command_name) except CommandNotFound: continue raise CommandNotFound('python')
def test_uri_parse(self): with pytest.raises(base.UriError): svn.svn_syncer.parse_uri("svn+://dar") # external binary doesn't exist with mock.patch('snakeoil.process.find_binary') as find_binary: find_binary.side_effect = CommandNotFound('svn') with pytest.raises(base.SyncError): svn.svn_syncer(str(self.repo_path), "svn+http://foon.com/dar") # fake that the external binary exists with mock.patch('snakeoil.process.find_binary') as find_binary: find_binary.return_value = 'svn' o = svn.svn_syncer(str(self.repo_path), "svn+http://dar") assert o.uri == "http://dar"
def test_uri_parse(self): assert git.git_syncer.parse_uri("git+http://dar") == "http://dar" with pytest.raises(base.UriError): git.git_syncer.parse_uri("git+://dar") # external binary doesn't exist with mock.patch('snakeoil.process.find_binary') as find_binary: find_binary.side_effect = CommandNotFound('git') with pytest.raises(base.SyncError): git.git_syncer(str(self.repo_path), "git+http://foon.com/dar") # fake that the external binary exists with mock.patch('snakeoil.process.find_binary') as find_binary: find_binary.return_value = 'git' for proto in ('http', 'https'): for uri in (f"git+{proto}://repo.git", f"{proto}://repo.git"): o = git.git_syncer(str(self.repo_path), uri) assert o.uri == f"{proto}://repo.git"
def test_uri_parse(self): # external binary doesn't exist with mock.patch('snakeoil.process.find_binary') as find_binary: find_binary.side_effect = CommandNotFound('cvs') with pytest.raises(base.SyncError): cvs.cvs_syncer(str(self.repo_path), "cvs+/bin/sh://foon.com/dar") # fake that the external binary exists with mock.patch('snakeoil.process.find_binary') as find_binary: find_binary.return_value = 'cvs' # nonexistent rsh with mock.patch('pkgcore.sync.base.ExternalSyncer.require_binary' ) as require_binary: require_binary.side_effect = base.MissingBinary('', 'rsh') with pytest.raises(base.SyncError): cvs.cvs_syncer(str(self.repo_path), "cvs+rsh://foon.com/dar") o = cvs.cvs_syncer(str(self.repo_path), "cvs://dar:module") assert o.uri == ":anoncvs:dar" assert o.module == "module" assert o.rsh == None assert o.env["CVSROOT"] == ":anoncvs:dar" o = cvs.cvs_syncer(str(self.repo_path), "cvs+pserver://dar:module") assert o.uri == ":pserver:dar" assert o.module == "module" assert o.rsh == None assert o.env["CVSROOT"] == ":pserver:dar" with mock.patch('pkgcore.sync.base.ExternalSyncer.require_binary' ) as require_binary: require_binary.return_value = '/bin/sh' o = cvs.cvs_syncer(str(self.repo_path), "cvs+/bin/sh://dar:module") assert o.rsh == "/bin/sh" assert o.uri == ":ext:dar" assert o.env["CVSROOT"] == ":ext:dar" assert o.env["CVS_RSH"] == "/bin/sh"
def test_uri_parse_rsync_missing(self, find_binary, spawn, getaddrinfo): find_binary.side_effect = CommandNotFound('rsync') with pytest.raises(base.SyncError): self._syncer_class(self.repo_path, 'rsync://foon.com/dar')
def test_missing_binary(self, find_binary): find_binary.side_effect = CommandNotFound('foo') with pytest.raises(base.MissingBinary): base.ExternalSyncer(self.repo_path, 'http://dar')