예제 #1
0
def test_available_packages_get_by_name():
    simplejson = PackageReleases(name='simplejson', versions=('1.0', '1.1'))
    six = PackageReleases(name='six', versions=('1.2', '2.4'))

    avs = AvailablePackages(
        packages=[
            simplejson,
            six,
        ],
    )

    # exact name matches
    assert avs.get_by_name('simplejson') is simplejson
    assert avs.get_by_name('six') is six

    # nothing else matches
    assert avs.get_by_name('simplejson==1.0') is None
    assert avs.get_by_name('simple') is None
예제 #2
0
def test_package_releases_as_display_name_single():
    pkg1 = PackageReleases(name='simplejson', versions=('1.0',))
    pkg2 = PackageReleases(name='simplejson', versions=('1.0', '1.1'))

    assert pkg1.as_display_name_single() == 'simplejson-1.0'

    with pytest.raises(ValueError):
        pkg2.as_display_name_single()
예제 #3
0
def test_pip_search_parser():
    pkg_rels_expected = PackageReleases(
        name='six',
        versions=('1.10.0', '1.11.0'),
    )

    parser = PipSearchParser(content=SEARCH_EXAMPLE_SIX)
    pkg_rels = parser.parse(package_name='six')

    assert pkg_rels_expected == pkg_rels
예제 #4
0
def test_package_releases_equality():
    pkg1 = PackageReleases(name='simplejson', versions=('1.0', '1.1'))

    # different name
    pkg2 = PackageReleases(name='difficultyaml', versions=('1.0', '1.1'))

    # different version
    pkg3 = PackageReleases(name='simplejson', versions=('1.0', '1.2'))

    assert not pkg1 == None  # noqa
    assert pkg1 == pkg1
    assert not pkg1 != pkg1

    assert pkg1 != pkg2
    assert not pkg1 == pkg2

    assert pkg1 != pkg3
    assert not pkg1 == pkg3

    # Test repr
    assert repr(pkg1) == (
        "<PackageReleases name='simplejson', versions=['1.0', '1.1']>"
    )
예제 #5
0
def test_available_packages_equality():
    avs1 = AvailablePackages(
        packages=[
            PackageReleases(name='simplejson', versions=('1.0', '1.1')),
            PackageReleases(name='six', versions=('1.2', '2.3')),
        ],
    )

    # missing one package
    avs2 = AvailablePackages(
        packages=[
            PackageReleases(name='six', versions=('1.2', '2.3')),
        ],
    )

    # name differs
    avs3 = AvailablePackages(
        packages=[
            PackageReleases(name='complicatedyaml', versions=('1.0', '1.1')),
            PackageReleases(name='six', versions=('1.2', '2.3')),
        ],
    )

    # versions differ
    avs4 = AvailablePackages(
        packages=[
            PackageReleases(name='simplejson', versions=('1.0', '1.1')),
            PackageReleases(name='six', versions=('1.2', '2.4')),
        ],
    )

    assert not avs1 == None  # noqa
    assert avs1 == avs1
    assert not avs1 != avs1

    assert avs1 != avs2
    assert not avs1 == avs2

    assert avs1 != avs3
    assert not avs1 == avs3

    assert avs1 != avs4
    assert not avs1 == avs4

    # Test repr
    assert repr(avs1) == (
        "<AvailablePackages num_packages=2>"
    )
예제 #6
0
    def parse(self, package_name):
        versions = []
        cur_pkgname = None

        for line in self.content.splitlines():
            # the line is all whitespace, skip it

            if not line.strip():
                continue

            match_starting = self.rx_starting_line.match(line)
            match_continuation = self.rx_continuation_line.match(line)
            match_version = self.rx_version_line.match(line)

            # we don't recognize this line
            if not any((match_starting, match_continuation, match_version)):
                _logger.warn('Unable to parse pip search line: %s', line)
                continue

            if match_starting:
                cur_pkgname = match_starting.groupdict()['name']

            # we've entered a new package block
            if cur_pkgname != package_name:
                continue

            if match_starting:
                version = match_starting.groupdict()['version']
                versions = [version]

            if match_version:
                # keyword = match_version.groupdict()['keyword']
                version = match_version.groupdict()['version']
                versions.append(version)

        pkg_rels = PackageReleases(
            name=package_name,
            versions=versions,
        )
        return pkg_rels
예제 #7
0
def test_can_be_upgraded_analyzer():
    pkgs_available = AvailablePackages(
        packages=[
            PackageReleases(name='abc', versions=('8.5', '8.6')),
            PackageReleases(name='click', versions=('1.8', '1.9')),
            PackageReleases(name='coverage', versions=('3.5', '3.6', '4.0', '4.1')),
            PackageReleases(name='ply', versions=('0.5', '0.5.1')),
            PackageReleases(name='six', versions=('0.8', '0.9')),
        ],
    )

    pkgs_reqs = RequirementsTxt(
        packages=[
            PackageRequirement(name='abc', operator='<=', version='9.0'),
            PackageRequirement(name='click', operator=None, version=None),
            PackageRequirement(name='coverage', operator='<', version='4.0'),  # -> 4.1
            PackageRequirement(name='ply', operator='==', version='0.5'),  # -> 0.5.1
            PackageRequirement(name='six', operator='==', version='0.9'),
        ],
    )

    pkgs_installed = InstalledPackages(
        packages=[
            InstalledPackage(name='abc', version='8.5'),  # -> 8.6
            InstalledPackage(name='click', version='1.8'),  # -> 1.9
            InstalledPackage(name='coverage', version='3.5'),  # -> 3.6
        ],
    )

    analyzer = CanBeUpgradedAnalyzer(
        requirements_txt=pkgs_reqs,
        installed_packages=pkgs_installed,
        available_packages=pkgs_available,
    )
    advice_list = analyzer.analyze()

    expected_advice_list = AdviceList(
        advice_list=[
            Advice(
                analyzer=analyzer,
                severity='info',
                message=(
                    "Installed dependency 'abc-8.5' "
                    "can be updated to 'abc-8.6'"
                ),
            ),
            Advice(
                analyzer=analyzer,
                severity='info',
                message=(
                    "Installed dependency 'click-1.8' "
                    "can be updated to 'click-1.9'"
                ),
            ),
            Advice(
                analyzer=analyzer,
                severity='info',
                message=(
                    "Required dependency 'coverage<4.0' "
                    "can be upgraded to 'coverage-4.1'"
                ),
            ),
            Advice(
                analyzer=analyzer,
                severity='info',
                message=(
                    "Installed dependency 'coverage-3.5' "
                    "can be updated to 'coverage-3.6'"
                ),
            ),
            Advice(
                analyzer=analyzer,
                severity='info',
                message=(
                    "Required dependency 'ply==0.5' "
                    "can be upgraded to 'ply-0.5.1'"
                ),
            ),
        ],
    )

    assert expected_advice_list == advice_list