From: Oleg Broytman Date: Sat, 17 Sep 2016 15:56:35 +0000 (+0300) Subject: Remove classes from tests X-Git-Tag: 0.0.6~20 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=19e5f010328b314a5ead4468ba11b1fcb27fe42f;p=sqlconvert.git Remove classes from tests Remove leftovers from unittest, completely switch to pytest. --- diff --git a/tests/test_stgrouper.py b/tests/test_stgrouper.py index 7bdca56..994ef4e 100644 --- a/tests/test_stgrouper.py +++ b/tests/test_stgrouper.py @@ -4,21 +4,21 @@ from sqlconvert.print_tokens import tlist2str from sqlconvert.process_tokens import StatementGrouper -class TestStGrouper(object): - def test_incomplete(self): - grouper = StatementGrouper() - grouper.process_line("select * from `T`") - assert not grouper.statements - assert len(grouper.statements) == 0 - raises(ValueError, grouper.close) +def test_incomplete(): + grouper = StatementGrouper() + grouper.process_line("select * from `T`") + 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;") - assert grouper.statements - assert len(grouper.statements) == 1 - for statement in grouper.get_statements(): - query = tlist2str(statement) - assert query == 'SELECT * FROM T;' - assert len(grouper.statements) == 0 - assert grouper.close() is None + +def test_statements(): + grouper = StatementGrouper() + grouper.process_line("select * from T;") + assert grouper.statements + assert len(grouper.statements) == 1 + for statement in grouper.get_statements(): + query = tlist2str(statement) + assert query == 'SELECT * FROM T;' + assert len(grouper.statements) == 0 + assert grouper.close() is None diff --git a/tests/test_tokens.py b/tests/test_tokens.py index 8201e74..ffe5814 100644 --- a/tests/test_tokens.py +++ b/tests/test_tokens.py @@ -8,44 +8,49 @@ from sqlconvert.process_mysql import remove_directive_tokens, \ process_statement -class TestTokens(object): - def test_encoding(self): - parsed = parse("insert into test (1, 'тест')", 'utf-8')[0] - query = tlist2str(parsed).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) - 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) - assert query == u'SELECT * FROM /* test */ `T`' - - def test_directive_statement(self): - parsed = parse("/*! test */ test ;")[0] - assert not is_directive_statement(parsed) - parsed = parse("/*! test */ ;")[0] - assert is_directive_statement(parsed) - - def test_requote(self): - parsed = parse("select * from `T`")[0] - requote_names(parsed) - query = tlist2str(parsed) - assert query == u'SELECT * FROM "T"' - - def test_string(self): - parsed = parse("insert into test values ('\"test\\\"')")[0] - unescape_strings(parsed) - query = tlist2str(parsed) - 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) - assert query == u'SELECT * FROM /* test */ "T"' +def test_encoding(): + parsed = parse("insert into test (1, 'тест')", 'utf-8')[0] + query = tlist2str(parsed).encode('utf-8') + assert query == \ + u"INSERT INTO test (1, 'тест')".encode('utf-8') + + +def test_unicode(): + parsed = parse(u"insert into test (1, 'тест')")[0] + query = tlist2str(parsed) + assert query, u"INSERT INTO test (1 == 'тест')" + + +def test_directive(): + parsed = parse("select /*! test */ * from /* test */ `T`")[0] + remove_directive_tokens(parsed) + query = tlist2str(parsed) + assert query == u'SELECT * FROM /* test */ `T`' + + +def test_directive_statement(): + parsed = parse("/*! test */ test ;")[0] + assert not is_directive_statement(parsed) + parsed = parse("/*! test */ ;")[0] + assert is_directive_statement(parsed) + + +def test_requote(): + parsed = parse("select * from `T`")[0] + requote_names(parsed) + query = tlist2str(parsed) + assert query == u'SELECT * FROM "T"' + + +def test_string(): + parsed = parse("insert into test values ('\"test\\\"')")[0] + unescape_strings(parsed) + query = tlist2str(parsed) + assert query == u"INSERT INTO test VALUES ('\"test\"')" + + +def test_process(): + parsed = parse("select /*! test */ * from /* test */ `T`")[0] + process_statement(parsed) + query = tlist2str(parsed) + assert query == u'SELECT * FROM /* test */ "T"'