2 # -*- coding: utf-8 -*-
5 from sqlparse import parse
7 from sqlconvert.print_tokens import tlist2str
8 from sqlconvert.process_mysql import remove_directive_tokens, requote_names, \
9 is_directive_statement, process_statement
10 from tests import main
13 class TestTokens(unittest.TestCase):
14 def test_encoding(self):
15 parsed = parse("insert into test (1, 'тест')", 'utf-8')[0]
16 query = tlist2str(parsed).encode('utf-8')
17 self.assertEqual(query,
18 u"INSERT INTO test (1, 'тест')".encode('utf-8'))
20 def test_unicode(self):
21 parsed = parse(u"insert into test (1, 'тест')")[0]
22 query = tlist2str(parsed)
23 self.assertEqual(query, u"INSERT INTO test (1, 'тест')")
25 def test_requote(self):
26 parsed = parse("select * from `T`")[0]
28 query = tlist2str(parsed)
29 self.assertEqual(query, 'SELECT * FROM "T"')
31 def test_directive(self):
32 parsed = parse("select /*! test */ * from /* test */ `T`")[0]
33 remove_directive_tokens(parsed)
34 query = tlist2str(parsed)
35 self.assertEqual(query, 'SELECT * FROM /* test */ `T`')
37 def test_directive_statement(self):
38 parsed = parse("/*! test */ test ;")[0]
39 self.assertFalse(is_directive_statement(parsed))
40 parsed = parse("/*! test */ ;")[0]
41 self.assertTrue(is_directive_statement(parsed))
43 def test_process(self):
44 parsed = parse("select /*! test */ * from /* test */ `T`")[0]
45 process_statement(parsed)
46 query = tlist2str(parsed)
47 self.assertEqual(query, 'SELECT * FROM /* test */ "T"')
50 if __name__ == "__main__":