Example #1
0
def validate_pykwalify(response, schema):
    """Make sure the response matches a given schema

    Args:
        response (Response): reqeusts.Response object
        schema (dict): Schema for response
    """
    with wrapfile(response.json()) as rdump, wrapfile(schema) as sdump:
        verify_generic(rdump, sdump)
Example #2
0
def _get_or_wrap_global_cfg(stack, tavern_global_cfg):
    """
    Try to parse global configuration from given argument.

    Args:
        stack (ExitStack): context stack for wrapping file if a dictionary is given
        tavern_global_cfg (dict, str): Dictionary or string. It should be a
            path to a file or a dictionary with configuration.

    Returns:
        str: path to global config file

    Raises:
        InvalidSettingsError: If global config was not of the right type or a given path
            does not exist

    Todo:
        Once python 2 is dropped, allow this to take a 'path like object'
    """
    if isinstance(tavern_global_cfg, str):
        if not os.path.exists(tavern_global_cfg):
            raise exceptions.InvalidSettingsError(
                "global config file '{}' does not exist".format(
                    tavern_global_cfg))
        global_filename = tavern_global_cfg
    elif isinstance(tavern_global_cfg, dict):
        global_filename = stack.enter_context(wrapfile(tavern_global_cfg))
    else:
        raise exceptions.InvalidSettingsError(
            "Invalid format for global settings - must be dict or path to settings file, was {}"
            .format(type(tavern_global_cfg)))

    return global_filename
Example #3
0
    def test_load_one(self):
        example = {"a": "b"}

        with wrapfile(example) as f:
            assert example == load_single_document_yaml(f)