Unescape strings.
+ Use pytest for testing.
+
Version 0.0.5 (2016-09-07)
Remove /*! directives */; and newlines after them.
--- /dev/null
+-r requirements.txt
+
+pytest
.PHONY: all
all:
- ./run_all.py
+ python `which pytest`
+++ /dev/null
-
-import unittest
-
-__all__ = ['TestCase', 'main']
-
-
-class TestCase(unittest.TestCase):
- def setUp(self):
- pass
-
- def tearDown(self):
- pass
-
-
-def main():
- try:
- unittest.main(testRunner=unittest.TextTestRunner())
- except SystemExit as msg:
- result = msg.args[0]
- else:
- result = 0
- raise SystemExit(result)
+++ /dev/null
-#! /usr/bin/env python
-from __future__ import print_function
-
-
-import os
-import sys
-import subprocess
-
-
-def isexecutable(filename):
- infile = open(filename, 'r')
- magic = infile.read(2)
- infile.close()
- return magic == "#!"
-
-
-def collect_tests():
- tests = []
- for dirpath, dirs, files in os.walk("tests"):
- tests.extend(
- [os.path.join(dirpath, filename) for filename in files
- if filename.startswith("test") and filename.endswith(".py")
- ])
- return [test[:-3].replace(os.sep, '.') for test in tests
- if isexecutable(test)]
-
-
-def main():
- os.chdir(os.path.join(os.path.dirname(sys.argv[0]), os.pardir))
- tests = collect_tests()
-
- os.environ["PYTHONPATH"] = os.curdir
-
- for test in sorted(tests):
- print(test)
- subprocess.call((sys.executable, '-m', test))
-
-if __name__ == '__main__':
- main()
-#! /usr/bin/env python
-
-
-import unittest
+from pytest import raises
from sqlconvert.print_tokens import tlist2str
from sqlconvert.process_mysql import requote_names
from sqlconvert.process_tokens import StatementGrouper
-from tests import main
-class TestStGrouper(unittest.TestCase):
+class TestStGrouper(object):
def test_incomplete(self):
grouper = StatementGrouper()
grouper.process_line("select * from `T`")
- self.assertFalse(grouper.statements)
- self.assertEqual(len(grouper.statements), 0)
- self.assertRaises(ValueError, grouper.close)
+ assert not grouper.statements
+ assert len(grouper.statements) == 0
+ raises(ValueError, grouper.close)
def test_statements(self):
grouper = StatementGrouper()
grouper.process_line("select * from `T`;")
- self.assertTrue(grouper.statements)
- self.assertEqual(len(grouper.statements), 1)
+ assert grouper.statements
+ assert len(grouper.statements) == 1
for statement in grouper.get_statements():
requote_names(statement)
query = tlist2str(statement)
- self.assertEqual(query, 'SELECT * FROM "T";')
- self.assertEqual(len(grouper.statements), 0)
- self.assertEqual(grouper.close(), None)
-
-if __name__ == "__main__":
- main()
+ assert query == 'SELECT * FROM "T";'
+ assert len(grouper.statements) == 0
+ assert grouper.close() is None
-#! /usr/bin/env python
# -*- coding: utf-8 -*-
-import unittest
from sqlparse import parse
from sqlconvert.print_tokens import tlist2str
from sqlconvert.process_mysql import remove_directive_tokens, \
is_directive_statement, requote_names, unescape_strings, \
process_statement
-from tests import main
-class TestTokens(unittest.TestCase):
+class TestTokens(object):
def test_encoding(self):
parsed = parse("insert into test (1, 'тест')", 'utf-8')[0]
query = tlist2str(parsed).encode('utf-8')
- self.assertEqual(query,
- u"INSERT INTO test (1, 'тест')".encode('utf-8'))
+ assert query == \
+ u"INSERT INTO test (1, 'тест')".encode('utf-8')
def test_unicode(self):
parsed = parse(u"insert into test (1, 'тест')")[0]
query = tlist2str(parsed)
- self.assertEqual(query, u"INSERT INTO test (1, 'тест')")
+ assert query, u"INSERT INTO test (1 == 'тест')"
def test_directive(self):
parsed = parse("select /*! test */ * from /* test */ `T`")[0]
remove_directive_tokens(parsed)
query = tlist2str(parsed)
- self.assertEqual(query, u'SELECT * FROM /* test */ `T`')
+ assert query == u'SELECT * FROM /* test */ `T`'
def test_directive_statement(self):
parsed = parse("/*! test */ test ;")[0]
- self.assertFalse(is_directive_statement(parsed))
+ assert not is_directive_statement(parsed)
parsed = parse("/*! test */ ;")[0]
- self.assertTrue(is_directive_statement(parsed))
+ assert is_directive_statement(parsed)
def test_requote(self):
parsed = parse("select * from `T`")[0]
requote_names(parsed)
query = tlist2str(parsed)
- self.assertEqual(query, u'SELECT * FROM "T"')
+ assert query == u'SELECT * FROM "T"'
def test_string(self):
parsed = parse("insert into test values ('\"test\\\"')")[0]
unescape_strings(parsed)
query = tlist2str(parsed)
- self.assertEqual(query, u"INSERT INTO test VALUES ('\"test\"')")
+ assert query == u"INSERT INTO test VALUES ('\"test\"')"
def test_process(self):
parsed = parse("select /*! test */ * from /* test */ `T`")[0]
process_statement(parsed)
query = tlist2str(parsed)
- self.assertEqual(query, u'SELECT * FROM /* test */ "T"')
-
-
-if __name__ == "__main__":
- main()
+ assert query == u'SELECT * FROM /* test */ "T"'