Esempio n. 1
0
    def test_not_solved_without_error(self, context: Context) -> None:
        """Test a not found package is not accepted by sieve."""
        package_version, project = self._get_case()
        (GraphDatabase.should_receive("has_python_solver_error").with_args(
            package_version.name,
            package_version.locked_version,
            package_version.index.url,
            os_name=None,
            os_version=None,
            python_version=None,
        ).and_return(True).once())

        context.graph = GraphDatabase()
        context.project = flexmock(
            runtime_environment=RuntimeEnvironment.from_dict({}))

        assert not context.stack_info, "No stack info should be provided before test run"

        sieve = SolvedSieve()
        sieve.pre_run()

        with SolvedSieve.assigned_context(context):
            assert list(sieve.run(p for p in [package_version])) == []

        assert context.stack_info, "No stack info provided by the pipeline unit"
        assert self.verify_justification_schema(context.stack_info) is True
Esempio n. 2
0
    def test_no_rule(self, context: Context) -> None:
        """Test if no rule is configured for the given package."""
        package_version = PackageVersion(
            name="flask",
            version="==1.1.2",
            index=Source("https://pypi.org/simple"),
            develop=False)
        (GraphDatabase.should_receive(
            "get_python_package_version_solver_rules_all").with_args(
                "flask",
                "1.1.2",
                "https://pypi.org/simple",
            ).and_return([]))
        (GraphDatabase.should_receive(
            "get_python_package_version_solver_rules_all").with_args(
                "flask",
                "1.1.2",
            ).and_return([]))

        context.graph = GraphDatabase()

        assert not context.stack_info, "No stack info should be provided before test run"

        sieve = self.UNIT_TESTED()
        sieve.pre_run()

        with self.UNIT_TESTED.assigned_context(context):
            assert list(sieve.run(
                p for p in [package_version])) == [package_version]

        assert not context.stack_info, "No stack info should be provided by the pipeline unit"
Esempio n. 3
0
    def test_rule(self, context: Context) -> None:
        """Test if a rule is assigned to a package."""
        package_version = PackageVersion(
            name="flask",
            version="==1.1.2",
            index=Source("https://pypi.org/simple"),
            develop=False)
        (GraphDatabase.should_receive(
            "get_python_package_version_solver_rules_all").with_args(
                "flask",
                "1.1.2",
                "https://pypi.org/simple",
            ).and_return(["foo"]))
        (GraphDatabase.should_receive(
            "get_python_package_version_solver_rules_all").with_args(
                "flask",
                "1.1.2",
            ).and_return(["bar"]))

        context.graph = GraphDatabase()

        assert not context.stack_info, "No stack info should be provided before test run"

        sieve = self.UNIT_TESTED()
        sieve.pre_run()

        with self.UNIT_TESTED.assigned_context(context):
            assert list(sieve.run(p for p in [package_version])) == []

        assert context.stack_info == [
            {
                "link":
                "https://thoth-station.ninja/j/rules",
                "message":
                "Removing package ('flask', '1.1.2', 'https://pypi.org/simple') based on solver "
                "rule configured: foo",
                "type":
                "WARNING",
            },
            {
                "link":
                "https://thoth-station.ninja/j/rules",
                "message":
                "Removing package ('flask', '1.1.2', 'https://pypi.org/simple') based on solver "
                "rule configured: bar",
                "type":
                "WARNING",
            },
        ]
        assert self.verify_justification_schema(context.stack_info) is True
Esempio n. 4
0
    def test_not_solved_without_error(self, context: Context) -> None:
        """Test a not found package is not accepted by sieve."""
        package_version, project = self._get_case()
        (GraphDatabase.should_receive("has_python_solver_error").with_args(
            package_version.name,
            package_version.locked_version,
            package_version.index.url,
            os_name=None,
            os_version=None,
            python_version=None,
        ).and_return(True).once())

        context.graph = GraphDatabase()
        context.project = flexmock(
            runtime_environment=RuntimeEnvironment.from_dict({}))

        assert not context.stack_info, "No stack info should be provided before test run"

        sieve = SolvedSieve()
        sieve.pre_run()

        with SolvedSieve.assigned_context(context):
            assert list(sieve.run(p for p in [package_version])) == []
            sieve.post_run()

        assert context.stack_info, "No stack info provided by the pipeline unit"
        assert context.stack_info == [{
            "link":
            jl("install_error"),
            "message":
            "The following versions of 'tensorflow' from "
            "'https://pypi.org/simple' were removed due to installation "
            "issues in the target environment: 2.0.0",
            "type":
            "WARNING",
        }]

        assert self.verify_justification_schema(context.stack_info) is True