-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #256 from godatadriven/alphabetical-checks
Alphabetical checks
- Loading branch information
Showing
5 changed files
with
273 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import ast | ||
import logging | ||
from pathlib import Path | ||
|
||
from dbt_bouncer.logger import configure_console_logging | ||
|
||
|
||
def main(): | ||
"""Assert that all checks are alphabetically sorted.""" | ||
for f in Path("src/dbt_bouncer/checks").glob("*/*.py"): | ||
logging.info(f"Checking {f.name}...") | ||
with Path.open(f) as file: | ||
node = ast.parse(file.read()) | ||
|
||
class_names = [ | ||
class_.name | ||
for class_ in [n for n in node.body if isinstance(n, ast.ClassDef)] | ||
if class_.name.startswith("Check") | ||
] | ||
logging.debug(f"{class_names=}") | ||
logging.debug(f"{sorted(class_names)=}") | ||
logging.debug(class_names == sorted(class_names)) | ||
assert class_names == sorted( | ||
class_names | ||
), f"Class names are not sorted alphabetically in {f.name}" | ||
|
||
|
||
if __name__ == "__main__": | ||
configure_console_logging(1) | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.