mirror of
https://github.com/apache/impala.git
synced 2025-12-19 18:12:08 -05:00
sqlparse-0.1.19 is the last version of sqlparse that supports Python 2.6. Testing: - Ran all end-to-end tests Change-Id: Ide51ef3ac52d25a96b0fa832e29b6535197d23cb Reviewed-on: http://gerrit.cloudera.org:8080/10354 Reviewed-by: David Knupp <dknupp@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
"""Helpers for testing."""
|
|
|
|
import codecs
|
|
import difflib
|
|
import os
|
|
import unittest
|
|
from StringIO import StringIO
|
|
|
|
import sqlparse.utils
|
|
|
|
NL = '\n'
|
|
DIR_PATH = os.path.abspath(os.path.dirname(__file__))
|
|
PARENT_DIR = os.path.dirname(DIR_PATH)
|
|
FILES_DIR = os.path.join(DIR_PATH, 'files')
|
|
|
|
|
|
def load_file(filename, encoding='utf-8'):
|
|
"""Opens filename with encoding and return it's contents."""
|
|
f = codecs.open(os.path.join(FILES_DIR, filename), 'r', encoding)
|
|
data = f.read()
|
|
f.close()
|
|
return data
|
|
|
|
|
|
class TestCaseBase(unittest.TestCase):
|
|
"""Base class for test cases with some additional checks."""
|
|
|
|
# Adopted from Python's tests.
|
|
def ndiffAssertEqual(self, first, second):
|
|
"""Like failUnlessEqual except use ndiff for readable output."""
|
|
if first != second:
|
|
sfirst = unicode(first)
|
|
ssecond = unicode(second)
|
|
# Using the built-in .splitlines() method here will cause incorrect
|
|
# results when splitting statements that have quoted CR/CR+LF
|
|
# characters.
|
|
sfirst = sqlparse.utils.split_unquoted_newlines(sfirst)
|
|
ssecond = sqlparse.utils.split_unquoted_newlines(ssecond)
|
|
diff = difflib.ndiff(sfirst, ssecond)
|
|
fp = StringIO()
|
|
fp.write(NL)
|
|
fp.write(NL.join(diff))
|
|
print fp.getvalue()
|
|
raise self.failureException, fp.getvalue()
|