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.
Convert string escapes to generic SQL, Postgres- or SQLite-specific.
-Add tests for SQLite.
-
Convert extended INSERTs to series of plain INSERTs.
.PHONY: all
-all: nodb postgres clean
+all: nodb postgres sqlite clean
.PHONY: nodb
nodb:
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
--- /dev/null
+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"
[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]
flake8
createdb
dropdb
+ rm
[general]
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