Example #1
0
    def test_run_match(self, package_name: Optional[str],
                       context: Context) -> None:
        """Test proper initialization based on yielded package_name."""
        prescription_str = """
name: PseudonymUnit
type: pseudonym
should_include:
  times: 1
  adviser_pipeline: true
match:
  package_version:
    name: tensorflow-cpu
    index_url: 'https://pypi.org/simple'
run:
  yield:
    package_version:
      name: intel-tensorflow
      locked_version: null
      index_url: 'https://pypi.org/simple'
"""
        prescription = yaml.safe_load(prescription_str)
        PRESCRIPTION_PSEUDONYM_SCHEMA(prescription)
        PseudonymPrescription.set_prescription(prescription)

        package_version = PackageVersion(
            name="tensorflow-cpu",
            version="==2.4.0",
            index=Source("https://pypi.org/simple"),
            develop=False,
        )

        expected_result = [
            ("intel-tensorflow", "2.4.0", "https://pypi.org/simple"),
            ("intel-tensorflow", "2.4.1", "https://pypi.org/simple"),
        ]

        context.graph.should_receive(
            "get_solved_python_package_versions_all"
        ).with_args(
            package_name="intel-tensorflow",
            package_version=None,
            index_url="https://pypi.org/simple",
            count=None,
            os_name=context.project.runtime_environment.operating_system.name,
            os_version=context.project.runtime_environment.operating_system.
            version,
            python_version=context.project.runtime_environment.python_version,
            distinct=True,
            is_missing=False,
        ).and_return(expected_result).once()

        unit = PseudonymPrescription()
        unit.pre_run()
        with unit.assigned_context(context):
            result = list(unit.run(package_version=package_version))

        assert result == expected_result
Example #2
0
    def test_run_yield_matched_version_not_index_url(self,
                                                     context: Context) -> None:
        """Check yielding correct version when "not" index_url is supplied."""
        prescription_str = """
name: PseudonymUnit
type: pseudonym
should_include:
  times: 1
  adviser_pipeline: true
match:
  package_version:
    name: flask
    version: '>1.0,<=1.1.0'
    index_url:
      not: 'https://pypi.org/simple'
run:
  yield:
    yield_matched_version: true
    package_version:
      name: flask
      index_url: 'https://pypi.org/simple'
"""
        prescription = yaml.safe_load(prescription_str)
        PRESCRIPTION_PSEUDONYM_SCHEMA(prescription)
        PseudonymPrescription.set_prescription(prescription)
        package_version = PackageVersion(
            name="flask",
            version="==1.1.0",
            index=Source("https://thoth-station.ninja/simple"),
            develop=False,
        )

        context.graph.should_receive(
            "get_solved_python_package_versions_all"
        ).with_args(
            package_name=prescription["run"]["yield"].get(
                "package_version", {}).get("name"),
            package_version="1.1.0",
            index_url=prescription["run"]["yield"].get("package_version",
                                                       {}).get("index_url"),
            count=None,
            os_name=context.project.runtime_environment.operating_system.name,
            os_version=context.project.runtime_environment.operating_system.
            version,
            python_version=context.project.runtime_environment.python_version,
            distinct=True,
            is_missing=False,
        ).and_return([("flask", "1.1.0", "https://pypi.org/simple")]).once()

        unit = PseudonymPrescription()
        unit.pre_run()
        with unit.assigned_context(context):
            result = list(unit.run(package_version))

        assert result == [("flask", "1.1.0", "https://pypi.org/simple")]
Example #3
0
    def test_run_stack_info_multi_call(self, context: Context) -> None:
        """Make sure the stack info is added just once on multiple calls."""
        prescription_str = """
name: PseudonymUnit
type: pseudonym
should_include:
  times: 1
  adviser_pipeline: true
match:
  package_version:
    name: flask
    version: '>1.0,<=1.1.0'
    index_url: 'https://pypi.org/simple'
run:
  yield:
    package_version:
      name: flask
      locked_version: ==1.2.0
      index_url: 'https://pypi.org/simple'

  stack_info:
    - type: WARNING
      message: Some stack warning message
      link: https://thoth-station.ninja
"""
        prescription = yaml.safe_load(prescription_str)
        PRESCRIPTION_PSEUDONYM_SCHEMA(prescription)
        PseudonymPrescription.set_prescription(prescription)
        package_version = PackageVersion(
            name="flask",
            version="==1.1.0",
            index=Source("https://pypi.org/simple"),
            develop=False,
        )

        context.graph.should_receive(
            "get_solved_python_package_versions_all"
        ).with_args(
            package_name="flask",
            package_version="1.2.0",
            index_url="https://pypi.org/simple",
            count=None,
            os_name=context.project.runtime_environment.operating_system.name,
            os_version=context.project.runtime_environment.operating_system.
            version,
            python_version=context.project.runtime_environment.python_version,
            distinct=True,
            is_missing=False,
        ).and_return([("flask", "1.2.0", "https://pypi.org/simple")]).twice()

        assert not context.stack_info

        unit = PseudonymPrescription()
        unit.pre_run()
        with unit.assigned_context(context):
            result = list(unit.run(package_version))
            assert result == [("flask", "1.2.0", "https://pypi.org/simple")]
            result = list(unit.run(package_version))
            assert result == [("flask", "1.2.0", "https://pypi.org/simple")]

        assert self.verify_justification_schema(context.stack_info)
        assert len(
            context.stack_info) == 1, "Only one stack info should be included"
        assert context.stack_info == unit.run_prescription["stack_info"]