Пример #1
0
def test_dependencies_for():
    pkg = Package("mixology")

    v = Version.parse("2.1.0")

    Mock = MockProvider()
    p = PackageSource(Mock, None)
    p.package[pkg] = {}
    p.package[pkg][v] = Candidate("mixology", "2.1.0")

    expected_range1 = Range(Version(1, 1, 0), Version(1, 1, 0), True, True)
    expected_constraint = Constraint(Package('pub'), expected_range1)
    expected_range2 = Range(Version(1, 2, 0), Version(1, 2, 0), True, True)
    expected_constraint2 = Constraint(Package('pub'), expected_range2)
    expected = [expected_constraint, expected_constraint2]

    assert expected == p.dependencies_for(pkg, v)


# def test_package_build():
#     p = PackageSource(MockProvider, None)
#     pkg = Package("mixology")
#     v = Version.parse("2.1.0")

#     p.dependencies_for(pkg, v)

#     # rrr what do package saved
#     assert p.package["pub"]["1.0.0"] ==
Пример #2
0
def test_with_constraint():
    p = my_pkg_source(PipProvider, None)
    pkg_name = "numpy"

    version_1 = Version(1, 2, 0)
    version_2 = Version(1, 5, 1)
    test_package = {
        pkg_name: {
            version_1: "candidate",
            version_2: "candidate2"
        }
    }
    p.init_pkg(test_package)

    constraint_version_1 = Version(1, 2, 0)
    constraint_version_2 = Version(1, 3, 1)
    pkg_range_1 = Range(constraint_version_1, constraint_version_2, True, True)

    constraint_version_3 = Version(2, 2, 0)
    constraint_version_4 = Version(2, 3, 1)
    pkg_range_2 = Range(constraint_version_3, constraint_version_4, True, True)

    constraint_version_5 = Version(3, 2, 0)
    constraint_version_6 = Version(3, 3, 1)
    pkg_range_3 = Range(constraint_version_5, constraint_version_6, True, True)

    pkg_union = Union.of(pkg_range_1, pkg_range_2)

    set_result = set(p._versions_for(pkg_name, pkg_union))

    set_expect = set([version_1])

    assert set_result == set_expect
Пример #3
0
def test_parse_not_equal():
    specifier = "!=1.0.0"
    p = PackageSource(PipProvider, None)
    v = Version.parse("1.0.0")
    expected = [Range(v, None, False, False), Range(None, v, False, False)]

    assert expected == p.parse_specifier(specifier)
Пример #4
0
    def convert_requirement(self, requirement):
        # convert requirement to the type which mixology recongize
        # requirement -> constraint

        if isinstance(requirement, ExplicitRequirement):
            # may occur problem because of unclean specifier
            #for_constraint = re.split(r'(===|==|~=|!=|>=|>|<=|<)', requirement.candidate.version)
            return Constraint(
                Package(requirement.name),
                Range(Version.parse(requirement.candidate.version),
                      Version.parse(requirement.candidate.version), True,
                      True))

        elif isinstance(requirement, SpecifierRequirement):

            specs = requirement._ireq.req.specifier
            ranges = []
            if len(specs) == 0:
                # print("0")
                ranges = Range()
                ranges = [ranges]
            for spec in specs:
                s = spec.__str__()
                temp_ranges = self.parse_specifier(s)
                ranges = ranges + temp_ranges

            # if there is a range only, error may happen (this problem is from "union and range" )
            if len(ranges) == 1:
                # print("ranges == 1")
                constraint = (Constraint(Package(requirement.name), ranges[0]))
            else:
                constraint = (Constraint(Package(requirement.name),
                                         Union(*ranges)))

        elif isinstance(requirement, RequiresPythonRequirement):

            specs = requirement.specifier
            ranges = []
            if len(specs) == 0:
                # print("0")
                ranges = Range()
                ranges = [ranges]
            for spec in specs:
                s = spec.__str__()
                temp_ranges = self.parse_specifier(s)
                ranges = ranges + temp_ranges

            # if there is a range only, error may happen (this problem is from "union and range" )
            if len(ranges) == 1:
                # print("ranges == 1")
                constraint = (Constraint(Package(requirement.name), ranges[0]))
            else:
                constraint = (Constraint(Package(requirement.name),
                                         Union(*ranges)))
        else:
            print("some error happen")

        return constraint
Пример #5
0
def test_parse_equal():
    specifier = "==1.0.0"
    p = PackageSource(PipProvider, None)
    v = Version.parse("1.0.0")
    expected = Range(v, v, True, True)

    assert [expected] == p.parse_specifier(specifier)
Пример #6
0
def test_parse_smaller_include():
    specifier = "<=1.0.0"
    p = PackageSource(PipProvider, None)
    v = Version.parse("1.0.0")
    expected = Range(None, v, False, True)

    assert [expected] == p.parse_specifier(specifier)
Пример #7
0
def test_parse_bigger():
    specifier = ">1.0.0"
    p = PackageSource(PipProvider, None)
    v = Version.parse("1.0.0")
    expected = Range(v, None, False, False)

    assert [expected] == p.parse_specifier(specifier)
