Ejemplo n.º 1
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")
Ejemplo n.º 2
0
def test_unrecognized_format(tmpdir):
    install_dir = tmpdir.mkdir("install_dir")

    install_dir.join("bla.txt").write("yay")

    with pytest.raises(NotImplementedError):
        source.open_downloaded(install_dir.strpath, [], "bla")
Ejemplo n.º 3
0
def test_open_downloaded_tarball(mocker):
    mocker.patch("os.listdir", return_value=["a.tar.gz"])
    tb = mocker.patch("raincoat.source.open_in_tarball")
    whl = mocker.patch("raincoat.source.open_in_wheel")

    source.open_downloaded("b", ["yay.py"])

    assert whl.mock_calls == []
    assert tb.mock_calls == [mock.call("b/a.tar.gz", ["yay.py"])]
Ejemplo n.º 4
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):"
Ejemplo n.º 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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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"""')
Ejemplo n.º 8
0
 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)