예제 #1
0
    def test_no_should_include(self) -> None:
        """Test including this pipeline unit without 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'
"""
        flexmock(PseudonymPrescription).should_receive(
            "_should_include_base").replace_with(lambda _: False).once()
        prescription = yaml.safe_load(prescription_str)
        PRESCRIPTION_PSEUDONYM_SCHEMA(prescription)
        PseudonymPrescription.set_prescription(prescription)

        builder_context = flexmock()
        assert list(
            PseudonymPrescription.should_include(builder_context)) == []
예제 #2
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
예제 #3
0
    def test_run_log(self, caplog, context: Context, log_level: str) -> None:
        """Check logging messages."""
        prescription_str = f"""
name: PseudonymUnit
type: pseudonym
should_include:
  times: 1
  adviser_pipeline: true
match:
  package_version:
    name: tensorflow
    version: '~=2.4.0'
    index_url: 'https://pypi.org/simple'
run:
  yield:
    package_version:
      name: intel-tensorflow
      locked_version: ==2.4.0
      index_url: 'https://pypi.org/simple'

  log:
    message: Yet some message logged
    type: {log_level}
"""
        prescription = yaml.safe_load(prescription_str)
        PRESCRIPTION_PSEUDONYM_SCHEMA(prescription)
        PseudonymPrescription.set_prescription(prescription)
        package_version = PackageVersion(
            name="tensorflow",
            version="==2.4.1dev0",
            index=Source("https://pypi.org/simple"),
            develop=False,
        )

        context.graph.should_receive(
            "get_solved_python_package_versions_all"
        ).with_args(
            package_name="intel-tensorflow",
            package_version="2.4.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([("intel-tensorflow", "2.4.0", "https://pypi.org/simple")
                      ]).once()

        self.check_run_log(caplog,
                           context,
                           log_level,
                           PseudonymPrescription,
                           package_version=package_version)
예제 #4
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")]
예제 #5
0
    def test_run_stack_info(self, context: Context) -> None:
        """Check assigning stack info."""
        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")]).once()
        self.check_run_stack_info(context,
                                  PseudonymPrescription,
                                  package_version=package_version)
예제 #6
0
    def test_should_include_multi(self) -> None:
        """Test including this pipeline unit multiple times."""
        prescription_str = """
name: PseudonymUnit
type: pseudonym
should_include:
  times: 1
  adviser_pipeline: true
match:
  - package_version:
      name: tensorflow-cpu
  - package_version:
      name: tensorflow-gpu
  - package_version:
      name: intel-tensorflow
  - package_version:
      name: tensorflow
run:
  yield:
    package_version:
      name: intel-tensorflow
      locked_version: null
      index_url: 'https://pypi.org/simple'
"""
        flexmock(PseudonymPrescription).should_receive(
            "_should_include_base").replace_with(lambda _: True).once()
        prescription = yaml.safe_load(prescription_str)
        PRESCRIPTION_PSEUDONYM_SCHEMA(prescription)
        PseudonymPrescription.set_prescription(prescription)

        builder_context = flexmock()
        assert list(PseudonymPrescription.should_include(builder_context)) == [
            {
                "package_name": "tensorflow-cpu",
                "match": {
                    "package_version": {
                        "name": "tensorflow-cpu",
                    }
                },
                "run": {
                    "yield": {
                        "package_version": {
                            "name": "intel-tensorflow",
                            "locked_version": None,
                            "index_url": "https://pypi.org/simple",
                        },
                    },
                },
            },
            {
                "package_name": "tensorflow-gpu",
                "match": {
                    "package_version": {
                        "name": "tensorflow-gpu",
                    }
                },
                "run": {
                    "yield": {
                        "package_version": {
                            "name": "intel-tensorflow",
                            "locked_version": None,
                            "index_url": "https://pypi.org/simple",
                        },
                    },
                },
            },
            {
                "package_name": "intel-tensorflow",
                "match": {
                    "package_version": {
                        "name": "intel-tensorflow",
                    }
                },
                "run": {
                    "yield": {
                        "package_version": {
                            "name": "intel-tensorflow",
                            "locked_version": None,
                            "index_url": "https://pypi.org/simple",
                        },
                    },
                },
            },
            {
                "package_name": "tensorflow",
                "match": {
                    "package_version": {
                        "name": "tensorflow",
                    }
                },
                "run": {
                    "yield": {
                        "package_version": {
                            "name": "intel-tensorflow",
                            "locked_version": None,
                            "index_url": "https://pypi.org/simple",
                        },
                    },
                },
            },
        ]
예제 #7
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"]