diff options
| author | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-04 21:57:43 -0700 |
|---|---|---|
| committer | Victor Uriarte <victor.m.uriarte@intel.com> | 2016-06-06 06:31:35 -0700 |
| commit | a7c7d9586208516de372cb01203b48a53f7095fb (patch) | |
| tree | 95e887de388e5f6f1516b1ea862e9d48a4d174eb /tests | |
| parent | 035ffb8e61b2cda516ae448246df36451ff6d14b (diff) | |
| download | sqlparse-a7c7d9586208516de372cb01203b48a53f7095fb.tar.gz | |
Format `pr` to pass flake8 and update functions used
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_format.py | 34 | ||||
| -rw-r--r-- | tests/test_grouping.py | 12 |
2 files changed, 27 insertions, 19 deletions
diff --git a/tests/test_format.py b/tests/test_format.py index 22ab5b6..7b5af06 100644 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -252,7 +252,7 @@ class TestFormatReindentAligned(TestCaseBase): ])) def test_group_by_subquery(self): - # TODO: add subquery alias in again when test_grouping.TestGrouping.test_identifier_list_subquery fixed + # TODO: add subquery alias when test_identifier_list_subquery fixed sql = """ select *, sum_b + 2 as mod_sum from ( @@ -275,23 +275,27 @@ class TestFormatReindentAligned(TestCaseBase): ' )', ' order by 1,', ' 2', - ])) + ])) def test_window_functions(self): sql = """ select a, - SUM(a) OVER (PARTITION BY b ORDER BY c ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as sum_a, - ROW_NUMBER() OVER (PARTITION BY b, c ORDER BY d DESC) as row_num + SUM(a) OVER (PARTITION BY b ORDER BY c ROWS + BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as sum_a, + ROW_NUMBER() OVER + (PARTITION BY b, c ORDER BY d DESC) as row_num from table """ self.ndiffAssertEqual( self.formatter(sql), '\n'.join([ 'select a,', - ' SUM(a) OVER (PARTITION BY b ORDER BY c ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as sum_a,', - ' ROW_NUMBER() OVER (PARTITION BY b, c ORDER BY d DESC) as row_num', + (' SUM(a) OVER (PARTITION BY b ORDER BY c ROWS ' + 'BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as sum_a,'), + (' ROW_NUMBER() OVER ' + '(PARTITION BY b, c ORDER BY d DESC) as row_num'), ' from table', - ])) + ])) class TestSpacesAroundOperators(TestCaseBase): @@ -300,32 +304,34 @@ class TestSpacesAroundOperators(TestCaseBase): return sqlparse.format(sql, use_space_around_operators=True) def test_basic(self): - sql = 'select a+b as d from table where (c-d)%2= 1 and e> 3.0/4 and z^2 <100' + sql = ('select a+b as d from table ' + 'where (c-d)%2= 1 and e> 3.0/4 and z^2 <100') self.ndiffAssertEqual( - self.formatter(sql), - 'select a + b as d from table where (c - d) % 2 = 1 and e > 3.0 / 4 and z ^ 2 < 100' - ) + self.formatter(sql), ( + 'select a + b as d from table ' + 'where (c - d) % 2 = 1 and e > 3.0 / 4 and z ^ 2 < 100') + ) def test_bools(self): sql = 'select * from table where a &&b or c||d' self.ndiffAssertEqual( self.formatter(sql), 'select * from table where a && b or c || d' - ) + ) def test_nested(self): sql = 'select *, case when a-b then c end from table' self.ndiffAssertEqual( self.formatter(sql), 'select *, case when a - b then c end from table' - ) + ) def test_wildcard_vs_mult(self): sql = 'select a*b-c from table' self.ndiffAssertEqual( self.formatter(sql), 'select a * b - c from table' - ) + ) class TestFormatReindent(TestCaseBase): diff --git a/tests/test_grouping.py b/tests/test_grouping.py index 40a35cf..fdcd4a7 100644 --- a/tests/test_grouping.py +++ b/tests/test_grouping.py @@ -122,15 +122,16 @@ class TestGrouping(TestCaseBase): p = sqlparse.parse('(a, b, c)')[0] self.assert_(isinstance(p.tokens[0].tokens[1], sql.IdentifierList)) - @pytest.mark.xfail(strict=True) def test_identifier_list_subquery(self): """identifier lists should still work in subqueries with aliases""" - p = sqlparse.parse("""select * from (select a, b + c as d from table) sub""")[0] + p = sqlparse.parse("select * from (" + "select a, b + c as d from table) sub")[0] subquery = p.tokens[-1].tokens[0] - iden_list = subquery.token_next_by_instance(0, sql.IdentifierList) + iden_list = subquery.token_next_by(i=sql.IdentifierList) self.assert_(iden_list is not None) # all the identifiers should be within the IdentifierList - self.assert_(subquery.token_next_by_instance(subquery.token_index(iden_list), sql.Identifier) is None) + self.assert_(subquery.token_next_by(i=sql.Identifier, + idx=iden_list) is None) def test_identifier_list_case(self): p = sqlparse.parse('a, case when 1 then 2 else 3 end as b, c')[0] @@ -152,7 +153,8 @@ class TestGrouping(TestCaseBase): def test_identifiers_with_operators(self): p = sqlparse.parse('a+b as c from table where (d-e)%2= 1')[0] - self.assertEqual(len([x for x in p.flatten() if x.ttype == sqlparse.tokens.Name]), 5) + self.assertEqual(len([x for x in p.flatten() + if x.ttype == sqlparse.tokens.Name]), 5) def test_identifier_list_with_order(self): # issue101 p = sqlparse.parse('1, 2 desc, 3')[0] |
