add some smoke tests
authorKali Kaneko (leap communications) <kali@leap.se>
Thu, 13 Apr 2017 18:39:31 +0000 (20:39 +0200)
committerKali Kaneko (leap communications) <kali@leap.se>
Thu, 13 Apr 2017 18:51:16 +0000 (20:51 +0200)
Makefile
tests/blobs.py [new file with mode: 0644]
tests/flags.py [new file with mode: 0644]
tests/run.sh [new file with mode: 0755]
tests/test.py [new file with mode: 0644]

index 9473a1c..c72e005 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,5 +10,10 @@ get_amalgamation:
 upload:
        python setup.py sdist upload -r pypi 
 
+test:
+       rm -f tests/*.db
+       cd tests && ./run.sh
+       rm -f tests/*.db
+
 clean:
        rm -rf build dist
diff --git a/tests/blobs.py b/tests/blobs.py
new file mode 100644 (file)
index 0000000..a10cac0
--- /dev/null
@@ -0,0 +1,13 @@
+from pysqlcipher import dbapi2 as sqlite3
+con = sqlite3.connect("blobs.db")
+# creating the table
+con.execute("create table test(id integer primary key, blob_col blob)")
+con.execute("insert into test(blob_col) values (zeroblob(10))")
+# opening blob handle
+blob = con.blob("test", "blob_col", 1, 1)
+blob.write("a" * 5)
+blob.write("b" * 5)
+blob.seek(0)
+assert blob.read() == "aaaaabbbbb"
+blob.close()
+
diff --git a/tests/flags.py b/tests/flags.py
new file mode 100644 (file)
index 0000000..e6e7790
--- /dev/null
@@ -0,0 +1,12 @@
+from pysqlcipher import dbapi2
+
+c = dbapi2.connect(":memory:")
+cur = c.execute("pragma compile_options")
+
+lines = cur.fetchall()
+flags = [l[0] for l in lines]
+for flag in flags:
+    print flag
+assert "HAVE_USLEEP" in flags
+assert "ENABLE_LOAD_EXTENSION" in flags
+
diff --git a/tests/run.sh b/tests/run.sh
new file mode 100755 (executable)
index 0000000..a8769bf
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+set -e
+python test.py
+python blobs.py
+python flags.py
+echo "[+] tests ok, no smoke."
diff --git a/tests/test.py b/tests/test.py
new file mode 100644 (file)
index 0000000..559946a
--- /dev/null
@@ -0,0 +1,8 @@
+from pysqlcipher import dbapi2 as sqlite
+conn = sqlite.connect('test.db')
+c = conn.cursor()
+c.execute("PRAGMA key='testaverylongpasswordisthisokey'")
+c.execute("create table stocks (date text, trans text, symbol text, qty real, price real)")
+c.execute("""insert into stocks values ('2006-01-05','BUY','RHAT',100,35.14)""")
+conn.commit()
+c.close()