Exemple #1
0
 def test_should_include(self,
                         builder_context: PipelineBuilderContext) -> None:
     """Test registering this unit if supplied software environment is fully specified."""
     builder_context.project.runtime_environment.should_receive(
         "is_fully_specified").with_args().and_return(True).twice()
     assert list(
         SolvedSoftwareEnvironmentBoot.should_include(builder_context)) == [
             {}
         ]
     builder_context.add_unit(SolvedSoftwareEnvironmentBoot())
     assert list(
         SolvedSoftwareEnvironmentBoot.should_include(
             builder_context)) == []
Exemple #2
0
 def test_no_include(
     self,
     builder_context: PipelineBuilderContext,
     recommendation_type: RecommendationType,
     decision_type: DecisionType,
     cuda_version: str,
 ) -> None:
     """Test not including this pipeline unit."""
     builder_context.decision_type = decision_type
     builder_context.recommendation_type = recommendation_type
     builder_context.project.runtime_environment.cuda_version = cuda_version
     assert builder_context.is_adviser_pipeline() or builder_context.is_dependency_monkey_pipeline()
     assert self.UNIT_TESTED.should_include(builder_context) is None
    def test_include(
        self,
        builder_context: PipelineBuilderContext,
        recommendation_type: RecommendationType,
    ) -> None:
        """Test including this pipeline unit."""
        builder_context.recommendation_type = recommendation_type
        builder_context.project = Project.from_strings(
            self._CASE_DISALLOWED_PIPFILE)

        assert builder_context.is_adviser_pipeline()
        assert list(
            CutPreReleasesSieve.should_include(builder_context)) == [{}]
 def test_is_included(self,
                      builder_context: PipelineBuilderContext) -> None:
     """Test check if the given pipeline unit is included."""
     assert builder_context.is_included(units.boots.Boot1)
     assert not builder_context.is_included(units.boots.Boot2)
     assert builder_context.is_included(units.sieves.Sieve1)
     assert not builder_context.is_included(units.sieves.Sieve2)
     assert builder_context.is_included(units.steps.Step1)
     assert not builder_context.is_included(units.steps.Step2)
     assert builder_context.is_included(units.strides.Stride1)
     assert not builder_context.is_included(units.strides.Stride2)
     assert builder_context.is_included(units.wraps.Wrap1)
     assert not builder_context.is_included(units.wraps.Wrap2)
Exemple #5
0
    def test_include(
        self,
        builder_context: PipelineBuilderContext,
        recommendation_type: RecommendationType,
        decision_type: DecisionType,
    ) -> None:
        """Test including this pipeline unit."""
        builder_context.decision_type = decision_type
        builder_context.recommendation_type = recommendation_type
        builder_context.project.runtime_environment.python_version = "3.6"

        assert builder_context.is_adviser_pipeline() or builder_context.is_dependency_monkey_pipeline()
        assert Py36SetuptoolsSieve.should_include(builder_context) == {}
Exemple #6
0
 def test_no_include(
     self,
     builder_context: PipelineBuilderContext,
     recommendation_type,
     decision_type: DecisionType,
     cpu_family: Optional[int],
     cpu_model: Optional[int],
 ) -> None:
     """Test not including this pipeline unit step."""
     builder_context.decision_type = decision_type
     builder_context.recommendation_type = recommendation_type
     builder_context.project.runtime_environment.hardware.cpu_family = cpu_family
     builder_context.project.runtime_environment.hardware.cpu_model = cpu_model
     assert list(self.UNIT_TESTED.should_include(builder_context)) == []
 def test_no_include(
     self,
     builder_context: PipelineBuilderContext,
     recommendation_type: RecommendationType,
     decision_type: DecisionType,
     library_usage: str,
 ) -> None:
     """Test not including this pipeline unit."""
     builder_context.decision_type = decision_type
     builder_context.recommendation_type = recommendation_type
     builder_context.library_usage = library_usage
     assert builder_context.is_adviser_pipeline(
     ) or builder_context.is_dependency_monkey_pipeline()
     assert self.UNIT_TESTED.should_include(builder_context) is None
 def test_no_include(
     self,
     builder_context: PipelineBuilderContext,
     recommendation_type,
     decision_type: DecisionType,
     cpu_family: Optional[int],
     cpu_model: Optional[int],
 ) -> None:
     """Test not including this pipeline unit step."""
     builder_context.decision_type = decision_type
     builder_context.recommendation_type = recommendation_type
     # A Haswell CPU with AVX2 support.
     builder_context.project.runtime_environment.hardware.cpu_family = cpu_family
     builder_context.project.runtime_environment.hardware.cpu_model = cpu_model
     assert TensorFlowAVX2Step.should_include(builder_context) is None
