Skip to content

Commit

Permalink
Merge pull request #183 from coursera/sb_add_tests
Browse files Browse the repository at this point in the history
Add more tests for 134
  • Loading branch information
sb2nov committed Nov 19, 2015
2 parents 12f413f + 06b3ffc commit 6853049
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
6 changes: 3 additions & 3 deletions dataduct/database/parsers/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from pyparsing import CaselessKeyword
from pyparsing import CharsNotIn
from pyparsing import Literal
from pyparsing import nestedExpr
from pyparsing import OneOrMore
from pyparsing import replaceWith
from pyparsing import WordStart
from pyparsing import ZeroOrMore
from pyparsing import nestedExpr
from pyparsing import replaceWith


def remove_empty_statements(string, seperator=';'):
Expand Down Expand Up @@ -67,7 +67,7 @@ def remove_transactional(string):
result(str): String with begin and commit trimmed
"""
transaction = WordStart() + (
CaselessKeyword('BEGIN')| CaselessKeyword('COMMIT'))
CaselessKeyword('BEGIN') | CaselessKeyword('COMMIT'))

return transaction.suppress().transformString(string)

Expand Down
33 changes: 32 additions & 1 deletion dataduct/database/sql/tests/test_sql_statement.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Tests for the SqlStatement class
"""
from unittest import TestCase
from nose.tools import assert_not_equal
from nose.tools import eq_
from nose.tools import raises
from unittest import TestCase

from ..sql_statement import SqlStatement

Expand All @@ -28,6 +29,36 @@ def test_sanatization():

eq_(SqlStatement(query).sql(), result)

@staticmethod
def test_sanatization_multiline_comment():
"""Sanatization of comments
"""
query = '/* Comment */\n select 1;'
result = 'select 1'

eq_(SqlStatement(query).sql(), result)

@staticmethod
def test_sanatization_multiline_comment_nesting():
"""Sanatization of comments
"""
query = '/* Comment /* nest */ */\n select 1;'
result = 'select 1'

eq_(SqlStatement(query).sql(), result)

@staticmethod
def test_sanatization_multiline_comment_partial_nesting():
"""Sanatization of comments
This is a test to highlight issue #134 which was marked as won't fix
"""
query = '/* Comment /* nest */\n select 1;'
result = 'select 1'
parsed_output = '/* Comment select 1'

eq_(SqlStatement(query).sql(), parsed_output)
assert_not_equal(SqlStatement(query).sql(), result)

@staticmethod
@raises(ValueError)
def test_error():
Expand Down

0 comments on commit 6853049

Please sign in to comment.