From 33993dbf47ad6e82c870cf728acaecdd8788b9ea Mon Sep 17 00:00:00 2001 From: rabelmervin Date: Wed, 13 Nov 2024 22:25:14 +0530 Subject: [PATCH 1/7] changes made for table iteration --- paracelsus/graph.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/paracelsus/graph.py b/paracelsus/graph.py index 5f98048..21d439e 100644 --- a/paracelsus/graph.py +++ b/paracelsus/graph.py @@ -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 @@ -83,9 +83,15 @@ 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" From b162ff2c57045520d485a0f5ba614e6c90e523df Mon Sep 17 00:00:00 2001 From: rabelmervin Date: Tue, 19 Nov 2024 18:58:25 +0530 Subject: [PATCH 2/7] changes made --- paracelsus/graph.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/paracelsus/graph.py b/paracelsus/graph.py index 21d439e..6a5953f 100644 --- a/paracelsus/graph.py +++ b/paracelsus/graph.py @@ -83,14 +83,11 @@ def resolve_included_tables( case 0, 0: return all_tables case 0, int(): - excluded = {table for table in all_tables - if any(re.match(pattern,table)for pattern in 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: + included = {table for table in all_tables if any(re.match(pattern, table) for pattern in include_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( From e13d509a66ee6c12aacd81f3a0abfc19dd6d9f42 Mon Sep 17 00:00:00 2001 From: rabelmervin Date: Wed, 20 Nov 2024 21:13:26 +0530 Subject: [PATCH 3/7] tested --- tests/test_cli.py | 60 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 667a253..47e6d38 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,3 +1,5 @@ +from pathlib import Path +from typing import Literal import pytest from typer.testing import CliRunner @@ -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)], @@ -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, [ @@ -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, [ @@ -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, [ @@ -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, [ @@ -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, [ @@ -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, [ @@ -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 + + +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 \ No newline at end of file From ebe3616382624fc6ec8c511d82bc36e1945a42d9 Mon Sep 17 00:00:00 2001 From: rabelmervin Date: Wed, 20 Nov 2024 22:15:20 +0530 Subject: [PATCH 4/7] Changes made --- tests/test_cli.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 47e6d38..d1bea72 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -144,7 +144,19 @@ def test_version(): assert result.exit_code == 0 from click.testing import CliRunner -from paracelsus.cli import cli +from paracelsus.cli import app + +from sqlalchemy import Column, Integer, String +from sqlalchemy.ext.declarative import declarative_base + +Base = declarative_base() + + +class Comments(Base): + __tablename__ = 'comments' + id = Column(Integer, primary_key=True) + text = Column(String) + @@ -159,13 +171,13 @@ def test_graph_with_inclusion_regex(package_path: Path): "--python-dir", str(package_path), "--include-tables", - "^com.*", + "comments", ], ) assert result.exit_code == 0 - assert "regular_table {" not in result.stdout - assert "first_test {" in result.stdout - assert "second{" not in result.stdout + assert "comments {" in result.stdout + assert "users {" not in result.stdout + assert "post{" not in result.stdout def test_graph_with_exclusion_regex(package_path: Path): @@ -179,10 +191,10 @@ def test_graph_with_exclusion_regex(package_path: Path): "--python-dir", str(package_path), "--exclude-tables", - "pos.*", + "^pos*", ], ) assert result.exit_code == 0 - assert "regular_table {" in result.stdout - assert "first {" not in result.stdout - assert "second {" in result.stdout \ No newline at end of file + assert "comments {" in result.stdout + assert "users {" in result.stdout + assert "post {" not in result.stdout \ No newline at end of file From fa69117b0588dd0a138e84e61ae31277dba17b11 Mon Sep 17 00:00:00 2001 From: rabelmervin Date: Wed, 20 Nov 2024 22:46:02 +0530 Subject: [PATCH 5/7] formatted --- tests/test_cli.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index d1bea72..1aa8a61 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -22,7 +22,7 @@ def test_graph(package_path: Path): @pytest.mark.parametrize("column_sort_arg", ["key-based", "preserve-order"]) -def test_graph_column_sort(package_path: Path, column_sort_arg: Literal['key-based'] | Literal['preserve-order']): +def test_graph_column_sort(package_path: Path, column_sort_arg: Literal["key-based"] | Literal["preserve-order"]): result = runner.invoke( app, [ @@ -117,7 +117,7 @@ def test_inject(package_path: Path): @pytest.mark.parametrize("column_sort_arg", ["key-based", "preserve-order"]) -def test_inject_column_sort(package_path: Path, column_sort_arg: Literal['key-based'] | Literal['preserve-order']): +def test_inject_column_sort(package_path: Path, column_sort_arg: Literal["key-based"] | Literal["preserve-order"]): result = runner.invoke( app, [ @@ -143,6 +143,7 @@ def test_version(): result = runner.invoke(app, ["version"]) assert result.exit_code == 0 + from click.testing import CliRunner from paracelsus.cli import app @@ -153,13 +154,11 @@ def test_version(): class Comments(Base): - __tablename__ = 'comments' + __tablename__ = "comments" id = Column(Integer, primary_key=True) text = Column(String) - - def test_graph_with_inclusion_regex(package_path: Path): result = runner.invoke( app, @@ -197,4 +196,4 @@ def test_graph_with_exclusion_regex(package_path: Path): assert result.exit_code == 0 assert "comments {" in result.stdout assert "users {" in result.stdout - assert "post {" not in result.stdout \ No newline at end of file + assert "post {" not in result.stdout From c1c0b4da23c1ffb1ff028368383f607563835370 Mon Sep 17 00:00:00 2001 From: rabelmervin Date: Thu, 21 Nov 2024 05:41:54 +0530 Subject: [PATCH 6/7] changes --- tests/test_cli.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 1aa8a61..032bf3e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -144,21 +144,6 @@ def test_version(): assert result.exit_code == 0 -from click.testing import CliRunner -from paracelsus.cli import app - -from sqlalchemy import Column, Integer, String -from sqlalchemy.ext.declarative import declarative_base - -Base = declarative_base() - - -class Comments(Base): - __tablename__ = "comments" - id = Column(Integer, primary_key=True) - text = Column(String) - - def test_graph_with_inclusion_regex(package_path: Path): result = runner.invoke( app, @@ -170,7 +155,7 @@ def test_graph_with_inclusion_regex(package_path: Path): "--python-dir", str(package_path), "--include-tables", - "comments", + "^com.*", ], ) assert result.exit_code == 0 @@ -190,7 +175,7 @@ def test_graph_with_exclusion_regex(package_path: Path): "--python-dir", str(package_path), "--exclude-tables", - "^pos*", + "^pos*.", ], ) assert result.exit_code == 0 From 5d572b2ba53d351bbc946ebfb0b4125ddccc3f44 Mon Sep 17 00:00:00 2001 From: rabelmervin Date: Thu, 21 Nov 2024 18:41:44 +0530 Subject: [PATCH 7/7] changed --- paracelsus/graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paracelsus/graph.py b/paracelsus/graph.py index 6a5953f..7031cd1 100644 --- a/paracelsus/graph.py +++ b/paracelsus/graph.py @@ -94,7 +94,7 @@ def resolve_included_tables( f"Some tables to include ({non_existent_tables}) don't exist" "withinthe found tables ({all_tables})." ) - return include_tables + return included case _: raise ValueError( f"Only one or none of include_tables ({include_tables}) or exclude_tables"