Exemple #9
0
 def test_should_include_recommendation_type(
         self, builder_context: PipelineBuilderContext,
         recommendation_type: RecommendationType):
     """Check inclusion for various recommendation types."""
     builder_context.recommendation_type = recommendation_type
     builder_context.decision_type = None
     if recommendation_type in (RecommendationType.LATEST,
                                RecommendationType.TESTING):
         assert list(self.UNIT_TESTED.should_include(builder_context)) == [{
             "cve_penalization":
             0.0
         }]
     else:
         assert list(
             self.UNIT_TESTED.should_include(builder_context)) == [{}]
Exemple #10
0
    def test_no_include(
        self,
        builder_context: PipelineBuilderContext,
        python_version: Optional[str],
        recommendation_type: RecommendationType,
        decision_type: DecisionType,
        develop: bool,
    ) -> None:
        """Test not including this unit."""
        builder_context.project.runtime_environment.python_version = python_version
        builder_context.recommendation_type = recommendation_type
        builder_context.decision_type = decision_type

        assert builder_context.is_dependency_monkey_pipeline() or builder_context.is_adviser_pipeline()
        assert ImportlibResourcesBackportSieve.should_include(builder_context) is None
    def test_verify_multiple_should_include(self) -> None:
        """Verify multiple should_include calls do not loop endlessly."""
        builder_context = PipelineBuilderContext(recommendation_type=RecommendationType.LATEST)

        for package_name in ("tensorflow", "tensorflow-cpu", "tensorflow-gpu", "intel-tensorflow"):
            pipeline_config = self.UNIT_TESTED.should_include(builder_context)
            assert pipeline_config is not None
            assert pipeline_config == {"package_name": package_name}

            unit = self.UNIT_TESTED()
            unit.update_configuration(pipeline_config)

            builder_context.add_unit(unit)

        assert self.UNIT_TESTED.should_include(builder_context) is None, "The unit must not be included"
Exemple #12
0
    def test_include(
        self,
        builder_context: PipelineBuilderContext,
        recommendation_type: RecommendationType,
    ) -> None:
        """Test including this pipeline unit."""
        builder_context.recommendation_type = recommendation_type
        builder_context.project = Project.from_strings(self._CASE_ENABLED)

        assert builder_context.is_adviser_pipeline()
        assert list(self.UNIT_TESTED.should_include(builder_context)) == [{
            "package_name":
            "tensorflow",
            "index_url":
            "https://thoth-station.ninja/simple",
        }]
