Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes made for table iteration #26

Merged
merged 7 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions paracelsus/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import os
import sys
from pathlib import Path
import re
from typing import List, Set

from sqlalchemy import MetaData

from sqlalchemy.schema import MetaData
from .transformers.dot import Dot
from .transformers.mermaid import Mermaid

Expand Down Expand Up @@ -83,9 +83,12 @@ def resolve_included_tables(
case 0, 0:
return all_tables
case 0, int():
return all_tables - exclude_tables
excluded = {table for table in all_tables if any(re.match(pattern, table) for pattern in exclude_tables)}
return all_tables - excluded
case int(), 0:
if not include_tables.issubset(all_tables):
included = {table for table in all_tables if any(re.match(pattern, table) for pattern in include_tables)}

if not included:
non_existent_tables = include_tables - all_tables
raise ValueError(
f"Some tables to include ({non_existent_tables}) don't exist"
Expand Down
60 changes: 53 additions & 7 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from pathlib import Path
from typing import Literal
import pytest

from typer.testing import CliRunner
Expand All @@ -9,7 +11,7 @@
runner = CliRunner()


def test_graph(package_path):
def test_graph(package_path: Path):
result = runner.invoke(
app,
["graph", "example.base:Base", "--import-module", "example.models", "--python-dir", str(package_path)],
Expand All @@ -20,7 +22,7 @@ def test_graph(package_path):


@pytest.mark.parametrize("column_sort_arg", ["key-based", "preserve-order"])
def test_graph_column_sort(package_path, column_sort_arg):
def test_graph_column_sort(package_path: Path, column_sort_arg: Literal['key-based'] | Literal['preserve-order']):
result = runner.invoke(
app,
[
Expand All @@ -39,7 +41,7 @@ def test_graph_column_sort(package_path, column_sort_arg):
mermaid_assert(result.stdout)


def test_graph_with_exclusion(package_path):
def test_graph_with_exclusion(package_path: Path):
result = runner.invoke(
app,
[
Expand All @@ -58,7 +60,7 @@ def test_graph_with_exclusion(package_path):
assert "comments {" not in result.stdout


def test_graph_with_inclusion(package_path):
def test_graph_with_inclusion(package_path: Path):
result = runner.invoke(
app,
[
Expand All @@ -77,7 +79,7 @@ def test_graph_with_inclusion(package_path):
assert "comments {" in result.stdout


def test_inject_check(package_path):
def test_inject_check(package_path: Path):
result = runner.invoke(
app,
[
Expand All @@ -94,7 +96,7 @@ def test_inject_check(package_path):
assert result.exit_code == 1


def test_inject(package_path):
def test_inject(package_path: Path):
result = runner.invoke(
app,
[
Expand All @@ -115,7 +117,7 @@ def test_inject(package_path):


@pytest.mark.parametrize("column_sort_arg", ["key-based", "preserve-order"])
def test_inject_column_sort(package_path, column_sort_arg):
def test_inject_column_sort(package_path: Path, column_sort_arg: Literal['key-based'] | Literal['preserve-order']):
result = runner.invoke(
app,
[
Expand All @@ -140,3 +142,47 @@ def test_inject_column_sort(package_path, column_sort_arg):
def test_version():
result = runner.invoke(app, ["version"])
assert result.exit_code == 0

from click.testing import CliRunner
from paracelsus.cli import cli



def test_graph_with_inclusion_regex(package_path: Path):
result = runner.invoke(
app,
[
"graph",
"example.base:Base",
"--import-module",
"example.models",
"--python-dir",
str(package_path),
"--include-tables",
"^com.*",
],
)
assert result.exit_code == 0
assert "regular_table {" not in result.stdout
assert "first_test {" in result.stdout
assert "second{" not in result.stdout
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests don't make sense- I don't know where these strings are coming from. The goal here is to test that the proper columns exist, but the excluded ones do not.

In this case we have three tables- comments, users, and posts. Since we're trying to include the pattern ^com.* we expect the comments table to be in the diagram but not the other two.

assert "comments {" in result.stdout
assert "users {" not in result.stdout
assert "post {" not in result.stdout

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I apologise @tedivm I'll make changes !

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries! I appreciate you taking this on!



def test_graph_with_exclusion_regex(package_path: Path):
result = runner.invoke(
app,
[
"graph",
"example.base:Base",
"--import-module",
"example.models",
"--python-dir",
str(package_path),
"--exclude-tables",
"pos.*",
],
)
assert result.exit_code == 0
assert "regular_table {" in result.stdout
assert "first {" not in result.stdout
assert "second {" in result.stdout
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case we have three tables- comments, users, and posts. Since we're trying to exclude the pattern ^pos.* we expect the comments and users table to be in the diagram but not the posts one.

assert "comments {" in result.stdout
assert "users {" in result.stdout
assert "post {" not in result.stdout

Loading