PyFixate / Fixate

Framework for hardware test fixtures and automatic test environments
MIT License
22 stars 16 forks source link

_user_req_input ignores valid falsy values #213

Open daniel-montanari opened 2 months ago

daniel-montanari commented 2 months ago

The ui implementations of requesting user input have a flaw when returning results. This is due to the validator functions returning a Union of validated input and False . The ui functions then blindly convert the result to a boolean and loop without feedback if a false value is received from the input validator. If a valid input converts to false, then the input is discarded.

I found this happening specifically with user_input_float as 0 or 0.0 are valid floats.

In cmd_line.py

    for _ in range(attempts):
        # This will change based on the interface
        print("\a")
        ret_val = input(msg)
        if target is None:
            q.put(ret_val)
            return
        ret_val = target(ret_val, **kwargs)
        if ret_val:
            q.put(("Result", ret_val))
            return

In ui_gui_qt.py

        for _ in range(attempts):
            # This will change based on the interface
            ret_val = self.gui_user_input(msg, None)
            if target is None or ret_val == "ABORT_FORCE":
                q.put(ret_val)
                return
            ret_val = target(ret_val, **kwargs)
            if ret_val:
                q.put(("Result", ret_val))
                return

example validator target

def _float_validate(entry):
    """Requires float entry"""
    try:
        return float(entry)
    except ValueError:
        user_info("Please enter a number")
        return False