Exemple #13
0
    def verify_multiple_should_include(
            cls, builder_context: PipelineBuilderContext) -> bool:
        """Check multiple should_include calls do not end in an infinite loop."""
        assert cls.UNIT_TESTED is not None, "No unit assigned for testing"
        pipeline_config = cls.UNIT_TESTED.should_include(builder_context)
        assert pipeline_config is not None, "First call to should_include should be always non-None"

        unit = cls.UNIT_TESTED()
        if pipeline_config:
            unit.update_configuration(pipeline_config)

        builder_context.add_unit(unit)
        assert (
            cls.UNIT_TESTED.should_include(builder_context) is None
        ), "Make sure the pipeline unit does not loop endlessly on multiple should_include calls"
        return True
    def test_should_include(
        self,
        builder_context: PipelineBuilderContext,
        python_version: str,
        recommendation_type: RecommendationType,
        decision_type: DecisionType,
        develop: bool,
    ) -> None:
        """Test registering this unit."""
        builder_context.project.runtime_environment.python_version = python_version
        builder_context.recommendation_type = recommendation_type
        builder_context.decision_type = decision_type

        assert builder_context.is_dependency_monkey_pipeline(
        ) or builder_context.is_adviser_pipeline()
        assert Functools32BackportSieve.should_include(builder_context) == {}
    def test_verify_multiple_should_include(self, builder_context: PipelineBuilderContext) -> None:
        """Verify multiple should_include calls do not loop endlessly."""
        builder_context.recommendation_type = RecommendationType.STABLE
        builder_context.project.runtime_environment.cuda_version = None

        for package_name in ("tensorflow", "tensorflow-cpu"):
            pipeline_config = self.UNIT_TESTED.should_include(builder_context)
            assert pipeline_config is not None
            assert pipeline_config == {"package_name": package_name}

            unit = self.UNIT_TESTED()
            unit.update_configuration(pipeline_config)

            builder_context.add_unit(unit)

        assert self.UNIT_TESTED.should_include(builder_context) is None, "The unit must not be included"
 def test_include(
     self,
     builder_context: PipelineBuilderContext,
     cpu_model: int,
     cpu_family: str,
     recommendation_type: RecommendationType,
 ) -> None:
     """Test including this pipeline unit."""
     builder_context.decision_type = None
     builder_context.recommendation_type = recommendation_type
     builder_context.project.runtime_environment.hardware.cpu_family = cpu_family
     builder_context.project.runtime_environment.hardware.cpu_model = cpu_model
     builder_context.project.runtime_environment.platform = "linux-x86_64"
     assert builder_context.is_adviser_pipeline()
     assert not builder_context.is_dependency_monkey_pipeline()
     assert IntelTensorFlowWrap.should_include(builder_context) == {}
Exemple #17
0
    def test_verify_multiple_should_include(self, builder_context: PipelineBuilderContext) -> None:
        """Verify multiple should_include calls do not loop endlessly."""
        builder_context.recommendation_type = RecommendationType.STABLE
        builder_context.project.runtime_environment.cuda_version = "10.1"

        pipeline_config = list(self.UNIT_TESTED.should_include(builder_context))
        assert {"package_name": "tensorflow"} in pipeline_config
        assert {"package_name": "tensorflow-gpu"} in pipeline_config
        assert len(pipeline_config) == 2

        for item in pipeline_config:
            unit = self.UNIT_TESTED()
            unit.update_configuration(item)
            builder_context.add_unit(unit)

        assert list(self.UNIT_TESTED.should_include(builder_context)) == [], "The unit must not be included"
 def test_verify_multiple_should_include(self, builder_context: PipelineBuilderContext) -> None:
     """Verify multiple should_include calls do not loop endlessly."""
     builder_context.recommendation_type = RecommendationType.STABLE
     builder_context.project.runtime_environment.hardware.cpu_model = 13
     builder_context.project.runtime_environment.hardware.cpu_family = 6
     builder_context.project.runtime_environment.platform = "linux-x86_64"
     self.verify_multiple_should_include(builder_context)
