Use SQLObject for testing.
Rename remove_directives -> remove_directive_tokens.
- Unescape strings.
+ Unescape strings. Add a test for Postgres.
- Use pytest, coverage and tox for testing.
+ Use pytest, coverage, tox and SQLObject for testing.
Version 0.0.5 (2016-09-07)
Convert string escapes to generic SQL, Postgres- or SQLite-specific.
-Add tests for Postgres and SQLite.
+Add tests for SQLite.
Convert extended INSERTs to series of plain INSERTs.
pytest
pytest-cov
tox >= 1.8
+SQLObject>=2.2.1; python_version >= '2.6' and python_version < '3.0'
+SQLObject>=3.0.0; python_version >= '3.4'
tag_svn_revision = 0
[flake8]
-exclude = .git,docs/conf.py,ez_setup.py
+exclude = .git,docs/conf.py,tests/conftest.py,ez_setup.py
.PHONY: all
-all:
- python `which pytest`
+all: nodb postgres clean
+
+.PHONY: nodb
+nodb:
+ PYTHONPATH=.. python -m pytest
+
+.PHONY: postgres
+postgres:
+ createdb test
+ PYTHONPATH=.. python -m pytest -D postgres:///test
+ dropdb test
+
+.PHONY: clean
+clean:
+ rm -f *.tmp
--- /dev/null
+# noqa: imported for pytest
+
+from sqlobject.conftest import \
+ pytest_addoption, pytest_configure, setup_tests
--- /dev/null
+from sqlparse import parse
+from sqlobject.tests.dbtest import getConnection
+import py.test
+
+from sqlconvert.print_tokens import tlist2str
+from sqlconvert.process_mysql import unescape_strings
+
+
+create_postgres_test_table = """
+CREATE TABLE test (
+ id serial PRIMARY KEY,
+ test_str VARCHAR(255) NOT NULL
+);
+"""
+
+
+def test_mysql2postgres_string():
+ connection = getConnection()
+ if connection.dbName != "postgres":
+ py.test.skip("This test requires PostgreSQL")
+ connection.query(create_postgres_test_table)
+ parsed = parse("insert into test (id, test_str) "
+ "values (1, '\"te\\'st\\\"')")[0]
+ unescape_strings(parsed)
+ query = tlist2str(parsed)
+ assert query == u"INSERT INTO test (id, test_str) VALUES (1, '\"te''st\"')"
+ connection.query(query)
+ test_str = connection.queryOne("SELECT test_str FROM test WHERE id=1")[0]
+ assert test_str == u"\"te'st\""
[tox]
minversion = 1.8
-envlist = {py26,py27,py34},{py27,py34}-flake8
+envlist = {py26,py27,py34},{py26,py27,py34}-postgres,{py27,py34}-flake8
# Base test environment settings
[testenv]
pytest
pytest-cov
py26: argparse
+ py26,py27: SQLObject>=2.2.1
+ py34: SQLObject>=3.0.0
py26,py27: m_lib>=2.0
py34: m_lib>=3.0
+ postgres: psycopg2
sitepackages = True
# Don't fail or warn on uninstalled commands
whitelist_externals =
flake8
+ createdb
+ dropdb
[general]
commands =
python -m pytest --cov=sqlconvert
+ rm -f *.tmp
[testenv:py26]
commands = {[general]commands}
[testenv:py34]
commands = {[general]commands}
+# PostgreSQL test environments
+[postgresql]
+commands =
+ createdb test
+ python -m pytest -D postgres:///test
+ dropdb test
+ rm -f *.tmp
+
+[testenv:py26-postgres]
+commands = {[postgresql]commands}
+
+[testenv:py27-postgres]
+commands = {[postgresql]commands}
+
+[testenv:py34-postgres]
+commands = {[postgresql]commands}
+
[testenv:py27-flake8]
deps =
flake8