def test__config__glob_include_config_tests(): """Test linting with a glob pattern in rules. This looks like a linter test but it's actually a config test. """ lntr = Linter( config=FluffConfig.from_path("test/fixtures/config/glob_include")) lnt = lntr.lint_path("test/fixtures/config/glob_include/test.sql") violations = lnt.check_tuples(by_path=True) for k in violations: assert ("L050", 1, 1) in violations[k] assert ("L051", 12, 1) in violations[k] assert ("L052", 12, 9) in violations[k] assert ("L027", 10, 8) in violations[k] assert "L044" not in [c[0] for c in violations[k]]
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"): raw_sliced, sliced_file, templated_str = templater.slice_file( raw_file, templated_file, make_template=make_template ) # Create a TemplatedFile from the results. This runs some useful sanity # checks. _ = TemplatedFile(raw_file, "<<DUMMY>>", templated_str, sliced_file, raw_sliced) # Check contiguous on the TEMPLATED VERSION print(sliced_file) prev_slice = None for elem in sliced_file: 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 sliced_file: 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 sliced_file ] assert actual == result
def test__templater_jinja_error_macro_path_does_not_exist(): """Tests that an error is raised if macro path doesn't exist.""" with pytest.raises(ValueError) as e: JinjaTemplater().template_builder(config=FluffConfig.from_path( "test/fixtures/templater/jinja_macro_path_does_not_exist")) assert str(e.value).startswith("Path does not exist")