Exemple #19
0
    def test_include(
        self,
        builder_context: PipelineBuilderContext,
        recommendation_type: RecommendationType,
    ) -> None:
        """Test including this pipeline unit."""
        builder_context.recommendation_type = recommendation_type
        builder_context.project = Project.from_strings(
            self._CASE_GLOBAL_ALLOW_PIPFILE)

        assert builder_context.is_adviser_pipeline()
        assert list(self.UNIT_TESTED.should_include(builder_context)) == [{
            "package_name":
            None,
            "allowed_indexes": {"https://pypi.org/simple"},
        }]
    def test_verify_multiple_should_include(
            self, builder_context: PipelineBuilderContext) -> None:
        """Verify multiple should_include calls do not loop endlessly."""
        builder_context.recommendation_type = RecommendationType.STABLE

        for package_name in ("tensorflow", "tensorflow-cpu", "tensorflow-gpu"):
            pipeline_config = self.UNIT_TESTED.should_include(builder_context)
            assert pipeline_config is not None
            assert pipeline_config == {"package_name": package_name}

            unit = self.UNIT_TESTED()
            unit.update_configuration(pipeline_config)

            builder_context.add_unit(unit)

        self.verify_multiple_should_include(builder_context)
Exemple #21
0
 def test_verify_multiple_should_include(
         self, builder_context: PipelineBuilderContext) -> None:
     """Verify multiple should_include calls do not loop endlessly."""
     builder_context.recommendation_type = RecommendationType.LATEST
     builder_context.project.runtime_environment.should_receive(
         "is_fully_specified").with_args().and_return(True)
     self.verify_multiple_should_include(builder_context)
 def test_get_included_pseudonyms(self) -> None:
     """Test get included pseudonyms of the provided pseudonym class."""
     builder_context = PipelineBuilderContext(decision_type=DecisionType.RANDOM)
     assert list(builder_context.get_included_pseudonyms(units.pseudonyms.Pseudonym1)) == []
     assert list(builder_context.get_included_pseudonym_names()) == []
     unit = units.pseudonyms.Pseudonym1()
     builder_context.add_unit(unit)
     assert list(builder_context.get_included_pseudonyms(units.pseudonyms.Pseudonym1)) == [unit]
     assert list(builder_context.get_included_pseudonym_names()) == ["Pseudonym1"]
 def test_get_included_strides(self) -> None:
     """Get included strides of the provided stride class."""
     builder_context = PipelineBuilderContext(decision_type=DecisionType.RANDOM)
     assert list(builder_context.get_included_strides(units.strides.Stride1)) == []
     assert list(builder_context.get_included_stride_names()) == []
     unit = units.strides.Stride1()
     builder_context.add_unit(unit)
     assert list(builder_context.get_included_strides(units.strides.Stride1)) == [unit]
     assert list(builder_context.get_included_stride_names()) == ["Stride1"]
 def test_get_included_wraps(self) -> None:
     """Get included wraps of the provided wrap class."""
     builder_context = PipelineBuilderContext(decision_type=DecisionType.RANDOM)
     assert list(builder_context.get_included_wraps(units.wraps.Wrap1)) == []
     assert list(builder_context.get_included_wrap_names()) == []
     unit = units.wraps.Wrap1()
     builder_context.add_unit(unit)
     assert list(builder_context.get_included_wraps(units.wraps.Wrap1)) == [unit]
     assert list(builder_context.get_included_wrap_names()) == ["Wrap1"]
 def test_get_included_boots(self) -> None:
     """Test get included boots of the provided boot class."""
     builder_context = PipelineBuilderContext(decision_type=DecisionType.RANDOM)
     assert list(builder_context.get_included_boots(units.boots.Boot1)) == []
     assert list(builder_context.get_included_boot_names()) == []
     unit = units.boots.Boot1()
     builder_context.add_unit(unit)
     assert list(builder_context.get_included_boots(units.boots.Boot1)) == [unit]
     assert list(builder_context.get_included_boot_names()) == ["Boot1"]
Exemple #26
0
    def verify_multiple_should_include(cls, builder_context: PipelineBuilderContext) -> bool:
        """Check multiple should_include calls do not end in an infinite loop."""
        assert cls.UNIT_TESTED is not None, "No unit assigned for testing"
        pipeline_config = list(cls.UNIT_TESTED.should_include(builder_context))
        assert pipeline_config != [], "First call to should_include should be always non-empty generator"
        assert (
            len(pipeline_config) == 1
        ), "First call to should_include should return one config, adjust the test if it requires additional logic"

        unit = cls.UNIT_TESTED()
        unit.update_configuration(pipeline_config[0])

        builder_context.add_unit(unit)
        assert (
            list(cls.UNIT_TESTED.should_include(builder_context)) == []
        ), "Make sure the pipeline unit does not loop endlessly on multiple should_include calls"
        return True
