This repository has been archived by the owner on Sep 3, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
102 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
*.pyc | ||
docs/_build | ||
venv | ||
.eggs | ||
.cache | ||
.tox | ||
.python-version | ||
anosql.egg-info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from __future__ import absolute_import | ||
from .core import load_queries | ||
from .core import load_queries_from_string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tox | ||
pytest |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import pytest | ||
|
||
import anosql | ||
|
||
|
||
@pytest.fixture | ||
def sqlite(request): | ||
import sqlite3 | ||
sqlconnection = sqlite3.connect(':memory:') | ||
|
||
def fin(): | ||
"teardown" | ||
print("teardown") | ||
sqlconnection.close() | ||
|
||
request.addfinalizer(fin) | ||
|
||
return sqlconnection | ||
|
||
|
||
def test_simple_query(sqlite): | ||
_test_create_insert = ("-- name: create-some-table\n" | ||
"-- testing insertion\n" | ||
"CREATE TABLE foo (a, b, c);\n\n" | ||
"-- name: insert-some-value\n" | ||
"INSERT INTO foo (a, b, c) VALUES (1, 2, 3);\n") | ||
|
||
q = anosql.load_queries_from_string("sqlite", _test_create_insert) | ||
q.create_some_table(sqlite) | ||
q.insert_some_value(sqlite) | ||
|
||
|
||
def test_auto_insert_query(sqlite): | ||
_test_create_insert = ("-- name: create-some-table\n" | ||
"-- testing insertion\n" | ||
"CREATE TABLE foo (a, b, c);\n\n" | ||
"-- name: insert-some-value<!\n" | ||
"INSERT INTO foo (a, b, c) VALUES (1, 2, 3);\n") | ||
|
||
q = anosql.load_queries_from_string("sqlite", _test_create_insert) | ||
q.create_some_table(sqlite) | ||
assert q.insert_some_value_auto(sqlite) == 1 | ||
assert q.insert_some_value_auto(sqlite) == 2 | ||
assert q.insert_some_value_auto(sqlite) == 3 | ||
|
||
|
||
def test_parametrized_insert(sqlite): | ||
_test_create_insert = ("-- name: create-some-table\n" | ||
"-- testing insertion\n" | ||
"CREATE TABLE foo (a, b, c);\n\n" | ||
"-- name: insert-some-value\n" | ||
"INSERT INTO foo (a, b, c) VALUES (%s, %s, %s);\n\n" | ||
"-- name: get-all-values\n" | ||
"SELECT * FROM foo;\n") | ||
|
||
q = anosql.load_queries_from_string("sqlite", _test_create_insert) | ||
q.create_some_table(sqlite) | ||
q.insert_some_value(sqlite, 10, 11, 12) | ||
assert q.get_all_values(sqlite) == [(10, 11, 12)] | ||
|
||
|
||
def test_parametrized_insert_named(sqlite): | ||
_test_create_insert = ("-- name: create-some-table\n" | ||
"-- testing insertion\n" | ||
"CREATE TABLE foo (a, b, c);\n\n" | ||
"-- name: insert-some-value\n" | ||
"INSERT INTO foo (a, b, c) VALUES (:a, :b, :c);\n\n" | ||
"-- name: get-all-values\n" | ||
"SELECT * FROM foo;\n") | ||
|
||
q = anosql.load_queries_from_string("sqlite", _test_create_insert) | ||
q.create_some_table(sqlite) | ||
q.insert_some_value(sqlite, c=12, b=11, a=10) | ||
assert q.get_all_values(sqlite) == [(10, 11, 12)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[tox] | ||
envlist = py27, py35 | ||
|
||
[testenv] | ||
deps = -rtest_requirements.txt | ||
commands = py.test tests |