コード例 #1
0
def test_source_tarball(tmpdir, mocker):
    install_dir = tmpdir.mkdir("install_dir")

    pip = mocker.patch("pip.main")

    def simulate_download(*args):
        filename = "fr2csv-1.0.1.tar.gz"
        shutil.copyfile(
            os.path.join(os.path.dirname(__file__), "samples", filename),
            os.path.join(install_dir.strpath, filename))
        return 0

    pip.side_effect = simulate_download

    # Does not provide a wheel
    source.download_package("fr2csv", "1.0.1", install_dir.strpath)

    assert pip.mock_calls == [
        mock.call([
            "download", "--no-deps", "-d", install_dir.strpath, "fr2csv==1.0.1"
        ])
    ]

    source_code = source.open_downloaded(install_dir.strpath,
                                         ["fr2csv/__init__.py"], "fr2csv")

    lines = source_code["fr2csv/__init__.py"].splitlines()
    assert len(lines) == 101
    assert lines[44] == "class AgnosticReader(object):"
コード例 #2
0
def test_file_not_found(tmpdir, mocker):
    install_dir = tmpdir.mkdir("install_dir")

    pip = mocker.patch("pip.main")

    def simulate_download(*args):
        filename = "fr2csv-1.0.1.tar.gz"
        shutil.copyfile(
            os.path.join(os.path.dirname(__file__), "samples", filename),
            os.path.join(install_dir.strpath, filename))
        return 0

    pip.side_effect = simulate_download

    # Does not provide a wheel
    source.download_package("fr2csv", "1.0.1", install_dir.strpath)

    assert pip.mock_calls == [
        mock.call([
            "download", "--no-deps", "-d", install_dir.strpath, "fr2csv==1.0.1"
        ])
    ]

    with pytest.raises(ValueError):
        source.open_downloaded(install_dir.strpath, ["fr2csv/bla.py"],
                               "fr2csv")
コード例 #3
0
def test_pip_error(tmpdir, mocker):
    install_dir = tmpdir.mkdir("install_dir")

    mocker.patch("pip.main", return_value=1)

    with pytest.raises(ValueError):
        source.download_package("fr2csv", "1.0.1", install_dir.strpath)
コード例 #4
0
def test_download_package(mocker):
    pip = mocker.patch("pip.main", return_value=0)

    source.download_package("fr2csv", "1.0.1", "/tmp/clean/")

    assert pip.mock_calls == [
        mock.call(
            ["download", "--no-deps", "-d", "/tmp/clean/", "fr2csv==1.0.1"])
    ]
コード例 #5
0
 def get_source(self, key, files):
     if key.installed:
         path = source.get_current_path(key.package)
         return source.open_installed(path, files)
     else:
         with Cleaner() as cleaner:
             path = cleaner.mkdir()
             source.download_package(key.package, key.version, path)
             return source.open_downloaded(path, files)
コード例 #6
0
ファイル: test_source.py プロジェクト: wo0dyn/raincoat
def test_pip_error(tmpdir, mocker):
    install_dir = tmpdir.mkdir("install_dir")

    mocker.patch("subprocess.run",
                 return_value=mocker.Mock(returncode=1, stdout=b"Foo"))

    with pytest.raises(ValueError) as exc_info:
        source.download_package("fr2csv", "1.0.1", install_dir.strpath)

    assert str(
        exc_info.value) == "Error while fetching fr2csv==1.0.1 via pip: Foo"
コード例 #7
0
ファイル: test_source.py プロジェクト: wo0dyn/raincoat
def test_download_package(mocker):
    pip = mocker.patch("subprocess.run",
                       return_value=mocker.Mock(returncode=0))

    source.download_package("fr2csv", "1.0.1", "/tmp/clean/")

    assert pip.mock_calls == [
        mocker.call([
            "pip", "download", "--no-deps", "-d", "/tmp/clean/",
            "fr2csv==1.0.1"
        ])
    ]
コード例 #8
0
    def check_package(self, package, version, matches_package):
        """
        For a given package, extract the sources and call compare_contents
        """
        installed, current_version = (
            source.get_current_or_latest_version(package))

        # If we're comparing the same version, let's not
        # waste time and resources.
        if current_version == version:
            return

        for match in matches_package:
            match.other_version = current_version

        # Get the list of files for this package
        # that we'll want to check. We only check those.
        files = set(match.path for match in matches_package)

        # If the package is installed, we'll use its source.
        # Otherwise, we'll download it.
        if not installed:
            current_path = self.cleaner.mkdir()
            source.download_package(package, current_version, current_path)
            current_content = source.open_downloaded(current_path, files,
                                                     package)
        else:
            current_path = source.get_current_path(package)
            current_content = source.open_installed(current_path, files)

        # For the package pointed by the Raincoat comment, we'll always have to
        # download it.
        matched_path = self.cleaner.mkdir()
        source.download_package(package, version, matched_path)
        match_content = source.open_downloaded(matched_path, files, package)

        # fast escape strategy
        if match_content == current_content:
            return

        self.compare_contents(match_content, current_content, matches_package)
コード例 #9
0
def test_source_wheel(tmpdir, mocker):
    install_dir = tmpdir.mkdir("install_dir")

    pip = mocker.patch("pip.main")

    def simulate_download(*args):
        filename = "six-1.10.0-py2.py3-none-any.whl"
        shutil.copyfile(
            os.path.join(os.path.dirname(__file__), "samples", filename),
            os.path.join(install_dir.strpath, filename))
        return 0

    pip.side_effect = simulate_download

    # Provides a wheel
    source.download_package("six", "1.10.0", install_dir.strpath)

    source_code = source.open_downloaded(install_dir.strpath, ["six.py"],
                                         "six")

    lines = source_code["six.py"].splitlines()
    assert len(lines) == 868
    assert lines[0] == ('"""Utilities for writing code '
                        'that runs on Python 2 and 3"""')
コード例 #10
0
ファイル: pypi.py プロジェクト: xordoquy/raincoat
 def download_package(self, package, version, files):
     with Cleaner() as cleaner:
         path = cleaner.mkdir()
         source.download_package(package, version, path)
         return source.open_downloaded(path, files, package)