def test__templater_jinja_slice_file(raw_file, override_context, result, caplog): """Test slice_file.""" templater = JinjaTemplater(override_context=override_context) env, live_context, make_template = templater.template_builder( config=FluffConfig.from_path( "test/fixtures/templater/jinja_slice_template_macros")) templated_file = make_template(raw_file).render() with caplog.at_level(logging.DEBUG, logger="sqlfluff.templater"): _, resp, _ = templater.slice_file(raw_file, templated_file, make_template=make_template) # Check contiguous on the TEMPLATED VERSION print(resp) prev_slice = None for elem in resp: print(elem) if prev_slice: assert elem[2].start == prev_slice.stop prev_slice = elem[2] # Check that all literal segments have a raw slice for elem in resp: if elem[0] == "literal": assert elem[1] is not None # check result actual = [( templated_file_slice.slice_type, templated_file_slice.source_slice, templated_file_slice.templated_slice, ) for templated_file_slice in resp] assert actual == result
def test__templater_jinja_slice_file(raw_file, templated_file, result, caplog): """Test slice_file.""" with caplog.at_level(logging.DEBUG, logger="sqlfluff.templater"): _, resp = JinjaTemplater.slice_file( raw_file, templated_file, ) # Check contigious on the TEMPLATED VERSION print(resp) prev_slice = None for elem in resp: print(elem) if prev_slice: assert elem[2].start == prev_slice.stop prev_slice = elem[2] # Check that all literal segments have a raw slice for elem in resp: if elem[0] == "literal": assert elem[1] is not None # check result assert resp == result