]> git.phdru.name Git - sqlconvert.git/commitdiff
Add tests for SQLite
authorOleg Broytman <phd@phdru.name>
Sun, 25 Sep 2016 15:25:49 +0000 (18:25 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 25 Sep 2016 15:33:27 +0000 (18:33 +0300)
ChangeLog
TODO
tests/Makefile
tests/test_mysql2sqlite.py [new file with mode: 0644]
tox.ini

index cd3988832ded3b5886894147e9d1cd58e4c44ab7..5193324331726acc48ef82bb5a5b52f9c2371861 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,8 @@ Version 0.0.6 (2016-09-??)
 
    Use pytest, coverage and tox for testing.
 
+   Add tests for Postgres and SQLite.
+
 Version 0.0.5 (2016-09-07)
 
    Remove /*! directives */; and newlines after them.
diff --git a/TODO b/TODO
index 347811bcb2d5d001920f1488bdb1800087863ddc..26baf8483a8282730500a3584a44955f4c288b85 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,4 @@
 Convert string escapes to generic SQL, Postgres- or SQLite-specific.
 
-Add tests for SQLite.
-
 
 Convert extended INSERTs to series of plain INSERTs.
index 6e7d1d837dfb435d3bc8b287a5c577d5b11cd48a..444794bf8c284281e5c7b89b87c3917f8b7a09b8 100644 (file)
@@ -1,6 +1,6 @@
 
 .PHONY: all
-all: nodb postgres clean
+all: nodb postgres sqlite clean
 
 .PHONY: nodb
 nodb:
@@ -12,6 +12,11 @@ postgres:
        PYTHONPATH=.. python -m  pytest -D postgres:///test
        dropdb test
 
+.PHONY: sqlite
+sqlite:
+       PYTHONPATH=.. python -m  pytest -D sqlite:///tmp/test.sqdb
+       rm -f /tmp/test.sqdb
+
 .PHONY: clean
 clean:
        rm -f *.tmp
diff --git a/tests/test_mysql2sqlite.py b/tests/test_mysql2sqlite.py
new file mode 100644 (file)
index 0000000..b5ae10f
--- /dev/null
@@ -0,0 +1,32 @@
+from sqlparse import parse
+from sqlobject.tests.dbtest import getConnection
+import pytest
+
+from sqlconvert.print_tokens import tlist2str
+from sqlconvert.process_mysql import unescape_strings
+from sqlconvert.process_tokens import escape_strings
+
+connection = getConnection()
+pytestmark = pytest.mark.skipif(connection.dbName != "sqlite",
+                                reason="This test requires SQLite")
+
+create_sqlite_test_table = """
+CREATE TABLE test (
+    id INTEGER PRIMARY KEY AUTOINCREMENT,
+    test_str VARCHAR(255) NOT NULL
+);
+"""
+
+
+def test_mysql2sqlite_string():
+    connection.query(create_sqlite_test_table)
+    parsed = parse("insert into test (id, test_str) values "
+                   "(1, '\"te\\'st\\\"\\n')")[0]
+    unescape_strings(parsed)
+    escape_strings(parsed, 'sqlite')
+    query = tlist2str(parsed)
+    assert query == u"INSERT INTO test (id, test_str) VALUES " \
+                    u"(1, '\"te''st\"\n')"
+    connection.query(query)
+    test_str = connection.queryOne("SELECT test_str FROM test WHERE id=1")[0]
+    assert test_str == u"\"te'st\"\n"
diff --git a/tox.ini b/tox.ini
index 5941ef82a3a6869e2e2b3ee1759e47c116fc97d4..e634cdfe660e584196d0a080a0926823152d3419 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -1,6 +1,6 @@
 [tox]
 minversion = 1.8
-envlist = {py26,py27,py34},{py26,py27,py34}-postgres,{py27,py34}-flake8
+envlist = {py26,py27,py34},{py26,py27,py34}-{postgres,sqlite},{py27,py34}-flake8
 
 # Base test environment settings
 [testenv]
@@ -20,6 +20,7 @@ whitelist_externals =
     flake8
     createdb
     dropdb
+    rm
 
 [general]
 commands =
@@ -50,6 +51,22 @@ commands = {[postgresql]commands}
 [testenv:py34-postgres]
 commands = {[postgresql]commands}
 
+# SQLite test environments
+[sqlite]
+commands =
+    python -m pytest -D sqlite:///tmp/test.sqdb
+    rm -f /tmp/test.sqdb
+
+[testenv:py26-sqlite]
+commands = {[sqlite]commands}
+
+[testenv:py27-sqlite]
+commands = {[sqlite]commands}
+
+[testenv:py34-sqlite]
+commands = {[sqlite]commands}
+
+# flake8
 [testenv:py27-flake8]
 deps =
     flake8