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"] ==
Beispiel #2
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)
Beispiel #3
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
Beispiel #4
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
Beispiel #5
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)
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
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)
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
Beispiel #10
0
    def __init__(self, provider, root_requirement):
        self._root_version = Version.parse("0.0.0")
        self.provider = provider
        self.package = {
        }  # store candidate {package(class)):{version(class):candidate}}
        # must be list
        self.root_requirements = root_requirement  # list[requirement] must be list

        super(PackageSource, self).__init__()
Beispiel #11
0
def test_no_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)

    set_result = set(p._versions_for(pkg_name, None))
    set_expect = set([version_1, version_2])

    assert set_result == set_expect
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
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
Beispiel #14
0
    def dependencies_for(
        self, package, version
    ):  # type: (Hashable(package(class)), Any(version(version))) -> List[dependency]

        if package == self.root:
            requirements = self.root_requirements
        else:
            candidate = self.package[package][version]
            requirements = self.provider.get_dependencies(candidate)

        # put candidate in requirement to self.package
        # in this way may take a lot of time in provider.find_match()
        # the better way is that chaeck self.package first if what requirement want
        # is already in self.package we would not call provider.find_match
        # if not call provider.find_match

        dependencies = []  # Constraint
        for requirement in requirements:

            if requirement.name not in self.package:
                package = Package(requirement.name)
                self.package[package] = {}

            candidates = self.provider.find_match(requirement)

            for candidate in candidates:
                version = Version.parse(candidate.version)
                package = Package(requirement.name)
                self.package[requirement.name][version] = candidate

            # change requirement to dependency (specifier to constraint)
            # and return dependency
            # requirements
            dependencies.append(self.convert_requirement(requirement))

        return dependencies
Beispiel #15
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
Beispiel #16
0
def test_init():
    p = PackageSource(PipProvider, None)
    v = Version.parse("0.0.0")

    assert p.root_version == v
def test_build_mapping():
    #package_source init*******
    pkg_source = my_pkg_source(PipProvider, None)
    pkg1_name = 'numpy'
    pkg1_version_1 = Version(1, 1, 0)
    pkg1_version_2 = Version(1, 5, 1)

    pkg2_name = 'skilearn'
    pkg2_version_1 = Version(1, 2, 0)
    pkg2_version_2 = Version(2, 0, 1)

    pkg3_name = 'pandas'
    pkg3_version_1 = Version(1, 4, 0)
    pkg3_version_2 = Version(1, 7, 2)

    test_package = {
        Package(pkg1_name): {
            pkg1_version_1: my_EditableCandidate(pkg1_name, '1.1.0'),
            pkg1_version_2: my_EditableCandidate(pkg2_name, '1.5.1')
        },
        Package(pkg2_name): {
            pkg2_version_1: my_EditableCandidate(pkg2_name, '1.2.0'),
            pkg2_version_2: my_EditableCandidate(pkg2_name, '2.0.1')
        },
        Package(pkg3_name): {
            pkg3_version_1: my_EditableCandidate(pkg3_name, '1.4.0'),
            pkg3_version_2: my_EditableCandidate(pkg3_name, '1.7.2')
        }
    }
    pkg_source.init_pkg(test_package)
    # package_source init************

    pkg_list = []
    pkg_list.append(Package(pkg1_name))
    pkg_list.append(Package(pkg2_name))
    pkg_list.append(Package(pkg3_name))

    pkg1_required_ver = Version(1, 1, 0)
    pkg2_required_ver = Version(1, 2, 0)
    pkg3_required_ver = Version(1, 4, 0)

    ver_list = []
    ver_list.append(pkg1_required_ver)
    ver_list.append(pkg2_required_ver)
    ver_list.append(pkg3_required_ver)

    solver = VersionSolver(pkg_source)

    for i in range(len(pkg_list)):
        solver._solution._decisions[pkg_list[i]] = ver_list[i]

    result_mapping = solver._build_mapping()
    print(result_mapping)

    expected_mapping = {
        pkg1_name: my_EditableCandidate(pkg1_name, '1.1.0'),
        pkg2_name: my_EditableCandidate(pkg2_name, '1.2.0'),
        pkg3_name: my_EditableCandidate(pkg3_name, '1.4.0')
    }

    assert expected_mapping == result_mapping