Пример #8
0
def test_parse_compatible3():
    specifier = "~=2.2.0"
    p = PackageSource(PipProvider, None)
    v = Version.parse("2.2")
    v2 = Version.parse("2.3")
    expected = Range(v, v2, True, False)

    assert [expected] == p.parse_specifier(specifier)
Пример #9
0
    def _versions_for(self, package, constraint=None):
        if package not in self.package:
            return []

        versions = []
        for version in self.package[package].keys():
            if not constraint or constraint.allows_any(
                    Range(version, version, True, True)):
                versions.append(version)
        return sorted(versions, reverse=True)
Пример #10
0
def test_SpecifierRequirement_multiple_specifiers(mocker):
    pkg_src = PackageSource(PipProvider, None)
    pkg_name = 'numpy'
    expected_range_v1 = Range(Version(1, 0, 0), None, True, False)
    expected_range_v2 = Range(None, Version(1, 5, 0), False, False)
    expected_range_v3 = Range(Version(1, 2, 0), None, False, False)
    expected_range_v4 = Range(None, Version(1, 2, 0), False, False)

    expected_constraint = Constraint(
        Package(pkg_name),
        Union(expected_range_v1, expected_range_v2, expected_range_v3,
              expected_range_v4))

    mocker.patch('src.package_source.PackageSource.parse_specifier',
                 side_effect=[[expected_range_v1], [expected_range_v2],
                              [expected_range_v3, expected_range_v4]])

    test_spififerset = SpecifierSet(">=1.0.0,<1.5.0,!=1.2.0", None)
    test_ireq = my_ireq(my_req(test_spififerset, pkg_name))
    test_requirement = my_SpecifierRequirement(test_ireq, None)

    result = pkg_src.convert_requirement(test_requirement)

    assert result == expected_constraint
Пример #11
0
def test_SpecifierRequirement_single_specifier(mocker):
    pkg_src = PackageSource(PipProvider, None)
    pkg_name = 'numpy'
    expected_range = Range(Version(1, 0, 0), None, True, False)
    expected_constraint = Constraint(Package(pkg_name),
                                     Union.of(expected_range))

    mocker.patch('src.package_source.PackageSource.parse_specifier',
                 return_value=[expected_range])

    test_spififerset = SpecifierSet(">=1.0.0", None)
    test_ireq = my_ireq(my_req(test_spififerset, pkg_name))
    test_requirement = my_SpecifierRequirement(test_ireq, None)

    result = pkg_src.convert_requirement(test_requirement)

    assert result == expected_constraint
Пример #12
0
def test_ExplicitRequirement(mocker):

    pkg_src = PackageSource(PipProvider, None)
    pkg_name = "numpy"
    pkg_version = '1.2.0'

    expected_range = Range(Version(1, 2, 0), Version(1, 2, 0), True, True)
    expected_constraint = Constraint(Package(pkg_name), expected_range)

    mocker.patch('src.package_source.PackageSource.parse_specifier',
                 return_value=[expected_range])

    test_candidate = my_EditableCandidate(pkg_name, pkg_version)
    test_requirement = ExplicitRequirement(test_candidate)
    result = pkg_src.convert_requirement(test_requirement)

    assert expected_constraint == result
Пример #13
0
    def parse_specifier(self, spec):
        # import pdb
        # pdb.set_trace()
        op_and_version = re.split(r'(===|==|~=|!=|>=|>|<=|<|\*)',
                                  spec)  #list of str
        if op_and_version[1] == '===':
            # I surrender. I think it can't be transformed to range
            return [Range()]

        elif op_and_version[1] == '==' and len(op_and_version) != 4:

            min = Version.parse(op_and_version[2])
            max = Version.parse(op_and_version[2])
            return [Range(min, max, True, True)]

        elif op_and_version[1] == '~=' or (op_and_version[1] == '=='
                                           and len(op_and_version) == 4):

            count = len(op_and_version[2].split('.'))

            min = Version.parse(op_and_version[2])
            max = Version.parse(op_and_version[2])

            if count == 2:
                max = max._increment_major()
            elif count == 3:
                max = max._increment_minor()
            # import pdb
            # pdb.set_trace()
            return [Range(min, max, True, False)]

        elif op_and_version[1] == '!=':
            # separate into two range

            version = Version.parse(op_and_version[2])
            return [
                Range(min=version,
                      max=None,
                      include_min=False,
                      include_max=False),
                Range(min=None,
                      max=version,
                      include_min=False,
                      include_max=False)
            ]

        elif op_and_version[1] == '>=':

            version = Version.parse(op_and_version[2])
            return [
                Range(min=version,
                      max=None,
                      include_min=True,
                      include_max=False)
            ]

        elif op_and_version[1] == '>':

            version = Version.parse(op_and_version[2])
            return [
                Range(min=version,
                      max=None,
                      include_min=False,
                      include_max=False)
            ]

        elif op_and_version[1] == '<=':

            version = Version.parse(op_and_version[2])
            return [
                Range(min=None,
                      max=version,
                      include_min=False,
                      include_max=True)
            ]

        elif op_and_version[1] == '<':

            version = Version.parse(op_and_version[2])
            return [
                Range(min=None,
                      max=version,
                      include_min=False,
                      include_max=False)
            ]

        else:
            print("error")

        return 0