def validate_test_settings_data(test_settings_data):
    """Raise exception if test settings data doesn't validate."""

    key = TEST_SESSION_SETTINGS_KEY

    ### ensure test settings data is a dict

    if not isinstance(test_settings_data, dict):

        raise TypeError(
            f"Test settings data from '{key}' key in user preferences"
            " must be a dictionary."
        )

    ### ensure its contents validate as well

    for subkey in ('test_cases_ids', 'playback_speed'):

        if subkey not in test_settings_data:

            raise (

                KeyError

                (
                    f"'{subkey}' not present in '{key}' key"
                    " from user preferences"
                )

            )

        elif subkey == 'test_cases_ids':

            value = test_settings_data[subkey]

            if not isinstance(value, tuple):

                raise (

                    TypeError

                    (
                        f"'{subkey}' subkey from '{key}' key"
                        " in user preferences must hold a tuple."
                    )

                )

            elif (
                any(
                    not isinstance(item, int)
                    for item in value
                )
            ):

                raise (
                    TypeError
                    (
                        f"'{subkey}' subkey from '{key}' key"
                        " in user preferences must hold at least one item"
                        " and all items must be integers"
                    )
                )

        elif subkey == 'playback_speed':

            value = test_settings_data[subkey]

            if not isinstance(value, int):

                raise (

                    TypeError

                    (
                        f"'{subkey}' subkey from '{key}' key"
                        " in user preferences must hold an int."
                    )

                )

            elif value < 0:

                raise (

                    ValueError

                    (
                        f"'{subkey}' subkey from '{key}' key"
                        " in user preferences must hold an integer >= 0"
                    )

                )
Raise exception if test settings data doesn't validate.
nodezator/userprefsman/validation.py