def test_create_discovery_function():
    def insane_discovery(info):
        """Completely crazy discovery function:

            * wrong arg name
            * is not a generator
            * returns all kinds of stuff
        """
        assert info == ["info"]
        return [
            ("foo", {}),
            "some string",
            HostLabel("whoop", "deedoo"),
            OldService("bar", {"P": "O"}),
        ]

    new_function = check_plugins_legacy._create_discovery_function(
        {"inventory_function": insane_discovery}, )

    fixed_params = inspect.signature(new_function).parameters
    assert list(fixed_params) == ["section"]
    assert inspect.isgeneratorfunction(new_function)

    result = list(new_function(["info"]))
    assert result == [
        checking_types.Service(item="foo"),
        "some string",  # bogus value let through intentionally
        checking_types.Service(item="bar", parameters={"P": "O"}),
    ]
def test_create_discovery_function(monkeypatch):
    def insane_discovery(info):
        """Completely crazy discovery function:

            * wrong arg name
            * is not a generator
            * returns all kinds of stuff
        """
        assert info == ["info"]
        return [
            ("foo", {}),
            ("foo", "params_string"),
            "some string",
            HostLabel("whoop", "deedoo"),
            OldService("bar", {"P": "O"}),
        ]

    monkeypatch.setattr(config, "_check_contexts",
                        {"norris": {
                            "params_string": {
                                "levels": "default"
                            }
                        }})
    new_function = check_plugins_legacy._create_discovery_function(
        "norris",
        {"inventory_function": insane_discovery},
        config.get_check_context,
    )

    fixed_params = inspect.signature(new_function).parameters
    assert list(fixed_params) == ["section"]
    assert inspect.isgeneratorfunction(new_function)

    result = list(new_function(["info"]))
    expected: List = [
        checking_classes.Service(item="foo"),
        checking_classes.Service(item="foo", parameters={"levels": "default"}),
        "some string",  # bogus value let through intentionally
        checking_classes.Service(item="bar", parameters={"P": "O"}),
    ]
    assert result == expected