def test__linter__skip_large_bytes(filesize, raises_skip): """Test extracting paths from a file path.""" config = FluffConfig(overrides={ "large_file_skip_byte_limit": filesize, "dialect": "ansi" }) # First check the function directly if raises_skip: with pytest.raises(SQLFluffSkipFile) as excinfo: Linter._load_raw_file_and_config( "test/fixtures/linter/indentation_errors.sql", config) assert "Skipping" in str(excinfo.value) assert f"over the limit of {filesize}" in str(excinfo.value) # If NOT raises, then we'll catch the raise an error and the test will fail. # Then check that it either is or isn't linted appropriately via lint_paths. lntr = Linter(config) result = lntr.lint_paths( ("test/fixtures/linter/indentation_errors.sql", ), ) if raises_skip: assert not result.get_violations() else: assert result.get_violations() # Same again via parse_path, which is the other entry point. result = list( lntr.parse_path("test/fixtures/linter/indentation_errors.sql", )) if raises_skip: assert not result else: assert result
def assert_structure(yaml_loader, path, code_only=True): """Check that a parsed sql file matches the yaml file with the same name.""" lntr = Linter() p = list(lntr.parse_path(path + ".sql")) parsed = p[0][0] if parsed is None: print(p) raise RuntimeError(p[0][1]) # Whitespace is important here to test how that's treated tpl = parsed.to_tuple(code_only=code_only, show_raw=True) # Check nothing unparsable if "unparsable" in parsed.type_set(): print(parsed.stringify()) raise ValueError("Input file is contains unparsable.") expected = yaml_loader(path + ".yml") assert tpl == expected