Esempio n. 1
0
    def test_to_dict(self, pipeline_config: PipelineConfig) -> None:
        """Test conversion to a dict."""
        report = Report(count=3, pipeline=pipeline_config)

        project = flexmock()
        project_dict = {"aresto momentum": "avada kedavra"}
        project.should_receive("to_dict").with_args(
            keep_thoth_section=True).and_return(
                project_dict).twice()  # In test and in the report.

        product = Product(
            project=project,
            score=0.666,
            justification=[{
                "gryffindor": "le gladium leviosa"
            }],
            advised_runtime_environment=RuntimeEnvironment.from_dict(
                {"python_version": "3.6"}),
        )
        report.add_product(product)

        assert report.product_count() == 1
        assert list(report.iter_products()) == [product]
        assert report.to_dict() == {
            "pipeline": pipeline_config.to_dict(),
            "products": [product.to_dict()],
            "stack_info": [],
            "resolver_iterations": 0,
            "accepted_final_states_count": 0,
            "discarded_final_states_count": 0,
        }
Esempio n. 2
0
    def test_to_dict(self) -> None:
        """Test conversion of this product into a dictionary representation."""
        project = flexmock()
        project.should_receive("to_dict").with_args().and_return({
            "baz": "bar"
        }).once()

        advised_runtime_environment = flexmock()
        advised_runtime_environment.should_receive(
            "to_dict").with_args().and_return({
                "hello": "thoth"
            }).once()

        advised_manifest_changes = [[{
            "apiVersion": "apps.openshift.io/v1",
            "kind": "DeploymentConfig",
            "patch": {
                "op": "add",
                "path": "spec.template.spec.containers[0].env",
                "value": {
                    "name": "OMP_NUM_THREADS",
                    "value": "1"
                },
            },
        }]]

        product = Product(
            advised_manifest_changes=advised_manifest_changes,
            advised_runtime_environment=advised_runtime_environment,
            justification=[{
                "foo": "bar"
            }],
            project=project,
            score=0.999,
        )

        assert product.to_dict() == {
            "score": 0.999,
            "project": {
                "baz": "bar"
            },
            "justification": [{
                "foo": "bar"
            }],
            "advised_runtime_environment": {
                "hello": "thoth"
            },
            "advised_manifest_changes": advised_manifest_changes,
        }
Esempio n. 3
0
    def test_to_dict_metadata(self, pipeline_config: PipelineConfig) -> None:
        """Test conversion to a dict with passed metadata."""
        report = Report(count=3, pipeline=pipeline_config)

        project = flexmock()
        project_dict = {"aresto momentum": "avada kedavra"}
        project.should_receive("to_dict").with_args(
            keep_thoth_section=True).and_return(project_dict)

        product = Product(
            project=project,
            score=0.666,
            justification=[{
                "gryffindor": "le gladium leviosa"
            }],
            advised_runtime_environment=RuntimeEnvironment.from_dict(
                {"python_version": "3.6"}),
        )
        report.add_product(product)

        stack_info = [{"type": "WARNING", "message": "Hello, metadata"}]
        stack_info_metadata = {
            "thoth.adviser": {
                "stack_info": stack_info,
            }
        }
        report.set_stack_info([{"foo": "bar"}])

        assert "THOTH_ADVISER_METADATA" not in os.environ
        os.environ["THOTH_ADVISER_METADATA"] = json.dumps(stack_info_metadata)

        try:
            assert report.product_count() == 1
            assert list(report.iter_products()) == [product]
            assert report.to_dict() == {
                "pipeline": pipeline_config.to_dict(),
                "products": [product.to_dict()],
                "stack_info": list(chain(stack_info, report.stack_info)),
                "resolver_iterations": 0,
                "accepted_final_states_count": 0,
                "discarded_final_states_count": 0,
            }
        except Exception:
            os.environ.pop("THOTH_ADVISER_METADATA")
            raise
Esempio n. 4
0
    def test_to_dict(self) -> None:
        """Test conversion of this product into a dictionary representation."""
        project = flexmock()
        project.should_receive("to_dict").with_args().and_return({"baz": "bar"}).once()

        advised_runtime_environment = flexmock()
        advised_runtime_environment.should_receive("to_dict").with_args().and_return(
            {"hello": "thoth"}
        ).once()

        product = Product(
            score=0.999,
            project=project,
            justification=[{"foo": "bar"}],
            advised_runtime_environment=advised_runtime_environment,
        )

        assert product.to_dict() == {
            "score": 0.999,
            "project": {"baz": "bar"},
            "justification": [{"foo": "bar"}],
            "advised_runtime_environment": {"hello": "thoth"},
        }
Esempio n. 5
0
    def test_to_dict(self, context: Context) -> None:
        """Test conversion of this product into a dictionary representation."""
        project = context.project
        project.should_receive("to_dict").with_args(keep_thoth_section=True).and_return({"baz": "bar"}).once()

        advised_runtime_environment = flexmock()
        advised_runtime_environment.should_receive("to_dict").with_args().and_return({"hello": "thoth"}).once()

        advised_manifest_changes = [
            [
                {
                    "apiVersion": "apps.openshift.io/v1",
                    "kind": "DeploymentConfig",
                    "patch": {
                        "op": "add",
                        "path": "spec.template.spec.containers[0].env",
                        "value": {"name": "OMP_NUM_THREADS", "value": "1"},
                    },
                }
            ]
        ]

        product = Product(
            advised_manifest_changes=advised_manifest_changes,
            advised_runtime_environment=advised_runtime_environment,
            justification=[{"foo": "bar"}],
            project=project,
            score=0.999,
            context=context,
        )

        assert product.to_dict() == {
            "score": 0.999,
            "project": {"baz": "bar"},
            "justification": [{"foo": "bar"}],
            "advised_runtime_environment": {"hello": "thoth"},
            "advised_manifest_changes": advised_manifest_changes,
            "dependency_graph": {
                "edges": [],
                "nodes": [
                    "absl-py",
                    "astor",
                    "click",
                    "flask",
                    "gast",
                    "grpcio",
                    "itsdangerous",
                    "jinja2",
                    "markdown",
                    "markupsafe",
                    "numpy",
                    "protobuf",
                    "six",
                    "tensorboard",
                    "tensorflow",
                    "termcolor",
                    "werkzeug",
                    "wheel",
                ],
            },
        }