# Path: samples/snippets.py
# def enable_autocommit_mode(connection, url):
# def create_table(url, table_id):
# def drop_table(table):
# def get_table_names(url):
# def create_unique_index(table):
# def delete_all_rows(connection, table):
# def delete_row_with_where_clause(connection, table):
# def table_exists(table):
# def fetch_rows(connection, table):
# def fetch_row_with_where_clause(connection, table):
# def fetch_rows_with_limit_offset(connection, table):
# def fetch_rows_with_order_by(connection, table):
# def filter_data_startswith(connection, table):
# def get_table_columns(url, table):
# def get_table_foreign_key(url, table):
# def get_table_indexes(url, table):
# def get_table_primary_key(url, table):
# def insert_row(connection, table):
# def update_row(connection, table):
# 
# Path: samples/conftest.py
# def insert_data(conn, table, data):
#     conn.execute(table.insert(), data)


from samples import snippets
from samples.conftest import insert_data
from sqlalchemy import (
    Column,
    create_engine,
    Index,
    Integer,
    inspect,
    MetaData,
    String,
    Table,
)


def test_exists_table(capsys, table):
    snippets.table_exists(table)

    out, err = capsys.readouterr()
    assert "Table exists" in out


def test_table_fetch_rows(capsys, connection, table):
    insert_data(connection, table, DATA)
    snippets.fetch_rows(connection, table)

    out, err = capsys.readouterr()
    assert "Fetched rows:" in out

    for row in DATA:  # check that all rows were fetched
        assert str(tuple(row.values())) in out


def test_table_fetch_row_with_where_clause(capsys, connection, table):
    insert_data(connection, table, DATA)
    snippets.fetch_row_with_where_clause(connection, table)

    out, err = capsys.readouterr()
    assert str(tuple(DATA[0].values())) in out


def test_table_fetch_rows_with_limit_offset(capsys, connection, table):
    insert_data(connection, table, DATA)

# Path: samples/snippets.py
# def enable_autocommit_mode(connection, url):
# def create_table(url, table_id):
# def drop_table(table):
# def get_table_names(url):
# def create_unique_index(table):
# def delete_all_rows(connection, table):
# def delete_row_with_where_clause(connection, table):
# def table_exists(table):
# def fetch_rows(connection, table):
# def fetch_row_with_where_clause(connection, table):
# def fetch_rows_with_limit_offset(connection, table):
# def fetch_rows_with_order_by(connection, table):
# def filter_data_startswith(connection, table):
# def get_table_columns(url, table):
# def get_table_foreign_key(url, table):
# def get_table_indexes(url, table):
# def get_table_primary_key(url, table):
# def insert_row(connection, table):
# def update_row(connection, table):
# 
# Path: samples/conftest.py
# def insert_data(conn, table, data):
#     conn.execute(table.insert(), data)


# Path: samples/snippets_test.py
from samples import snippets
from samples.conftest import insert_data
from sqlalchemy import (
    Column,
    create_engine,
    Index,
    Integer,
    inspect,
    MetaData,
    String,
    Table,
)



def test_exists_table(capsys, table):
    snippets.table_exists(table)

    out, err = capsys.readouterr()
    assert "Table exists" in out


def test_table_fetch_rows(capsys, connection, table):
    insert_data(connection, table, DATA)
    snippets.fetch_rows(connection, table)

    out, err = capsys.readouterr()
    assert "Fetched rows:" in out

    for row in DATA:  # check that all rows were fetched
        assert str(tuple(row.values())) in out


def test_table_fetch_row_with_where_clause(capsys, connection, table):
    insert_data(connection, table, DATA)
    snippets.fetch_row_with_where_clause(connection, table)

    out, err = capsys.readouterr()
    assert str(tuple(DATA[0].values())) in out


def test_table_fetch_rows_with_limit_offset(capsys, connection, table):
    insert_data(connection, table, DATA)

    snippets.fetch_rows_with_limit_offset(connection, table)