Exemple #27
0
 def test_verify_multiple_should_include(
         self, builder_context: PipelineBuilderContext) -> None:
     """Verify multiple should_include calls do not loop endlessly."""
     builder_context.recommendation_type = RecommendationType.STABLE
     builder_context.project.runtime_environment.operating_system.name = "rhel"
     builder_context.project.runtime_environment.operating_system.version = "8.2"
     builder_context.project.runtime_environment.python_version = "3.6"
     self.verify_multiple_should_include(builder_context)
Exemple #28
0
    def test_should_include_rpm_packages(
        self,
        builder_context: PipelineBuilderContext,
        rpms_present: List[Dict[str, str]],
        rpms_configured: List[Dict[str, str]],
        include: bool,
    ) -> None:
        """Test including pipeline units based on RPM packages present in the base image."""
        base_image_present_name, base_image_present_version = "s2i-thoth", "1.0.0"
        builder_context.project.runtime_environment.base_image = (
            f"{base_image_present_name}:v{base_image_present_version}"
        )
        should_include = {
            "adviser_pipeline": True,
            "runtime_environments": {"base_images": [builder_context.project.runtime_environment.base_image]},
        }

        if rpms_configured:
            should_include["runtime_environments"]["rpm_packages"] = rpms_configured

        PRESCRIPTION_UNIT_SHOULD_INCLUDE_SCHEMA(should_include)

        if rpms_configured:
            builder_context.graph.should_receive("get_last_analysis_document_id").with_args(
                base_image_present_name,
                base_image_present_version,
                is_external=False,
            ).and_return("package-extract-foo-bar").once()
            builder_context.graph.should_receive("get_rpm_package_version_all").with_args(
                "package-extract-foo-bar"
            ).and_return(rpms_present).once()
        else:
            builder_context.graph.should_receive("get_last_analysis_document_id").times(0)
            builder_context.graph.should_receive("get_rpm_package_version_all").times(0)

        UnitPrescription._PRESCRIPTION = {
            "name": "RPMPackagesUnit",
            "should_include": should_include,
        }

        builder_context.recommendation_type = RecommendationType.LATEST
        builder_context.decision_type = None

        assert builder_context.is_adviser_pipeline()
        builder_context.should_receive("is_included").with_args(UnitPrescription).and_return(False).once()
        assert UnitPrescription._should_include_base(builder_context) == include
Exemple #29
0
 def test_verify_multiple_should_include(
         self, builder_context: PipelineBuilderContext) -> None:
     """Verify multiple should_include calls do not loop endlessly."""
     builder_context.recommendation_type = RecommendationType.STABLE
     # Not None and not in AVX2 CPUs listing.
     builder_context.project.runtime_environment.hardware.cpu_family = 0x0
     builder_context.project.runtime_environment.hardware.cpu_model = 0x0
     self.verify_multiple_should_include(builder_context)
    def test_no_include(
        self,
        builder_context: PipelineBuilderContext,
        decision_type: DecisionType,
        recommendation_type: RecommendationType,
        cpu_model: int,
        cpu_family: int,
        platform: Optional[str],
    ) -> None:
        """Test not including this pipeline unit."""
        builder_context.decision_type = decision_type
        builder_context.recommendation_type = recommendation_type
        builder_context.project.runtime_environment.hardware.cpu_model = cpu_model
        builder_context.project.runtime_environment.hardware.cpu_family = cpu_family
        builder_context.project.runtime_environment.platform = platform

        assert builder_context.is_adviser_pipeline() or builder_context.is_dependency_monkey_pipeline()
        assert IntelTensorFlowWrap.should_include(builder_context) is None