def test__linter__path_from_paths__file(): """Test extracting paths from a file path.""" lntr = Linter() paths = lntr.paths_from_path("test/fixtures/linter/indentation_errors.sql") assert normalise_paths(paths) == { "test.fixtures.linter.indentation_errors.sql" }
def test__linter__path_from_paths__exts(): """Test configuration of file discovery.""" lntr = Linter(config=FluffConfig(overrides={"sql_file_exts": ".txt"})) paths = normalise_paths(lntr.paths_from_path("test/fixtures/linter")) assert "test.fixtures.linter.passing.sql" not in paths assert "test.fixtures.linter.passing_cap_extension.SQL" not in paths assert "test.fixtures.linter.discovery_file.txt" in paths
def test__linter__path_from_paths__default(): """Test .sql files are found by default.""" lntr = Linter() paths = normalise_paths(lntr.paths_from_path("test/fixtures/linter")) assert "test.fixtures.linter.passing.sql" in paths assert "test.fixtures.linter.passing_cap_extension.SQL" in paths assert "test.fixtures.linter.discovery_file.txt" not in paths
def test__linter__path_from_paths__ignore(path): """Test extracting paths from a dot.""" lntr = Linter() paths = lntr.paths_from_path(path) # We should only get query_b, because of the sqlfluffignore files. assert normalise_paths(paths) == { "test.fixtures.linter.sqlfluffignore.path_b.query_b.sql" }
def test__linter__path_from_paths__dir(): """Test extracting paths from directories.""" lntr = Linter() paths = lntr.paths_from_path("test/fixtures/lexer") assert normalise_paths(paths) == { "test.fixtures.lexer.block_comment.sql", "test.fixtures.lexer.inline_comment.sql", "test.fixtures.lexer.basic.sql", }
def test__linter__path_from_paths__dot(): """Test extracting paths from a dot.""" lntr = Linter() paths = lntr.paths_from_path(".") # Use set theory to check that we get AT LEAST these files assert normalise_paths(paths) >= { "test.fixtures.lexer.block_comment.sql", "test.fixtures.lexer.inline_comment.sql", "test.fixtures.lexer.basic.sql", }
def test__linter__path_from_paths__explicit_ignore(): """Test ignoring files that were passed explicitly.""" lntr = Linter() paths = lntr.paths_from_path( "test/fixtures/linter/sqlfluffignore/path_a/query_a.sql", ignore_non_existent_files=True, ignore_files=True, working_path="test/fixtures/linter/sqlfluffignore/", ) assert len(paths) == 0
def test__linter__path_from_paths__sqlfluffignore_current_directory(): """Test that .sqlfluffignore in the current directory is read when dir given.""" oldcwd = os.getcwd() try: os.chdir("test/fixtures/linter/sqlfluffignore") lntr = Linter() paths = lntr.paths_from_path( "path_a/", ignore_non_existent_files=True, ignore_files=True, working_path="test/fixtures/linter/sqlfluffignore/", ) assert len(paths) == 0 finally: os.chdir(oldcwd)
def test__linter__path_from_paths__not_exist_ignore(): """Test extracting paths from a file path.""" lntr = Linter() paths = lntr.paths_from_path("asflekjfhsakuefhse", ignore_non_existent_files=True) assert len(paths) == 0
def test__linter__path_from_paths__not_exist(): """Test extracting paths from a file path.""" lntr = Linter() with pytest.raises(IOError): lntr.paths_from_path("asflekjfhsakuefhse")