コード例 #1
0
 def _func(dbconn, cursor):
     lib = t.Library.from_file(t.yaml("conn-queries"))
     conn = t.Connection(lib, dbconn)
     try:
         func(conn)
     finally:
         conn.close()
コード例 #2
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_defaults():
    lib = t.Library.from_file(t.yaml("defaults-set"))
    s = lib.get_query("test")
    t.eq(s.name, "test")
    t.eq(s.desc, None)
    t.eq(s.type, "query")
    t.eq(s.dbs.keys(), [None])
    t.eq(s.dbs[None].sql, "select * from actors;")
コード例 #3
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_basic():
    l = t.Library.from_file(t.yaml("basic"))
    s = l.get_query("test")
    t.eq(s.name, "test")
    t.eq(s.dbs[None].sql, "select 1 as a")
    t.eq(s.dbs["pgsql"].sql, 'select 1 as "a"')
    u = l.get_update("test2")
    t.eq(u.dbs[None].sql, "create table foo(a int);")
コード例 #4
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_merge():
    lib = t.Library.from_file(t.yaml("merge"))
    s = lib.get_query("test")
    t.eq(sorted(s.dbs.keys()), [None, "pgsql"])
    t.eq(s.dbs[None].sql, "select * from scenes;")
    t.eq(s.dbs["pgsql"].sql, "select * from scenes2;")
コード例 #5
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_multiple_dbs():
    lib = t.Library.from_file(t.yaml("multiple-dbs"))
    s = lib.get_query("yay")
    t.eq(sorted(s.dbs.keys()), ["pgsql", "sqlite"])
    t.eq(s.dbs["pgsql"], s.dbs["sqlite"])
コード例 #6
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_invalid_type():
    t.raises(ValueError, t.Library.from_file, t.yaml("error-type"))
コード例 #7
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_no_sql():
    try:
        t.Library.from_file(t.yaml("error-no-sql"))
    except t.IncompleteStatementError, inst:
        t.eq(inst.name, "sql")
コード例 #8
0
ファイル: 006-connect-test.py プロジェクト: pombredanne/sheba
def test_file_name():
    args = tuple([":memory:"])
    conn = t.sheba.connect(t.yaml("conn-queries"), driver='sqlite3', args=args)
    t.eq(isinstance(conn, t.Connection), True)
コード例 #9
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_no_queries_after_conn():
    fname = t.yaml("error-no-queries-after-conn")
    t.raises(ValueError, t.Library.from_file, fname)
コード例 #10
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_no_conn_info():
    lib = t.Library.from_file(t.yaml("conn-queries"))
    t.raises(KeyError, lib.get_conn_info, "razzle-dazzle")
コード例 #11
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_repeated_name():
    fname = t.yaml("error-repeated-conn-name")
    t.raises(ValueError, t.Library.from_file, fname)
コード例 #12
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_trailing_doc():
    # Assert doesn't raise
    t.Library.from_file(t.yaml("error-last-doc-empty"))
コード例 #13
0
ファイル: 006-connect-test.py プロジェクト: pombredanne/sheba
def test_alternate_conn_info():
    conn = t.sheba.connect(t.yaml("with-conn-info"), name="prod")
    t.eq(isinstance(conn, t.Connection), True)
コード例 #14
0
ファイル: 006-connect-test.py プロジェクト: pombredanne/sheba
def test_kwargs():
    kw = {"database": ":memory:"}
    conn = t.sheba.connect(t.yaml("conn-queries"), driver='sqlite3', kwargs=kw)
    t.eq(isinstance(conn, t.Connection), True)
コード例 #15
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_merge_desc():
    lib = t.Library.from_file(t.yaml("merge-desc"))
    t.eq(lib.get_query("test").desc, "Some info")
    t.eq(lib.get_query("test2").desc, "Ignored second")
コード例 #16
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_merge_errors():
    t.raises(ValueError, t.Library.from_file, t.yaml("merge-error"))
コード例 #17
0
ファイル: 003-library-test.py プロジェクト: pombredanne/sheba
def test_no_queries():
    fname = t.yaml("error-no-queries")
    t.raises(ValueError, t.Library.from_file, fname)