Exemplo n.º 1
0
def test_combined_marker_and_statement_indices(sn_delayed):
    """Test that the combined marker and statement order is correct."""
    from snowmobile.core import Statement
    from snowmobile.core.cfg import Marker

    script = snowmobile.Script(path=FILES["markers_standard.sql"],
                               sn=sn_delayed)
    script_contents_expected: List[Tuple[int, Any[Marker, Statement], str]] = [
        # (index, BaseClass, 'tag.nm')
        (1, Marker, "markers_standard.sql"),
        (2, Statement, "create table~sample_table"),
        (3, Marker, "marker2"),
        (4, Marker, "marker3"),
        (5, Statement, "create table~sample_table2"),
        (6, Marker, "trailing_marker"),
    ]

    script_contents_under_test = script.contents(by_index=True, markers=True)

    for expected, (i, c) in zip(script_contents_expected,
                                script_contents_under_test.items()):
        expected_index, expected_base_class, expected_name = expected
        assert all([
            expected_index == i,
            expected_name == c.nm,
            isinstance(c, expected_base_class),
        ])
Exemplo n.º 2
0
def test_marker_number_standard(sn_delayed):
    """Test that 4 distinct markers are identified in `markers_standard.sql`"""
    # given
    script = snowmobile.Script(path=FILES["markers_standard.sql"],
                               sn=sn_delayed)
    # then
    assert len(script.markers) == 4
Exemplo n.º 3
0
def test_marker_number_duplicates(sn_delayed):
    """Test that two distinct markers were identified amongst 3 total in
    `markers_duplicates.sql`."""
    # given
    script = snowmobile.Script(path=FILES["markers_duplicates.sql"],
                               sn=sn_delayed)
    # then
    assert len(script.markers) == 2
Exemplo n.º 4
0
"""
Inspect the parsing of a sql file containing two bare statements.
../docs/snippets/script/a-few-statements.py
"""

# Setup -----------------------------------------------------------------------
from pathlib import Path
paths = {p.name: p for p in Path.cwd().glob('**/*.sql')}
path = paths['a-few-statements.sql']

import snowmobile

sn = snowmobile.connect(delay=True)

# Example ---------------------------------------------------------------------

script = snowmobile.Script(path=path, sn=sn)
script.dtl()
"""
>>>
a-few-statements.sql
====================
1: Statement('create table~s1')
2: Statement('select data~s2')
"""
Exemplo n.º 5
0
def test_script_depth(sn_delayed):
    """Tests the standard depth of a script."""
    # given
    script = snowmobile.Script(path=FILES["generic_script.sql"], sn=sn_delayed)
    # then
    assert script.depth == 7
Exemplo n.º 6
0
"""
Demonstrate core functionality of snowmobile.SQL object.
../docs/snippets/sql_working_example.py
"""
import snowmobile

from pathlib import Path

sn = snowmobile.connect()

path = Path.cwd() / "docs/snippets/dummy_table.sql"
_ = snowmobile.Script(path=path, sn=sn).run(1)

# -- 1.1 ----------------------------------------------------------------------

sample1 = sn.sql.select("dummy_table", n=5)

print(type(sample1))  #> <class 'pandas.core.frame.DataFrame'>
print(sample1.shape)  #> (5, 3)

sample1_run_false = sn.sql.select("dummy_table", n=5, run=False)

print(type(sample1_run_false))  #> <class 'str'>
print(sample1_run_false)

# -- 1.2 ----------------------------------------------------------------------

sn.sql.auto_run = False

sample2 = sn.sql.select("dummy_table", n=5)
Exemplo n.º 7
0
"""
This file exists for the purpose of exporting DDL.sql to a markdown file.

The relative 'ddl_location' path below assumes that this script is stored
within 'snowmobile/core/pkg_data/.snowmobile' and that `DDL.sql` is in `pkg_data`.
"""
from pathlib import Path

import snowmobile

# location of the DDL.sql file
ddl_location = Path(__file__).absolute().parent.parent / "DDL.sql"

# connector object, connection omitted
sn = snowmobile.connect(delay=True, config_file_nm="snowmobile_testing.toml")

# script object from DDL.sql
script = snowmobile.Script(path=ddl_location, sn=sn)

# accessing as a markup and exporting markdown file only
script.doc().save()
Exemplo n.º 8
0
"""
Inspect the parsing of a sql file.
../docs/snippets/script/intro.py
"""

# Setup -----------------------------------------------------------------------
from pathlib import Path
paths = {
    p.name: p
    for p in (Path.cwd() / 'docs' / 'snippets').glob('**/*.sql')
}
path = paths['intro.sql']

# Example ---------------------------------------------------------------------

import snowmobile

script = snowmobile.Script(path=path)
markup = script.doc()

print(script)  #> snowmobile.Script('intro.sql')
print(markup)  #> snowmobile.core.Markup('intro.sql')

markup.save()
"""
>>>
    ../intro/intro.md
    ../intro/intro.sql
"""
Exemplo n.º 9
0
def get_testing_script(nm: str, results_limit: int = 1):
    path = Path(__file__).absolute().parent.parent / nm
    sn = snowmobile.connect(delay=True,
                            config_file_nm="snowmobile_testing.toml")
    sn.cfg.script.markup.result_limit = results_limit
    return snowmobile.Script(path=path, sn=sn)