import torch


def test_observe_get_and_verify_response_input_unit(tmp_observe_class, method, tmp_val, monkeypatch):
    """
    test that _get_and_verify_response_input works for self.sampling["method"] = "iteratuve" or "functions". Leverage
    monkeypatching and create false class to mock that greattunes._observe will be called inside
    TuneSession class in greattunes.__init__. Rely on manual input for "iterative" option
    """

    # # define class
    cls = tmp_observe_class
    cls.sampling["method"] = method

    # monkeypatch the "support" functions _get_response_function_input, _read_response_manual_input
    def mock_get_response_function_input():
        return torch.tensor([[tmp_val]], dtype=torch.double,
                            device=torch.device("cuda" if torch.cuda.is_available() else "cpu"))

    monkeypatch.setattr(
        cls, "_get_response_function_input", mock_get_response_function_input
    )

    manual_tmp_val = tmp_val + 1.0
    def mock_read_response_manual_input(additional_text):
        return torch.tensor([[manual_tmp_val]], dtype=torch.double,
                            device=torch.device("cuda" if torch.cuda.is_available() else "cpu"))
    monkeypatch.setattr(
        cls, "_read_response_manual_input", mock_read_response_manual_input
    )

    # set kwarg response to None (so manually provided input is used)
    kwarg_response = None

    # run test
    output = cls._get_and_verify_response_input(response=kwarg_response)

    if method == "functions":
        assert output[0].item() == tmp_val
    elif method == "iterative":
        assert output[0].item() == manual_tmp_val