Skip to content

Commit

Permalink
add snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
Mause committed Dec 11, 2023
1 parent 11428a8 commit 3c05999
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
19 changes: 19 additions & 0 deletions duckdb_engine/tests/snapshots/snap_test_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# snapshottest: v1 - https://goo.gl/zC4yUc

from snapshottest import Snapshot

snapshots = Snapshot()

snapshots[
"test_graph 1"
] = """digraph G {
concentrate=False;
mode=ipsep;
overlap=ipsep;
prog=dot;
rankdir=LR;
sep="0.01";
user_prefs [fontname="Bitstream-Vera Sans", fontsize="7.0", label=<<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"><TR><TD ALIGN="CENTER">user_prefs</TD></TR><TR><TD BORDER="1" CELLPADDING="0"></TD></TR><TR><TD ALIGN="LEFT" PORT="pref_id">- pref_id</TD></TR><TR><TD ALIGN="LEFT" PORT="user_id">- user_id</TD></TR><TR><TD ALIGN="LEFT" PORT="pref_name">- pref_name</TD></TR><TR><TD ALIGN="LEFT" PORT="pref_value">- pref_value</TD></TR></TABLE>>, shape=plaintext];
user [fontname="Bitstream-Vera Sans", fontsize="7.0", label=<<TABLE BORDER="1" CELLBORDER="0" CELLSPACING="0"><TR><TD ALIGN="CENTER">user</TD></TR><TR><TD BORDER="1" CELLPADDING="0"></TD></TR><TR><TD ALIGN="LEFT" PORT="user_id">- user_id</TD></TR><TR><TD ALIGN="LEFT" PORT="user_name">- user_name</TD></TR><TR><TD ALIGN="LEFT" PORT="email_address">- email_address</TD></TR><TR><TD ALIGN="LEFT" PORT="nickname">- nickname</TD></TR></TABLE>>, shape=plaintext];
}
"""
23 changes: 6 additions & 17 deletions duckdb_engine/tests/test_graph.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
from sqlalchemy import (
Column,
ForeignKey,
Integer,
MetaData,
Sequence,
String,
Table,
create_engine,
)
from snapshottest.module import SnapshotTest
from sqlalchemy import Column, ForeignKey, Integer, MetaData, Sequence, String, Table
from sqlalchemy.engine import Engine
from sqlalchemy_schemadisplay import create_schema_graph


def display_schema(engine: Engine, outfile: str) -> None:
def display_schema(engine: Engine, snapshot: SnapshotTest) -> None:
"""
Display metadata
"""
Expand All @@ -25,13 +17,10 @@ def display_schema(engine: Engine, outfile: str) -> None:
rankdir="LR", # From left to right (instead of top to bottom)
concentrate=False, # Don't try to join the relation lines together
)
graph.write_png(outfile) # write out the file
snapshot.assert_match(graph.to_string())


def test_graph() -> None:
# Second test with duckdb
engine = create_engine("duckdb:///:memory:")

def test_graph(engine: Engine, snapshot: SnapshotTest) -> None:
metadata_obj = MetaData(engine)

user_id_seq: Sequence = Sequence("user_id_seq")
Expand Down Expand Up @@ -70,4 +59,4 @@ def test_graph() -> None:

metadata_obj.create_all(engine)

display_schema(engine, "duckdb/dbschema_2.png")
display_schema(engine, snapshot)

0 comments on commit 3c05999

Please sign in to comment.