1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
import unittest
from support import GNATCOLL_TestCase, chdir, pathsep, requires_sqlite, \
requires_postgresql, requires_own_sqlite_shell
import os
import sys
class Test(GNATCOLL_TestCase):
@chdir("sql1")
def test_sql(self):
self.runexec(['gnatcoll_db2ada', '-dbmodel', '../descr.txt'])
self.gprbuild()
self.runexec("obj/test_sql", "")
@chdir("sql3")
def test_sql3(self):
self.unlink_if_exists(["test.db", "pkg.ads"])
try:
self.runexec(["sqlite3", "test.db"], input=file("test.sql").read())
self.runexec(["gnatcoll_db2ada", "-dbname=test.db",
"-dbtype=sqlite", "-api=PKG"])
self.gprbuild()
except AssertionError:
# sqlite3 not found
pass
@requires_sqlite
@requires_own_sqlite_shell
@chdir("sql2")
def test_sql2(self):
try:
os.unlink("tmp.db")
except:
pass
# Create a tmp sqlite database
self.runexec(['gnatcoll_db2ada',
'-dbmodel', '../descr.txt',
'-dbname', 'tmp.db',
'-dbtype', 'sqlite',
'-createdb'])
self.runexec([os.environ['SQLITE3_SHELL'], 'tmp.db'],
input="INSERT INTO config VALUES (0,'f');")
# Extra info from it, to check that "max(id)" is correctly
# interpreted. Also check that we know how to read the
# schema from a live sqlite database.
self.runexec(['gnatcoll_db2ada',
'-dbmodel', '../descr.txt',
'-dbname', 'tmp.db',
'-dbtype', 'sqlite',
'-api', 'DB',
'-enum', 'config,id,id,config_enum,',
'-var', 'max_config,config,max(id),,'])
self.diff('db.ads.out', file('db.ads').read())
@requires_sqlite
@chdir("prepared")
def test_prepared(self):
self.unlink_if_exists("test.db")
self.runexec(['gnatcoll_db2ada', '-dbmodel', 'dbschema.txt',
'-api', 'dbschema'])
self.gprbuild()
self.runexec("obj/prepared", "test.out")
@requires_sqlite
@chdir("../../examples/library")
def test_check_doc(self):
"""Run the library example from the doc to detect errors"""
self.runexec(["sh", "./build.sh"])
@requires_postgresql
@chdir("prepared_postgres")
def test_postgres_prepared(self):
self.runexec(['gnatcoll_db2ada',
'-dbmodel', '../prepared/dbschema.txt',
'-api', 'dbschema'])
self.gprbuild()
self.runexec("obj/preparedpsql", "test.out")
@chdir("orm")
def test_orm(self):
os.environ["PATH"] = "." + pathsep + os.getenv("PATH")
self.runexec(["gnatcoll_db2ada", "-orm=Queries",
"-api=ORM_Database", "-dbmodel=descr.txt"])
self.runexec(["gnatcoll_db2ada", "-dot",
"-dbmodel=descr.txt",
"Group1:red:elements,properties"],
"test.out")
self.gprbuild()
@chdir("orm_views")
def test_orm_views(self):
os.environ["PATH"] = "." + pathsep + os.getenv("PATH")
self.runexec(["gnatcoll_db2ada", "-orm=Queries",
"-api=ORM_Database", "-dbmodel=descr.txt"])
self.gprbuild()
@chdir("json")
def test_json(self):
self.runexec(["gnatcoll_db2ada", "-orm=Queries",
"-api=DB", "-dbmodel=descr.txt"])
self.gprbuild()
# requires -lpthread on command line
@requires_sqlite
@chdir("check_sqlite")
def test_check_sqlite(self):
self.gprbuild()
self.runexec("sqlite_test", "test.out")
@requires_sqlite
@requires_postgresql
@chdir("task_cursor")
def test_task_cursor(self):
self.gprbuild()
self.runexec("tc_main", "test.out")
@chdir("bigint")
def test_bigint(self):
self.runexec([
"gnatcoll_db2ada", "-dbmodel=table.txt", "-orm=ORM",
"-api=DB", "-adacreate"])
self.gprbuild("bigint.gpr")
# Test handling of non-automatic transactions
@requires_sqlite
@chdir("NB11-001")
def test_NB11_001(self):
self.gprbuild()
self.runexec("great_expectations", "")
|