示例#1
0
 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)
示例#2
0
 def test_download_httperror(self):
     with pytest.raises(CondaRuntimeError) 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)
示例#3
0
 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)
示例#4
0
 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)
示例#5
0
    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://bitbucket.org/vinay.sajip/pyzzer/downloads/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)
示例#6
0
    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://bitbucket.org/vinay.sajip/pyzzer/downloads/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)
示例#7
0
 def __enter__(self):
     if '://' not in self.url:
         # if we provide the file itself, no tmp dir is created
         self.tmp_dir = None
         return self.url
     else:
         if self.verbose:
             from .console import setup_handlers
             setup_handlers()
         self.tmp_dir = tempfile.mkdtemp()
         dst = join(self.tmp_dir, basename(self.url))
         from conda.core.package_cache import download
         download(self.url, dst)
         return dst
示例#8
0
文件: fetch.py 项目: Korijn/conda
 def __enter__(self):
     if '://' not in self.url:
         # if we provide the file itself, no tmp dir is created
         self.tmp_dir = None
         return self.url
     else:
         if self.verbose:
             from .console import setup_handlers
             setup_handlers()
         self.tmp_dir = tempfile.mkdtemp()
         dst = join(self.tmp_dir, basename(self.url))
         from conda.core.package_cache import download
         download(self.url, dst)
         return dst
示例#9
0
    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)
示例#10
0
 def test_download_connectionerror(self):
     with pytest.raises(CondaRuntimeError) as execinfo:
         url = "http://240.0.0.0/"
         msg = "Connection error:"
         download(url, mktemp())
         assert msg in str(execinfo)
示例#11
0
 def test_download_connectionerror(self):
     with pytest.raises(CondaRuntimeError) as execinfo:
         url = "http://240.0.0.0/"
         msg = "Connection error:"
         download(url, mktemp())
         assert msg in str(execinfo)