def load_query_context(name, add_contexts=[]): """ Get query context from yaml file. Args: name (str): name of query add_contexts (list): additional contexts if needed Returns: query_contexts (list): mixed array of strings (name of common contexts) and dictionaries (full definition of specific contexts) """ with open(sources.get(name, query=True)) as fh: query = yaml.load(fh, Loader=yaml.SafeLoader) # Extract query and context specific_contexts = query.pop("context") if "context" in query else {} contexts = context.extract_context_names(query) contexts.update(add_contexts) query_contexts = context.get_context_definitions(contexts, specific_contexts) return query_contexts
def test_extract_context_names(query, expected_contexts): contexts = context.extract_context_names(query) assert set(expected_contexts) == contexts