def test_download_httperror(self): with pytest.raises(CondaHTTPError) as execinfo: url = DEFAULT_CHANNEL_ALIAS msg = "HTTPError:" responses.add(responses.GET, url, body='{"error": "not found"}', status=404, content_type='application/json') download(url, mktemp()) assert msg in str(execinfo)
def test_download_connectionerror(self): with env_var('CONDA_REMOTE_CONNECT_TIMEOUT_SECS', 1, conda_tests_ctxt_mgmt_def_pol): with env_var('CONDA_REMOTE_READ_TIMEOUT_SECS', 1, conda_tests_ctxt_mgmt_def_pol): with env_var('CONDA_REMOTE_MAX_RETRIES', 1, conda_tests_ctxt_mgmt_def_pol): with pytest.raises(CondaHTTPError) as execinfo: url = "http://240.0.0.0/" msg = "Connection error:" download(url, mktemp()) assert msg in str(execinfo)
def test_download_connectionerror(self): with env_var('CONDA_REMOTE_CONNECT_TIMEOUT_SECS', 1, reset_context): with env_var('CONDA_REMOTE_READ_TIMEOUT_SECS', 1, reset_context): with env_var('CONDA_REMOTE_MAX_RETRIES', 1, reset_context): with pytest.raises(CondaHTTPError) as execinfo: url = "http://240.0.0.0/" msg = "Connection error:" download(url, mktemp()) assert msg in str(execinfo)
def test_download_connectionerror(self): with env_var('CONDA_REMOTE_CONNECT_TIMEOUT_SECS', 1, stack_callback=conda_tests_ctxt_mgmt_def_pol): with env_var('CONDA_REMOTE_READ_TIMEOUT_SECS', 1, stack_callback=conda_tests_ctxt_mgmt_def_pol): with env_var('CONDA_REMOTE_MAX_RETRIES', 1, stack_callback=conda_tests_ctxt_mgmt_def_pol): with pytest.raises(CondaHTTPError) as execinfo: url = "http://240.0.0.0/" msg = "Connection error:" download(url, mktemp()) assert msg in str(execinfo)
def test_windows_entry_point(self): """ This emulates pip-created entry point executables on windows. For more info, refer to conda/install.py::replace_entry_point_shebang """ tmp_dir = tempfile.mkdtemp() cwd = getcwd() chdir(tmp_dir) original_prefix = "C:\\BogusPrefix\\python.exe" try: url = 'https://s3.amazonaws.com/conda-dev/pyzzerw.pyz' download(url, 'pyzzerw.pyz') url = 'https://files.pythonhosted.org/packages/source/c/conda/conda-4.1.6.tar.gz' download(url, 'conda-4.1.6.tar.gz') subprocess.check_call( [ sys.executable, 'pyzzerw.pyz', # output file '-o', 'conda.exe', # entry point '-m', 'conda.cli.main:main', # initial shebang '-s', '#! ' + original_prefix, # launcher executable to use (32-bit text should be compatible) '-l', 't32', # source archive to turn into executable 'conda-4.1.6.tar.gz', ], cwd=tmp_dir) # this is the actual test: change the embedded prefix and make sure that the exe runs. data = open('conda.exe', 'rb').read() fixed_data = binary_replace(data, original_prefix, sys.executable) with open("conda.fixed.exe", 'wb') as f: f.write(fixed_data) # without a valid shebang in the exe, this should fail with pytest.raises(subprocess.CalledProcessError): subprocess.check_call(['conda.exe', '-h']) process = subprocess.Popen(['conda.fixed.exe', '-h'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, error = process.communicate() output = output.decode('utf-8') error = error.decode('utf-8') assert ("conda is a tool for managing and deploying applications, " "environments and packages.") in output except: raise finally: chdir(cwd)
def test_windows_entry_point(self): """ This emulates pip-created entry point executables on windows. For more info, refer to conda/install.py::replace_entry_point_shebang """ tmp_dir = tempfile.mkdtemp() cwd = getcwd() chdir(tmp_dir) original_prefix = "C:\\BogusPrefix\\python.exe" try: url = 'https://s3.amazonaws.com/conda-dev/pyzzerw.pyz' download(url, 'pyzzerw.pyz') url = 'https://files.pythonhosted.org/packages/source/c/conda/conda-4.1.6.tar.gz' download(url, 'conda-4.1.6.tar.gz') subprocess.check_call([sys.executable, 'pyzzerw.pyz', # output file '-o', 'conda.exe', # entry point '-m', 'conda.cli.main:main', # initial shebang '-s', '#! ' + original_prefix, # launcher executable to use (32-bit text should be compatible) '-l', 't32', # source archive to turn into executable 'conda-4.1.6.tar.gz', ], cwd=tmp_dir) # this is the actual test: change the embedded prefix and make sure that the exe runs. data = open('conda.exe', 'rb').read() fixed_data = binary_replace(data, original_prefix, sys.executable) with open("conda.fixed.exe", 'wb') as f: f.write(fixed_data) # without a valid shebang in the exe, this should fail with pytest.raises(subprocess.CalledProcessError): subprocess.check_call(['conda.exe', '-h']) process = subprocess.Popen(['conda.fixed.exe', '-h'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, error = process.communicate() output = output.decode('utf-8') error = error.decode('utf-8') assert ("conda is a tool for managing and deploying applications, " "environments and packages.") in output except: raise finally: chdir(cwd)