summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2020-05-24 06:44:09 -0700
committerJon Dufresne <jon.dufresne@gmail.com>2020-08-31 17:27:38 -0700
commit3e3892f939031d58d98275ce8a237689225d299a (patch)
tree93b64d7fd8aa1cc19335db11c915dfc59376eae9 /tests
parent28a2acdd9b307c95d2111f1f831b1a5afc634691 (diff)
downloadsqlparse-3e3892f939031d58d98275ce8a237689225d299a.tar.gz
Remove support for end-of-life Pythons
Python 2.7 and 3.4 are end-of-life. They are no longer receiving bug fixes, including for security issues. Python 2.7 went EOL on 2020-01-01 and 3.4 on 2019-03-18. For additional details on support Python versions, see: Supported: https://devguide.python.org/#status-of-python-branches EOL: https://devguide.python.org/devcycle/#end-of-life-branches Removing support for EOL Pythons will reduce testing and maintenance resources while allowing the library to move towards modern Python 3. Using pypinfo, we can show the PyPI download statistics, showing less than 10% of users are using Python 2.7. | python_version | percent | download_count | | -------------- | ------: | -------------: | | 3.7 | 45.36% | 3,056,010 | | 3.6 | 26.46% | 1,782,778 | | 3.8 | 12.22% | 823,213 | | 2.7 | 9.97% | 671,459 | | 3.5 | 5.86% | 394,846 | | 3.4 | 0.10% | 6,700 | | 3.9 | 0.03% | 2,346 | | 2.6 | 0.00% | 57 | | 3.3 | 0.00% | 21 | | 3.10 | 0.00% | 6 | | Total | | 6,737,436 | Library users who continue to use Python 2.7 will still be able to install previous versions of sqlparse. Compatibility shims have been dropped, simplifying the code. Using pyupgrade, the codebase has been updated to take advantage of modern syntax <https://github.com/asottile/pyupgrade>. The wheel is no longer marked as "universal" as it is now Python 3 only.
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py6
-rw-r--r--tests/test_cli.py10
-rw-r--r--tests/test_format.py14
-rw-r--r--tests/test_grouping.py6
-rw-r--r--tests/test_keywords.py1
-rw-r--r--tests/test_parse.py16
-rw-r--r--tests/test_regressions.py31
-rw-r--r--tests/test_split.py18
-rw-r--r--tests/test_tokenize.py6
9 files changed, 43 insertions, 65 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index f2473a4..939c481 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
"""Helpers for testing."""
import io
@@ -35,7 +33,7 @@ def load_file(filepath):
# https://stackoverflow.com/questions/18011902/py-test-pass-a-parameter-to-a-fixture-function/33879151#33879151
# Syntax is noisy and requires specific variable names
# And seems to be limited to only 1 argument.
- with io.open(filepath(filename), encoding=encoding) as f:
+ with open(filepath(filename), encoding=encoding) as f:
return f.read().strip()
return make_load_file
@@ -44,6 +42,6 @@ def load_file(filepath):
@pytest.fixture()
def get_stream(filepath):
def make_stream(filename, encoding='utf-8'):
- return io.open(filepath(filename), encoding=encoding)
+ return open(filepath(filename), encoding=encoding)
return make_stream
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 5f1ea0e..746b632 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
import subprocess
import sys
@@ -71,7 +69,7 @@ def test_stdout(filepath, load_file, capsys):
def test_script():
# Call with the --help option as a basic sanity check.
- cmd = "{0:s} -m sqlparse.cli --help".format(sys.executable)
+ cmd = "{:s} -m sqlparse.cli --help".format(sys.executable)
assert subprocess.call(cmd.split()) == 0
@@ -115,7 +113,7 @@ def test_encoding_stdin_utf8(filepath, load_file, capfd):
path = filepath('encoding_utf8.sql')
expected = load_file('encoding_utf8.sql', 'utf-8')
old_stdin = sys.stdin
- with open(path, 'r') as f:
+ with open(path) as f:
sys.stdin = f
sys.stdout.encoding = 'utf-8'
sqlparse.cli.main(['-'])
@@ -128,7 +126,7 @@ def test_encoding_stdin_gbk(filepath, load_file, capfd):
path = filepath('encoding_gbk.sql')
expected = load_file('encoding_gbk.sql', 'gbk')
old_stdin = sys.stdin
- with open(path, 'r') as stream:
+ with open(path) as stream:
sys.stdin = stream
sys.stdout.encoding = 'gbk'
sqlparse.cli.main(['-', '--encoding', 'gbk'])
@@ -139,7 +137,7 @@ def test_encoding_stdin_gbk(filepath, load_file, capfd):
def test_encoding(filepath, capsys):
path = filepath('test_cp1251.sql')
- expected = u'insert into foo values (1); -- Песня про надежду\n'
+ expected = 'insert into foo values (1); -- Песня про надежду\n'
sqlparse.cli.main([path, '--encoding=cp1251'])
out, _ = capsys.readouterr()
assert out == expected
diff --git a/tests/test_format.py b/tests/test_format.py
index 811e083..20390ff 100644
--- a/tests/test_format.py
+++ b/tests/test_format.py
@@ -1,12 +1,10 @@
-# -*- coding: utf-8 -*-
-
import pytest
import sqlparse
from sqlparse.exceptions import SQLParseError
-class TestFormat(object):
+class TestFormat:
def test_keywordcase(self):
sql = 'select * from bar; -- select foo\n'
res = sqlparse.format(sql, keyword_case='upper')
@@ -123,7 +121,7 @@ class TestFormat(object):
== "SELECT some_column LIKE 'value\\\\\\'\r' WHERE id = 1\n")
-class TestFormatReindentAligned(object):
+class TestFormatReindentAligned:
@staticmethod
def formatter(sql):
return sqlparse.format(sql, reindent_aligned=True)
@@ -294,7 +292,7 @@ class TestFormatReindentAligned(object):
' from table'])
-class TestSpacesAroundOperators(object):
+class TestSpacesAroundOperators:
@staticmethod
def formatter(sql):
return sqlparse.format(sql, use_space_around_operators=True)
@@ -321,7 +319,7 @@ class TestSpacesAroundOperators(object):
assert self.formatter(sql) == 'select a * b - c from table'
-class TestFormatReindent(object):
+class TestFormatReindent:
def test_option(self):
with pytest.raises(SQLParseError):
sqlparse.format('foo', reindent=2)
@@ -598,7 +596,7 @@ class TestFormatReindent(object):
' , (5, 6)'])
-class TestOutputFormat(object):
+class TestOutputFormat:
def test_python(self):
sql = 'select * from foo;'
f = lambda sql: sqlparse.format(sql, output_format='python')
@@ -663,7 +661,7 @@ def test_format_column_ordering():
def test_truncate_strings():
- sql = "update foo set value = '{0}';".format('x' * 1000)
+ sql = "update foo set value = '{}';".format('x' * 1000)
formatted = sqlparse.format(sql, truncate_strings=10)
assert formatted == "update foo set value = 'xxxxxxxxxx[...]';"
formatted = sqlparse.format(sql, truncate_strings=3, truncate_char='YYY')
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index 87dcf11..683954e 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
import pytest
import sqlparse
@@ -484,7 +482,7 @@ def test_comparison_with_parenthesis():
))
def test_comparison_with_strings(operator):
# issue148
- p = sqlparse.parse("foo {0} 'bar'".format(operator))[0]
+ p = sqlparse.parse("foo {} 'bar'".format(operator))[0]
assert len(p.tokens) == 1
assert isinstance(p.tokens[0], sql.Comparison)
assert p.tokens[0].right.value == "'bar'"
@@ -563,7 +561,7 @@ def test_comparison_with_typed_literal():
@pytest.mark.parametrize('start', ['FOR', 'FOREACH'])
def test_forloops(start):
- p = sqlparse.parse('{0} foo in bar LOOP foobar END LOOP'.format(start))[0]
+ p = sqlparse.parse('{} foo in bar LOOP foobar END LOOP'.format(start))[0]
assert (len(p.tokens)) == 1
assert isinstance(p.tokens[0], sql.For)
diff --git a/tests/test_keywords.py b/tests/test_keywords.py
index c197f36..d4ded4b 100644
--- a/tests/test_keywords.py
+++ b/tests/test_keywords.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
import pytest
from sqlparse import tokens
diff --git a/tests/test_parse.py b/tests/test_parse.py
index c28cb06..6cce909 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -1,12 +1,10 @@
-# -*- coding: utf-8 -*-
-
"""Tests sqlparse.parse()."""
+from io import StringIO
import pytest
import sqlparse
from sqlparse import sql, tokens as T
-from sqlparse.compat import StringIO, text_type
def test_parse_tokenize():
@@ -409,26 +407,26 @@ def test_dbldollar_as_literal(sql, is_literal):
def test_non_ascii():
- _test_non_ascii = u"insert into test (id, name) values (1, 'тест');"
+ _test_non_ascii = "insert into test (id, name) values (1, 'тест');"
s = _test_non_ascii
stmts = sqlparse.parse(s)
assert len(stmts) == 1
statement = stmts[0]
- assert text_type(statement) == s
+ assert str(statement) == s
assert statement._pprint_tree() is None
s = _test_non_ascii.encode('utf-8')
stmts = sqlparse.parse(s, 'utf-8')
assert len(stmts) == 1
statement = stmts[0]
- assert text_type(statement) == _test_non_ascii
+ assert str(statement) == _test_non_ascii
assert statement._pprint_tree() is None
def test_get_real_name():
# issue 369
- s = u"update a t set t.b=1"
+ s = "update a t set t.b=1"
stmts = sqlparse.parse(s)
assert len(stmts) == 1
assert 'a' == stmts[0].tokens[2].get_real_name()
@@ -437,14 +435,14 @@ def test_get_real_name():
def test_from_subquery():
# issue 446
- s = u'from(select 1)'
+ s = 'from(select 1)'
stmts = sqlparse.parse(s)
assert len(stmts) == 1
assert len(stmts[0].tokens) == 2
assert stmts[0].tokens[0].value == 'from'
assert stmts[0].tokens[0].ttype == T.Keyword
- s = u'from (select 1)'
+ s = 'from (select 1)'
stmts = sqlparse.parse(s)
assert len(stmts) == 1
assert len(stmts[0].tokens) == 3
diff --git a/tests/test_regressions.py b/tests/test_regressions.py
index 2ed0ff3..648cc4a 100644
--- a/tests/test_regressions.py
+++ b/tests/test_regressions.py
@@ -1,10 +1,7 @@
-# -*- coding: utf-8 -*-
-
import pytest
import sqlparse
from sqlparse import sql, tokens as T
-from sqlparse.compat import PY2
def test_issue9():
@@ -20,9 +17,9 @@ def test_issue9():
def test_issue13():
- parsed = sqlparse.parse(("select 'one';\n"
- "select 'two\\'';\n"
- "select 'three';"))
+ parsed = sqlparse.parse("select 'one';\n"
+ "select 'two\\'';\n"
+ "select 'three';")
assert len(parsed) == 3
assert str(parsed[1]).strip() == "select 'two\\'';"
@@ -73,8 +70,8 @@ def test_issue39():
def test_issue40():
# make sure identifier lists in subselects are grouped
- p = sqlparse.parse(('SELECT id, name FROM '
- '(SELECT id, name FROM bar) as foo'))[0]
+ p = sqlparse.parse('SELECT id, name FROM '
+ '(SELECT id, name FROM bar) as foo')[0]
assert len(p.tokens) == 7
assert p.tokens[2].__class__ == sql.IdentifierList
assert p.tokens[-1].__class__ == sql.Identifier
@@ -149,7 +146,7 @@ def test_issue83():
def test_comment_encoding_when_reindent():
# There was an UnicodeEncodeError in the reindent filter that
# casted every comment followed by a keyword to str.
- sql = u'select foo -- Comment containing Ümläuts\nfrom bar'
+ sql = 'select foo -- Comment containing Ümläuts\nfrom bar'
formatted = sqlparse.format(sql, reindent=True)
assert formatted == sql
@@ -158,11 +155,9 @@ def test_parse_sql_with_binary():
# See https://github.com/andialbrecht/sqlparse/pull/88
# digest = '‚|ËêŠplL4¡h‘øN{'
digest = '\x82|\xcb\x0e\xea\x8aplL4\xa1h\x91\xf8N{'
- sql = "select * from foo where bar = '{0}'".format(digest)
+ sql = "select * from foo where bar = '{}'".format(digest)
formatted = sqlparse.format(sql, reindent=True)
- tformatted = "select *\nfrom foo\nwhere bar = '{0}'".format(digest)
- if PY2:
- tformatted = tformatted.decode('unicode-escape')
+ tformatted = "select *\nfrom foo\nwhere bar = '{}'".format(digest)
assert formatted == tformatted
@@ -180,7 +175,7 @@ def test_format_accepts_encoding(load_file):
# issue20
sql = load_file('test_cp1251.sql', 'cp1251')
formatted = sqlparse.format(sql, reindent=True, encoding='cp1251')
- tformatted = u'insert into foo\nvalues (1); -- Песня про надежду'
+ tformatted = 'insert into foo\nvalues (1); -- Песня про надежду'
assert formatted == tformatted
@@ -275,7 +270,7 @@ def test_issue186_get_type():
def test_issue212_py2unicode():
- t1 = sql.Token(T.String, u'schöner ')
+ t1 = sql.Token(T.String, 'schöner ')
t2 = sql.Token(T.String, 'bug')
token_list = sql.TokenList([t1, t2])
assert str(token_list) == 'schöner bug'
@@ -337,11 +332,9 @@ def test_issue315_utf8_by_default():
'\x9b\xb2.'
'\xec\x82\xac\xeb\x9e\x91\xed\x95\xb4\xec\x9a\x94'
)
- sql = "select * from foo where bar = '{0}'".format(digest)
+ sql = "select * from foo where bar = '{}'".format(digest)
formatted = sqlparse.format(sql, reindent=True)
- tformatted = "select *\nfrom foo\nwhere bar = '{0}'".format(digest)
- if PY2:
- tformatted = tformatted.decode('utf-8')
+ tformatted = "select *\nfrom foo\nwhere bar = '{}'".format(digest)
assert formatted == tformatted
diff --git a/tests/test_split.py b/tests/test_split.py
index a93e3d4..8214756 100644
--- a/tests/test_split.py
+++ b/tests/test_split.py
@@ -1,13 +1,11 @@
-# -*- coding: utf-8 -*-
-
# Tests splitting functions.
import types
+from io import StringIO
import pytest
import sqlparse
-from sqlparse.compat import StringIO, text_type
def test_split_semicolon():
@@ -33,7 +31,7 @@ def test_split_create_function(load_file, fn):
sql = load_file(fn)
stmts = sqlparse.parse(sql)
assert len(stmts) == 1
- assert text_type(stmts[0]) == sql
+ assert str(stmts[0]) == sql
def test_split_dashcomments(load_file):
@@ -74,12 +72,12 @@ def test_split_dropif():
def test_split_comment_with_umlaut():
- sql = (u'select * from foo;\n'
- u'-- Testing an umlaut: ä\n'
- u'select * from bar;')
+ sql = ('select * from foo;\n'
+ '-- Testing an umlaut: ä\n'
+ 'select * from bar;')
stmts = sqlparse.parse(sql)
assert len(stmts) == 2
- assert ''.join(text_type(q) for q in stmts) == sql
+ assert ''.join(str(q) for q in stmts) == sql
def test_split_comment_end_of_line():
@@ -125,11 +123,11 @@ def test_split_stream():
def test_split_encoding_parsestream():
stream = StringIO("SELECT 1; SELECT 2;")
stmts = list(sqlparse.parsestream(stream))
- assert isinstance(stmts[0].tokens[0].value, text_type)
+ assert isinstance(stmts[0].tokens[0].value, str)
def test_split_unicode_parsestream():
- stream = StringIO(u'SELECT ö')
+ stream = StringIO('SELECT ö')
stmts = list(sqlparse.parsestream(stream))
assert str(stmts[0]) == 'SELECT ö'
diff --git a/tests/test_tokenize.py b/tests/test_tokenize.py
index 3e8831b..0d7f878 100644
--- a/tests/test_tokenize.py
+++ b/tests/test_tokenize.py
@@ -1,13 +1,11 @@
-# -*- coding: utf-8 -*-
-
import types
+from io import StringIO
import pytest
import sqlparse
from sqlparse import lexer
from sqlparse import sql, tokens as T
-from sqlparse.compat import StringIO
def test_tokenize_simple():
@@ -152,7 +150,7 @@ def test_stream_error():
'INNER JOIN',
'LEFT INNER JOIN'])
def test_parse_join(expr):
- p = sqlparse.parse('{0} foo'.format(expr))[0]
+ p = sqlparse.parse('{} foo'.format(expr))[0]
assert len(p.tokens) == 3
assert p.tokens[0].ttype is T.Keyword