Harbor format: 871 coding_baseline tasks (part 14)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0ytgxfff/tests/trusted-inventory.json +152 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0ytgxfff/tests/trusted/tests/test_split.py +210 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0ytgxfff/tests/trusted/tests/test_tokenize.py +247 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0ytgxfff/tests/trusted/tests/test_utils.py +12 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0ytgxfff/validation/canaries/original-bug.sh +3 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0ytgxfff/validation/openenv.json +27 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/LICENSE.source +25 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/adapter.json +126 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/dependency-setup.sh +8 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/environment/Dockerfile +3 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/instruction.md +38 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/metadata.json +533 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/provenance.json +88 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/provided-gold.diff +15 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/solution/solve.sh +21 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/task.toml +24 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/check_pytest.py +91 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/expected-panels.json +337 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/grade.py +128 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/panel-config.json +22 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/test.sh +6 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted-inventory.json +152 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/pyproject.toml +104 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/__init__.py +0 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/conftest.py +47 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/_Make_DirEntry.sql +6 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/begintag.sql +4 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/begintag_2.sql +13 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/casewhen_procedure.sql +8 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/dashcomment.sql +5 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/encoding_gbk.sql +3 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/encoding_utf8.sql +3 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/function.sql +13 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/function_psql.sql +72 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/function_psql2.sql +7 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/function_psql3.sql +8 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/function_psql4.sql +12 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/huge_select.sql +1 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/multiple_case_in_begin.sql +8 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/mysql_handler.sql +10 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/stream.sql +2 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/test_cp1251.sql +1 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_cli.py +122 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_format.py +774 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_grouping.py +679 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_keywords.py +13 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_parse.py +595 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_regressions.py +467 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_split.py +210 -0
- tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_tokenize.py +247 -0
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0ytgxfff/tests/trusted-inventory.json
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
| 9 |
+
"sha256": "f45ed1a6a2c302a1b5a63cba825e9ad451c511427317faf52cf94492cb9f3144"
|
| 10 |
+
},
|
| 11 |
+
"tests/__init__.py": {
|
| 12 |
+
"bytes": 0,
|
| 13 |
+
"mode": 420,
|
| 14 |
+
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
| 15 |
+
},
|
| 16 |
+
"tests/conftest.py": {
|
| 17 |
+
"bytes": 1571,
|
| 18 |
+
"mode": 420,
|
| 19 |
+
"sha256": "78a520624361004ba4d9928e332b8df9e99279bff81d73aa735e58b8fc4d7f60"
|
| 20 |
+
},
|
| 21 |
+
"tests/files/_Make_DirEntry.sql": {
|
| 22 |
+
"bytes": 109,
|
| 23 |
+
"mode": 420,
|
| 24 |
+
"sha256": "477c6e434484000c6d34d8a1189b636c8595a906bbfdaead27110d33be192361"
|
| 25 |
+
},
|
| 26 |
+
"tests/files/begintag.sql": {
|
| 27 |
+
"bytes": 45,
|
| 28 |
+
"mode": 420,
|
| 29 |
+
"sha256": "eaf3ccbbe3e8a519ec00d95e875cf2063da21be757e85fdd15c3e11627ca350f"
|
| 30 |
+
},
|
| 31 |
+
"tests/files/begintag_2.sql": {
|
| 32 |
+
"bytes": 357,
|
| 33 |
+
"mode": 420,
|
| 34 |
+
"sha256": "d2deb7406afd541424617d618413d632b079bd650622a58d797df197f92eead2"
|
| 35 |
+
},
|
| 36 |
+
"tests/files/casewhen_procedure.sql": {
|
| 37 |
+
"bytes": 150,
|
| 38 |
+
"mode": 420,
|
| 39 |
+
"sha256": "e2fffb5d1c32f750b652231ef6a8267797f91d902dd5fbd09cdafa1490d7a9f5"
|
| 40 |
+
},
|
| 41 |
+
"tests/files/dashcomment.sql": {
|
| 42 |
+
"bytes": 88,
|
| 43 |
+
"mode": 420,
|
| 44 |
+
"sha256": "77d2a0426573b95fea0f33ff300d29d8779d69f4d6aae52588d45832cc97a7f9"
|
| 45 |
+
},
|
| 46 |
+
"tests/files/encoding_gbk.sql": {
|
| 47 |
+
"bytes": 50,
|
| 48 |
+
"mode": 420,
|
| 49 |
+
"sha256": "b46e2aa2afd9973c1ecf6a1778b65c1b9c32eac1679d2dd733bff93bd8f71403"
|
| 50 |
+
},
|
| 51 |
+
"tests/files/encoding_utf8.sql": {
|
| 52 |
+
"bytes": 76,
|
| 53 |
+
"mode": 420,
|
| 54 |
+
"sha256": "abd229df1799a0e3cacf0262439ac446a6f9e1475a061a836d54f7bf71537dce"
|
| 55 |
+
},
|
| 56 |
+
"tests/files/function.sql": {
|
| 57 |
+
"bytes": 187,
|
| 58 |
+
"mode": 420,
|
| 59 |
+
"sha256": "f7ebcddcfa7366ac9ef1f2042e85980b9d1b709376504fbcac2fbaf31d500438"
|
| 60 |
+
},
|
| 61 |
+
"tests/files/function_psql.sql": {
|
| 62 |
+
"bytes": 3066,
|
| 63 |
+
"mode": 420,
|
| 64 |
+
"sha256": "374d3ad5a85b295656c80891414575d2e914b7d44441cf0c301c8ba7823ba6e2"
|
| 65 |
+
},
|
| 66 |
+
"tests/files/function_psql2.sql": {
|
| 67 |
+
"bytes": 177,
|
| 68 |
+
"mode": 420,
|
| 69 |
+
"sha256": "ca09b0d5ec71d6b14c3547bd1f50bbb43a3c41c67a82ea7da7925b4a360978eb"
|
| 70 |
+
},
|
| 71 |
+
"tests/files/function_psql3.sql": {
|
| 72 |
+
"bytes": 171,
|
| 73 |
+
"mode": 420,
|
| 74 |
+
"sha256": "ab11189f23be717c821e84b61a43d65be26898aab0ddc3312dd4c017460e8eb2"
|
| 75 |
+
},
|
| 76 |
+
"tests/files/function_psql4.sql": {
|
| 77 |
+
"bytes": 221,
|
| 78 |
+
"mode": 420,
|
| 79 |
+
"sha256": "855912b6749f5252ee5a9d0a701e3fd00e8436b50953d4cb21ad66e8bab836dc"
|
| 80 |
+
},
|
| 81 |
+
"tests/files/huge_select.sql": {
|
| 82 |
+
"bytes": 9434,
|
| 83 |
+
"mode": 420,
|
| 84 |
+
"sha256": "2833206b9559cbbac1bb0cb9c15fb66a593528ec47ae5b8168a56550903658e7"
|
| 85 |
+
},
|
| 86 |
+
"tests/files/multiple_case_in_begin.sql": {
|
| 87 |
+
"bytes": 193,
|
| 88 |
+
"mode": 420,
|
| 89 |
+
"sha256": "120212421cbff79b576e173d5e6f2bdd45d8a7e06cfc8379e595cdea6ee58cec"
|
| 90 |
+
},
|
| 91 |
+
"tests/files/mysql_handler.sql": {
|
| 92 |
+
"bytes": 134,
|
| 93 |
+
"mode": 420,
|
| 94 |
+
"sha256": "70142d797ca7acf904e77aaec0587fd578f5ce134860fd81fbe98166fcd87157"
|
| 95 |
+
},
|
| 96 |
+
"tests/files/stream.sql": {
|
| 97 |
+
"bytes": 44,
|
| 98 |
+
"mode": 420,
|
| 99 |
+
"sha256": "8d1fdb5798c601f75f6bbcc750d07544ea47452e78687151a39fd7eb3c4a64bb"
|
| 100 |
+
},
|
| 101 |
+
"tests/files/test_cp1251.sql": {
|
| 102 |
+
"bytes": 49,
|
| 103 |
+
"mode": 420,
|
| 104 |
+
"sha256": "46f1d9cafe3b6f90ee79096e434f4509f5fa725f9c1b307e9180b8e2318a90b2"
|
| 105 |
+
},
|
| 106 |
+
"tests/test_cli.py": {
|
| 107 |
+
"bytes": 3521,
|
| 108 |
+
"mode": 420,
|
| 109 |
+
"sha256": "2283827e9658c1d785ee377a792f209bcc66ef411784706ffdf24c50030c2d46"
|
| 110 |
+
},
|
| 111 |
+
"tests/test_format.py": {
|
| 112 |
+
"bytes": 28438,
|
| 113 |
+
"mode": 420,
|
| 114 |
+
"sha256": "becba5a71cf4890844f0d602dbafc1a1a8337e6cd207cd966c9a71808baf7a46"
|
| 115 |
+
},
|
| 116 |
+
"tests/test_grouping.py": {
|
| 117 |
+
"bytes": 23973,
|
| 118 |
+
"mode": 420,
|
| 119 |
+
"sha256": "355a2dc8089f4f396c52f7922f0e10e4f1eb1c6c2a5d3ea47c3ae86d8d1cccd3"
|
| 120 |
+
},
|
| 121 |
+
"tests/test_keywords.py": {
|
| 122 |
+
"bytes": 447,
|
| 123 |
+
"mode": 420,
|
| 124 |
+
"sha256": "149f6845de1ae252a0265cf3e91086c6259c131c0f7f7a7518ea628e7ad399a3"
|
| 125 |
+
},
|
| 126 |
+
"tests/test_parse.py": {
|
| 127 |
+
"bytes": 18335,
|
| 128 |
+
"mode": 420,
|
| 129 |
+
"sha256": "f979f4024d44443d50a17a0169ace2f6fd8693e2e513529f222f6e56e2898838"
|
| 130 |
+
},
|
| 131 |
+
"tests/test_regressions.py": {
|
| 132 |
+
"bytes": 14896,
|
| 133 |
+
"mode": 420,
|
| 134 |
+
"sha256": "2c7c6c70fb416836e46fe752463e280022ebe5c1ecdd7ec18795862644bcb70e"
|
| 135 |
+
},
|
| 136 |
+
"tests/test_split.py": {
|
| 137 |
+
"bytes": 6147,
|
| 138 |
+
"mode": 420,
|
| 139 |
+
"sha256": "28d8917cc41d1755e78416e79c9ad6bd9e781938ed0ad09a12e41d771fab3d48"
|
| 140 |
+
},
|
| 141 |
+
"tests/test_tokenize.py": {
|
| 142 |
+
"bytes": 6364,
|
| 143 |
+
"mode": 420,
|
| 144 |
+
"sha256": "a26ee60a83832e0dee1420ef2f7df84de3d19ce8a92e69fc4f2cc39c91fa8db3"
|
| 145 |
+
},
|
| 146 |
+
"tests/test_utils.py": {
|
| 147 |
+
"bytes": 268,
|
| 148 |
+
"mode": 420,
|
| 149 |
+
"sha256": "49ae35e7607af5c8a9b83b6f14f47c30d8fcdc27da06a677fd92bef3e55ab998"
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
}
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0ytgxfff/tests/trusted/tests/test_split.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Tests splitting functions.
|
| 2 |
+
|
| 3 |
+
import types
|
| 4 |
+
from io import StringIO
|
| 5 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
import sqlparse
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_split_semicolon():
|
| 12 |
+
sql1 = 'select * from foo;'
|
| 13 |
+
sql2 = "select * from foo where bar = 'foo;bar';"
|
| 14 |
+
stmts = sqlparse.parse(''.join([sql1, sql2]))
|
| 15 |
+
assert len(stmts) == 2
|
| 16 |
+
assert str(stmts[0]) == sql1
|
| 17 |
+
assert str(stmts[1]) == sql2
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def test_split_backslash():
|
| 21 |
+
stmts = sqlparse.parse("select '\'; select '\'';")
|
| 22 |
+
assert len(stmts) == 2
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@pytest.mark.parametrize('fn', ['function.sql',
|
| 26 |
+
'function_psql.sql',
|
| 27 |
+
'function_psql2.sql',
|
| 28 |
+
'function_psql3.sql',
|
| 29 |
+
'function_psql4.sql'])
|
| 30 |
+
def test_split_create_function(load_file, fn):
|
| 31 |
+
sql = load_file(fn)
|
| 32 |
+
stmts = sqlparse.parse(sql)
|
| 33 |
+
assert len(stmts) == 1
|
| 34 |
+
assert str(stmts[0]) == sql
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_split_dashcomments(load_file):
|
| 38 |
+
sql = load_file('dashcomment.sql')
|
| 39 |
+
stmts = sqlparse.parse(sql)
|
| 40 |
+
assert len(stmts) == 3
|
| 41 |
+
assert ''.join(str(q) for q in stmts) == sql
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@pytest.mark.parametrize('s', ['select foo; -- comment\n',
|
| 45 |
+
'select foo; -- comment\r',
|
| 46 |
+
'select foo; -- comment\r\n',
|
| 47 |
+
'select foo; -- comment'])
|
| 48 |
+
def test_split_dashcomments_eol(s):
|
| 49 |
+
stmts = sqlparse.parse(s)
|
| 50 |
+
assert len(stmts) == 1
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def test_split_begintag(load_file):
|
| 54 |
+
sql = load_file('begintag.sql')
|
| 55 |
+
stmts = sqlparse.parse(sql)
|
| 56 |
+
assert len(stmts) == 3
|
| 57 |
+
assert ''.join(str(q) for q in stmts) == sql
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def test_split_begintag_2(load_file):
|
| 61 |
+
sql = load_file('begintag_2.sql')
|
| 62 |
+
stmts = sqlparse.parse(sql)
|
| 63 |
+
assert len(stmts) == 1
|
| 64 |
+
assert ''.join(str(q) for q in stmts) == sql
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def test_split_dropif():
|
| 68 |
+
sql = 'DROP TABLE IF EXISTS FOO;\n\nSELECT * FROM BAR;'
|
| 69 |
+
stmts = sqlparse.parse(sql)
|
| 70 |
+
assert len(stmts) == 2
|
| 71 |
+
assert ''.join(str(q) for q in stmts) == sql
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def test_split_comment_with_umlaut():
|
| 75 |
+
sql = ('select * from foo;\n'
|
| 76 |
+
'-- Testing an umlaut: ä\n'
|
| 77 |
+
'select * from bar;')
|
| 78 |
+
stmts = sqlparse.parse(sql)
|
| 79 |
+
assert len(stmts) == 2
|
| 80 |
+
assert ''.join(str(q) for q in stmts) == sql
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def test_split_comment_end_of_line():
|
| 84 |
+
sql = ('select * from foo; -- foo\n'
|
| 85 |
+
'select * from bar;')
|
| 86 |
+
stmts = sqlparse.parse(sql)
|
| 87 |
+
assert len(stmts) == 2
|
| 88 |
+
assert ''.join(str(q) for q in stmts) == sql
|
| 89 |
+
# make sure the comment belongs to first query
|
| 90 |
+
assert str(stmts[0]) == 'select * from foo; -- foo\n'
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def test_split_casewhen():
|
| 94 |
+
sql = ("SELECT case when val = 1 then 2 else null end as foo;\n"
|
| 95 |
+
"comment on table actor is 'The actor table.';")
|
| 96 |
+
stmts = sqlparse.split(sql)
|
| 97 |
+
assert len(stmts) == 2
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def test_split_casewhen_procedure(load_file):
|
| 101 |
+
# see issue580
|
| 102 |
+
stmts = sqlparse.split(load_file('casewhen_procedure.sql'))
|
| 103 |
+
assert len(stmts) == 2
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def test_split_cursor_declare():
|
| 107 |
+
sql = ('DECLARE CURSOR "foo" AS SELECT 1;\n'
|
| 108 |
+
'SELECT 2;')
|
| 109 |
+
stmts = sqlparse.split(sql)
|
| 110 |
+
assert len(stmts) == 2
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def test_split_if_function(): # see issue 33
|
| 114 |
+
# don't let IF as a function confuse the splitter
|
| 115 |
+
sql = ('CREATE TEMPORARY TABLE tmp '
|
| 116 |
+
'SELECT IF(a=1, a, b) AS o FROM one; '
|
| 117 |
+
'SELECT t FROM two')
|
| 118 |
+
stmts = sqlparse.split(sql)
|
| 119 |
+
assert len(stmts) == 2
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def test_split_stream():
|
| 123 |
+
stream = StringIO("SELECT 1; SELECT 2;")
|
| 124 |
+
stmts = sqlparse.parsestream(stream)
|
| 125 |
+
assert isinstance(stmts, types.GeneratorType)
|
| 126 |
+
assert len(list(stmts)) == 2
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def test_split_encoding_parsestream():
|
| 130 |
+
stream = StringIO("SELECT 1; SELECT 2;")
|
| 131 |
+
stmts = list(sqlparse.parsestream(stream))
|
| 132 |
+
assert isinstance(stmts[0].tokens[0].value, str)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def test_split_unicode_parsestream():
|
| 136 |
+
stream = StringIO('SELECT ö')
|
| 137 |
+
stmts = list(sqlparse.parsestream(stream))
|
| 138 |
+
assert str(stmts[0]) == 'SELECT ö'
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def test_split_simple():
|
| 142 |
+
stmts = sqlparse.split('select * from foo; select * from bar;')
|
| 143 |
+
assert len(stmts) == 2
|
| 144 |
+
assert stmts[0] == 'select * from foo;'
|
| 145 |
+
assert stmts[1] == 'select * from bar;'
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def test_split_ignores_empty_newlines():
|
| 149 |
+
stmts = sqlparse.split('select foo;\nselect bar;\n')
|
| 150 |
+
assert len(stmts) == 2
|
| 151 |
+
assert stmts[0] == 'select foo;'
|
| 152 |
+
assert stmts[1] == 'select bar;'
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def test_split_quotes_with_new_line():
|
| 156 |
+
stmts = sqlparse.split('select "foo\nbar"')
|
| 157 |
+
assert len(stmts) == 1
|
| 158 |
+
assert stmts[0] == 'select "foo\nbar"'
|
| 159 |
+
|
| 160 |
+
stmts = sqlparse.split("select 'foo\n\bar'")
|
| 161 |
+
assert len(stmts) == 1
|
| 162 |
+
assert stmts[0] == "select 'foo\n\bar'"
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def test_split_mysql_handler_for(load_file):
|
| 166 |
+
# see issue581
|
| 167 |
+
stmts = sqlparse.split(load_file('mysql_handler.sql'))
|
| 168 |
+
assert len(stmts) == 2
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
@pytest.mark.parametrize('sql, expected', [
|
| 172 |
+
('select * from foo;', ['select * from foo']),
|
| 173 |
+
('select * from foo', ['select * from foo']),
|
| 174 |
+
('select * from foo; select * from bar;', [
|
| 175 |
+
'select * from foo',
|
| 176 |
+
'select * from bar',
|
| 177 |
+
]),
|
| 178 |
+
(' select * from foo;\n\nselect * from bar;\n\n\n\n', [
|
| 179 |
+
'select * from foo',
|
| 180 |
+
'select * from bar',
|
| 181 |
+
]),
|
| 182 |
+
('select * from foo\n\n; bar', ['select * from foo', 'bar']),
|
| 183 |
+
])
|
| 184 |
+
def test_split_strip_semicolon(sql, expected):
|
| 185 |
+
stmts = sqlparse.split(sql, strip_semicolon=True)
|
| 186 |
+
assert len(stmts) == len(expected)
|
| 187 |
+
for idx, expectation in enumerate(expected):
|
| 188 |
+
assert stmts[idx] == expectation
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def test_split_strip_semicolon_procedure(load_file):
|
| 192 |
+
stmts = sqlparse.split(load_file('mysql_handler.sql'),
|
| 193 |
+
strip_semicolon=True)
|
| 194 |
+
assert len(stmts) == 2
|
| 195 |
+
assert stmts[0].endswith('end')
|
| 196 |
+
assert stmts[1].endswith('end')
|
| 197 |
+
|
| 198 |
+
@pytest.mark.parametrize('sql, num', [
|
| 199 |
+
('USE foo;\nGO\nSELECT 1;\nGO', 4),
|
| 200 |
+
('SELECT * FROM foo;\nGO', 2),
|
| 201 |
+
('USE foo;\nGO 2\nSELECT 1;', 3)
|
| 202 |
+
])
|
| 203 |
+
def test_split_go(sql, num): # issue762
|
| 204 |
+
stmts = sqlparse.split(sql)
|
| 205 |
+
assert len(stmts) == num
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def test_split_multiple_case_in_begin(load_file): # issue784
|
| 209 |
+
stmts = sqlparse.split(load_file('multiple_case_in_begin.sql'))
|
| 210 |
+
assert len(stmts) == 1
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0ytgxfff/tests/trusted/tests/test_tokenize.py
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import types
|
| 2 |
+
from io import StringIO
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
import sqlparse
|
| 7 |
+
from sqlparse import lexer
|
| 8 |
+
from sqlparse import sql, tokens as T
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_tokenize_simple():
|
| 12 |
+
s = 'select * from foo;'
|
| 13 |
+
stream = lexer.tokenize(s)
|
| 14 |
+
assert isinstance(stream, types.GeneratorType)
|
| 15 |
+
tokens = list(stream)
|
| 16 |
+
assert len(tokens) == 8
|
| 17 |
+
assert len(tokens[0]) == 2
|
| 18 |
+
assert tokens[0] == (T.Keyword.DML, 'select')
|
| 19 |
+
assert tokens[-1] == (T.Punctuation, ';')
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def test_tokenize_backticks():
|
| 23 |
+
s = '`foo`.`bar`'
|
| 24 |
+
tokens = list(lexer.tokenize(s))
|
| 25 |
+
assert len(tokens) == 3
|
| 26 |
+
assert tokens[0] == (T.Name, '`foo`')
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@pytest.mark.parametrize('s', ['foo\nbar\n', 'foo\rbar\r',
|
| 30 |
+
'foo\r\nbar\r\n', 'foo\r\nbar\n'])
|
| 31 |
+
def test_tokenize_linebreaks(s):
|
| 32 |
+
# issue1
|
| 33 |
+
tokens = lexer.tokenize(s)
|
| 34 |
+
assert ''.join(str(x[1]) for x in tokens) == s
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_tokenize_inline_keywords():
|
| 38 |
+
# issue 7
|
| 39 |
+
s = "create created_foo"
|
| 40 |
+
tokens = list(lexer.tokenize(s))
|
| 41 |
+
assert len(tokens) == 3
|
| 42 |
+
assert tokens[0][0] == T.Keyword.DDL
|
| 43 |
+
assert tokens[2][0] == T.Name
|
| 44 |
+
assert tokens[2][1] == 'created_foo'
|
| 45 |
+
s = "enddate"
|
| 46 |
+
tokens = list(lexer.tokenize(s))
|
| 47 |
+
assert len(tokens) == 1
|
| 48 |
+
assert tokens[0][0] == T.Name
|
| 49 |
+
s = "join_col"
|
| 50 |
+
tokens = list(lexer.tokenize(s))
|
| 51 |
+
assert len(tokens) == 1
|
| 52 |
+
assert tokens[0][0] == T.Name
|
| 53 |
+
s = "left join_col"
|
| 54 |
+
tokens = list(lexer.tokenize(s))
|
| 55 |
+
assert len(tokens) == 3
|
| 56 |
+
assert tokens[2][0] == T.Name
|
| 57 |
+
assert tokens[2][1] == 'join_col'
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def test_tokenize_negative_numbers():
|
| 61 |
+
s = "values(-1)"
|
| 62 |
+
tokens = list(lexer.tokenize(s))
|
| 63 |
+
assert len(tokens) == 4
|
| 64 |
+
assert tokens[2][0] == T.Number.Integer
|
| 65 |
+
assert tokens[2][1] == '-1'
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def test_token_str():
|
| 69 |
+
token = sql.Token(None, 'FoO')
|
| 70 |
+
assert str(token) == 'FoO'
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def test_token_repr():
|
| 74 |
+
token = sql.Token(T.Keyword, 'foo')
|
| 75 |
+
tst = "<Keyword 'foo' at 0x"
|
| 76 |
+
assert repr(token)[:len(tst)] == tst
|
| 77 |
+
token = sql.Token(T.Keyword, '1234567890')
|
| 78 |
+
tst = "<Keyword '123456...' at 0x"
|
| 79 |
+
assert repr(token)[:len(tst)] == tst
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def test_token_flatten():
|
| 83 |
+
token = sql.Token(T.Keyword, 'foo')
|
| 84 |
+
gen = token.flatten()
|
| 85 |
+
assert isinstance(gen, types.GeneratorType)
|
| 86 |
+
lgen = list(gen)
|
| 87 |
+
assert lgen == [token]
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def test_tokenlist_repr():
|
| 91 |
+
p = sqlparse.parse('foo, bar, baz')[0]
|
| 92 |
+
tst = "<IdentifierList 'foo, b...' at 0x"
|
| 93 |
+
assert repr(p.tokens[0])[:len(tst)] == tst
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def test_single_quotes():
|
| 97 |
+
p = sqlparse.parse("'test'")[0]
|
| 98 |
+
tst = "<Single \"'test'\" at 0x"
|
| 99 |
+
assert repr(p.tokens[0])[:len(tst)] == tst
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def test_tokenlist_first():
|
| 103 |
+
p = sqlparse.parse(' select foo')[0]
|
| 104 |
+
first = p.token_first()
|
| 105 |
+
assert first.value == 'select'
|
| 106 |
+
assert p.token_first(skip_ws=False).value == ' '
|
| 107 |
+
assert sql.TokenList([]).token_first() is None
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def test_tokenlist_token_matching():
|
| 111 |
+
t1 = sql.Token(T.Keyword, 'foo')
|
| 112 |
+
t2 = sql.Token(T.Punctuation, ',')
|
| 113 |
+
x = sql.TokenList([t1, t2])
|
| 114 |
+
assert x.token_matching([lambda t: t.ttype is T.Keyword], 0) == t1
|
| 115 |
+
assert x.token_matching([lambda t: t.ttype is T.Punctuation], 0) == t2
|
| 116 |
+
assert x.token_matching([lambda t: t.ttype is T.Keyword], 1) is None
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def test_stream_simple():
|
| 120 |
+
stream = StringIO("SELECT 1; SELECT 2;")
|
| 121 |
+
|
| 122 |
+
tokens = lexer.tokenize(stream)
|
| 123 |
+
assert len(list(tokens)) == 9
|
| 124 |
+
|
| 125 |
+
stream.seek(0)
|
| 126 |
+
tokens = list(lexer.tokenize(stream))
|
| 127 |
+
assert len(tokens) == 9
|
| 128 |
+
|
| 129 |
+
stream.seek(0)
|
| 130 |
+
tokens = list(lexer.tokenize(stream))
|
| 131 |
+
assert len(tokens) == 9
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def test_stream_error():
|
| 135 |
+
stream = StringIO("FOOBAR{")
|
| 136 |
+
|
| 137 |
+
tokens = list(lexer.tokenize(stream))
|
| 138 |
+
assert len(tokens) == 2
|
| 139 |
+
assert tokens[1][0] == T.Error
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
@pytest.mark.parametrize('expr', [
|
| 143 |
+
'JOIN',
|
| 144 |
+
'LEFT JOIN',
|
| 145 |
+
'LEFT OUTER JOIN',
|
| 146 |
+
'FULL OUTER JOIN',
|
| 147 |
+
'NATURAL JOIN',
|
| 148 |
+
'CROSS JOIN',
|
| 149 |
+
'STRAIGHT JOIN',
|
| 150 |
+
'INNER JOIN',
|
| 151 |
+
'LEFT INNER JOIN'])
|
| 152 |
+
def test_parse_join(expr):
|
| 153 |
+
p = sqlparse.parse('{} foo'.format(expr))[0]
|
| 154 |
+
assert len(p.tokens) == 3
|
| 155 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def test_parse_union(): # issue294
|
| 159 |
+
p = sqlparse.parse('UNION ALL')[0]
|
| 160 |
+
assert len(p.tokens) == 1
|
| 161 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
@pytest.mark.parametrize('s', ['END IF', 'END IF', 'END\t\nIF',
|
| 165 |
+
'END LOOP', 'END LOOP', 'END\t\nLOOP'])
|
| 166 |
+
def test_parse_endifloop(s):
|
| 167 |
+
p = sqlparse.parse(s)[0]
|
| 168 |
+
assert len(p.tokens) == 1
|
| 169 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
@pytest.mark.parametrize('s', [
|
| 173 |
+
'ASC', 'DESC',
|
| 174 |
+
'NULLS FIRST', 'NULLS LAST',
|
| 175 |
+
'ASC NULLS FIRST', 'ASC NULLS LAST',
|
| 176 |
+
'DESC NULLS FIRST', 'DESC NULLS LAST',
|
| 177 |
+
])
|
| 178 |
+
def test_parse_order(s): # issue487
|
| 179 |
+
p = sqlparse.parse(s)[0]
|
| 180 |
+
assert len(p.tokens) == 1
|
| 181 |
+
assert p.tokens[0].ttype is T.Keyword.Order
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
@pytest.mark.parametrize('s', [
|
| 185 |
+
'foo',
|
| 186 |
+
'Foo',
|
| 187 |
+
'FOO',
|
| 188 |
+
'v$name', # issue291
|
| 189 |
+
])
|
| 190 |
+
def test_parse_identifiers(s):
|
| 191 |
+
p = sqlparse.parse(s)[0]
|
| 192 |
+
assert len(p.tokens) == 1
|
| 193 |
+
token = p.tokens[0]
|
| 194 |
+
assert str(token) == s
|
| 195 |
+
assert isinstance(token, sql.Identifier)
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def test_parse_group_by():
|
| 199 |
+
p = sqlparse.parse('GROUP BY')[0]
|
| 200 |
+
assert len(p.tokens) == 1
|
| 201 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def test_parse_order_by():
|
| 205 |
+
p = sqlparse.parse('ORDER BY')[0]
|
| 206 |
+
assert len(p.tokens) == 1
|
| 207 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def test_parse_window_as():
|
| 211 |
+
p = sqlparse.parse('WINDOW w AS')[0]
|
| 212 |
+
assert len(p.tokens) == 5
|
| 213 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
@pytest.mark.parametrize('s', (
|
| 217 |
+
"LIKE", "ILIKE", "NOT LIKE", "NOT ILIKE",
|
| 218 |
+
"NOT LIKE", "NOT ILIKE",
|
| 219 |
+
))
|
| 220 |
+
def test_like_and_ilike_parsed_as_comparisons(s):
|
| 221 |
+
p = sqlparse.parse(s)[0]
|
| 222 |
+
assert len(p.tokens) == 1
|
| 223 |
+
assert p.tokens[0].ttype == T.Operator.Comparison
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
@pytest.mark.parametrize('s', (
|
| 227 |
+
"LIKEaaa", "bILIKE", "aaILIKEbb", "NOTLIKE", "NOTILIKE",
|
| 228 |
+
))
|
| 229 |
+
def test_near_like_and_ilike_parsed_appropriately(s):
|
| 230 |
+
p = sqlparse.parse(s)[0]
|
| 231 |
+
assert len(p.tokens) == 1
|
| 232 |
+
assert isinstance(p.tokens[0], sql.Identifier)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
@pytest.mark.parametrize('s', (
|
| 236 |
+
'AT TIME ZONE \'UTC\'',
|
| 237 |
+
))
|
| 238 |
+
def test_parse_tzcast(s):
|
| 239 |
+
p = sqlparse.parse(s)[0]
|
| 240 |
+
assert len(p.tokens) == 1
|
| 241 |
+
assert p.tokens[0].ttype == T.Keyword.TZCast
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def test_cli_commands():
|
| 245 |
+
p = sqlparse.parse('\\copy')[0]
|
| 246 |
+
assert len(p.tokens) == 1
|
| 247 |
+
assert p.tokens[0].ttype == T.Command
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0ytgxfff/tests/trusted/tests/test_utils.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
from sqlparse import utils
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@pytest.mark.parametrize('value, expected', (
|
| 7 |
+
[None, None],
|
| 8 |
+
['\'foo\'', 'foo'],
|
| 9 |
+
['"foo"', 'foo'],
|
| 10 |
+
['`foo`', 'foo']))
|
| 11 |
+
def test_remove_quotes(value, expected):
|
| 12 |
+
assert utils.remove_quotes(value) == expected
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0ytgxfff/validation/canaries/original-bug.sh
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
:
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0ytgxfff/validation/openenv.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"canaries": "validation/canaries",
|
| 3 |
+
"profile": "harbor-semantic-v1",
|
| 4 |
+
"requires_credentials": false,
|
| 5 |
+
"resources": {
|
| 6 |
+
"cpu": 2,
|
| 7 |
+
"disk_mb": 16384,
|
| 8 |
+
"episode_timeout_s": 1800,
|
| 9 |
+
"memory_mb": 8192
|
| 10 |
+
},
|
| 11 |
+
"reward": {
|
| 12 |
+
"floor_margin": 0.1,
|
| 13 |
+
"oracle_tolerance": 0,
|
| 14 |
+
"range": [
|
| 15 |
+
0,
|
| 16 |
+
1
|
| 17 |
+
]
|
| 18 |
+
},
|
| 19 |
+
"reward_key": "reward",
|
| 20 |
+
"types": {
|
| 21 |
+
"tags": [
|
| 22 |
+
"swe",
|
| 23 |
+
"python",
|
| 24 |
+
"mutation-repair"
|
| 25 |
+
]
|
| 26 |
+
}
|
| 27 |
+
}
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/LICENSE.source
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2016, Andi Albrecht <albrecht.andi@gmail.com>
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without modification,
|
| 5 |
+
are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright notice,
|
| 8 |
+
this list of conditions and the following disclaimer.
|
| 9 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 10 |
+
this list of conditions and the following disclaimer in the documentation
|
| 11 |
+
and/or other materials provided with the distribution.
|
| 12 |
+
* Neither the name of the authors nor the names of its contributors may be
|
| 13 |
+
used to endorse or promote products derived from this software without
|
| 14 |
+
specific prior written permission.
|
| 15 |
+
|
| 16 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 17 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 18 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 19 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
| 20 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 21 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 22 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 23 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 24 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 25 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/adapter.json
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"canary_selection": "Fixed first provided gold hunk only when at least2hunks exist; strict subset, never reward-selected. Single-hunk task original-bug canary is explicitly NOP-equivalent and adds no signal beyond floor_gap.",
|
| 3 |
+
"collector_sha256": "352e555112f2de8a1393f939903e4971c9ace0e944843762b707a725c5c72481",
|
| 4 |
+
"dependency_installation_pinned": false,
|
| 5 |
+
"dependency_setup_sha256": "2e52e9227520b938b0d5e8c191d3be78b387ebb587cb89223302ec79a00fc6c6",
|
| 6 |
+
"gold_patch_sha256": "c2db1a5d5faa728cd7c8fe1be739d7f8148826bedd46b3f662ecfe05ad46b67c",
|
| 7 |
+
"hostile_code_isolation_established": false,
|
| 8 |
+
"known_wrong_semantic_implementations": 0,
|
| 9 |
+
"native_inventory_sha256": "5075546c92574660c0edb039ff5b78c267c9dfbb372ca89a9b7487ab43947e01",
|
| 10 |
+
"new_files_deletions_and_executable_modes_supported": true,
|
| 11 |
+
"official_profile": {
|
| 12 |
+
"eval_sets": [],
|
| 13 |
+
"profile_class": "SqlparseE57923b3",
|
| 14 |
+
"profile_lines": [
|
| 15 |
+
921,
|
| 16 |
+
924
|
| 17 |
+
],
|
| 18 |
+
"profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f",
|
| 19 |
+
"profile_source_path": "swesmith/profiles/python.py",
|
| 20 |
+
"profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286",
|
| 21 |
+
"upstream_commit": "e57923b3aa823c524c807953cecc48cf6eec2cb2",
|
| 22 |
+
"upstream_repo": "andialbrecht/sqlparse"
|
| 23 |
+
},
|
| 24 |
+
"original_bug_canary_nop_equivalent": true,
|
| 25 |
+
"original_bug_runtime_wrongness_established": false,
|
| 26 |
+
"partial_repair_canary": false,
|
| 27 |
+
"partial_repair_sha256": null,
|
| 28 |
+
"partial_repair_wrongness_established": false,
|
| 29 |
+
"provided_original_bug_control": true,
|
| 30 |
+
"repo_url": "https://github.com/swesmith/andialbrecht__sqlparse.e57923b3.git",
|
| 31 |
+
"runtime_image": null,
|
| 32 |
+
"runtime_ready": false,
|
| 33 |
+
"runtime_recipe": {
|
| 34 |
+
"dependency_installation_pinned": false,
|
| 35 |
+
"official_install_cmds": [
|
| 36 |
+
"python -m pip install -e ."
|
| 37 |
+
],
|
| 38 |
+
"official_pytest_argv": [
|
| 39 |
+
"pytest",
|
| 40 |
+
"--disable-warnings",
|
| 41 |
+
"--color=no",
|
| 42 |
+
"--tb=no",
|
| 43 |
+
"--verbose"
|
| 44 |
+
],
|
| 45 |
+
"official_test_command": "source /opt/miniconda3/bin/activate; conda activate testbed; pytest --disable-warnings --color=no --tb=no --verbose",
|
| 46 |
+
"panel_normalization": "Override project addopts only to execute the exact frozen native panels; add JUnit output, preserve official pytest options and all selectors.",
|
| 47 |
+
"python_version": "3.10",
|
| 48 |
+
"source_bound_test_dependency_cmds": [
|
| 49 |
+
"python -m pip install pytest"
|
| 50 |
+
],
|
| 51 |
+
"test_dependency_source_sha256": {
|
| 52 |
+
"pyproject.toml": "f45ed1a6a2c302a1b5a63cba825e9ad451c511427317faf52cf94492cb9f3144"
|
| 53 |
+
}
|
| 54 |
+
},
|
| 55 |
+
"runtime_resource_review_required": false,
|
| 56 |
+
"schema": "python-git-patch-jobs-v1",
|
| 57 |
+
"source_base_commit": "d2dc9af40ebbd7e109b5c549fd80de8e9bcbee2d",
|
| 58 |
+
"source_completion_sha256": "535fea9c295e324b6614c71eeb6e56f8304ee8d168dddd724d93149020a06dba",
|
| 59 |
+
"source_index_sha256": "a8bacb23b190ac8227d8d322773176a10ed65e6b16cccd869cb625a465522876",
|
| 60 |
+
"source_pr_url": null,
|
| 61 |
+
"source_record": {
|
| 62 |
+
"anti_training_canary": false,
|
| 63 |
+
"anti_training_reviewed": true,
|
| 64 |
+
"candidate_id": "swesmith-py:andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky",
|
| 65 |
+
"cloud_launch_ready": false,
|
| 66 |
+
"eligibility": {
|
| 67 |
+
"reasons": [],
|
| 68 |
+
"semantic_nonoverlap_established": false,
|
| 69 |
+
"status": "eligible_for_controls",
|
| 70 |
+
"training_admissible": false,
|
| 71 |
+
"warnings": []
|
| 72 |
+
},
|
| 73 |
+
"healthy_mirror_commit": "d802518f3673051449163fc84fe1455448f79b3b",
|
| 74 |
+
"instruction_sha256": "22a97bfee4be839b24bba2990225421f6864528da5588ad59d23cafae4a7bf4b",
|
| 75 |
+
"is_fork": true,
|
| 76 |
+
"learner_path": "tasks/cfbfcdb7704d2b47a19931a3/learner",
|
| 77 |
+
"license_evidence": {
|
| 78 |
+
"source_code": {
|
| 79 |
+
"actual_upstream_commit": "e57923b3aa823c524c807953cecc48cf6eec2cb2",
|
| 80 |
+
"actual_upstream_url": "https://raw.githubusercontent.com/andialbrecht/sqlparse/e57923b3aa823c524c807953cecc48cf6eec2cb2/LICENSE",
|
| 81 |
+
"reviewed": true,
|
| 82 |
+
"sha256": "c1938235b80d39e93138eae89edc3af67e18ecbc40d266529fa57b2dce426310",
|
| 83 |
+
"spdx": "BSD-3-Clause",
|
| 84 |
+
"training_allowed": true,
|
| 85 |
+
"url": "https://raw.githubusercontent.com/swesmith/andialbrecht__sqlparse.e57923b3/d2dc9af40ebbd7e109b5c549fd80de8e9bcbee2d/LICENSE"
|
| 86 |
+
},
|
| 87 |
+
"task_bundle": {
|
| 88 |
+
"reviewed": true,
|
| 89 |
+
"sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808",
|
| 90 |
+
"spdx": "MIT",
|
| 91 |
+
"training_allowed": true,
|
| 92 |
+
"url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md"
|
| 93 |
+
}
|
| 94 |
+
},
|
| 95 |
+
"original_source_commit": "e57923b3aa823c524c807953cecc48cf6eec2cb2",
|
| 96 |
+
"patch_sha256": "82c507cd8533e0f0975e86b6f20aa802f9f5e23726bf98648e36e5ffb2a57f11",
|
| 97 |
+
"provenance_path": "tasks/cfbfcdb7704d2b47a19931a3/source-proof.json",
|
| 98 |
+
"repository_lineage": [
|
| 99 |
+
"swesmith/andialbrecht__sqlparse.e57923b3",
|
| 100 |
+
"andialbrecht/sqlparse"
|
| 101 |
+
],
|
| 102 |
+
"rfc008_complete": false,
|
| 103 |
+
"runtime_qualified": false,
|
| 104 |
+
"semantic_nonoverlap_established": false,
|
| 105 |
+
"source_commit": "d2dc9af40ebbd7e109b5c549fd80de8e9bcbee2d",
|
| 106 |
+
"source_dataset": "SWE-bench/SWE-smith-py",
|
| 107 |
+
"source_head_commit": "847515f1ec7cf0a3e76b4e89f1c26198c4cf0519",
|
| 108 |
+
"source_kind": "mutation",
|
| 109 |
+
"source_repo": "swesmith/andialbrecht__sqlparse.e57923b3",
|
| 110 |
+
"source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e",
|
| 111 |
+
"source_split": "train",
|
| 112 |
+
"target_model_calibrated": false,
|
| 113 |
+
"task_id": "andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky",
|
| 114 |
+
"task_sha256": "28af98c3ad20f79631e694193f4fd20fc4dd73f46175235e3b283a5216a4323e",
|
| 115 |
+
"training_admissible": false,
|
| 116 |
+
"upstream_identity_reviewed": true,
|
| 117 |
+
"upstream_repo": "andialbrecht/sqlparse",
|
| 118 |
+
"usage": "quarantine_only"
|
| 119 |
+
},
|
| 120 |
+
"source_repo": "swesmith/andialbrecht__sqlparse.e57923b3",
|
| 121 |
+
"symlink_submodule_changes_supported": false,
|
| 122 |
+
"task_id": "andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky",
|
| 123 |
+
"transfer": "index-independent-worktree-to-Git-binary-patch",
|
| 124 |
+
"transfer_path": "/testbed/submission.patch",
|
| 125 |
+
"upstream_repo": "andialbrecht/sqlparse"
|
| 126 |
+
}
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/dependency-setup.sh
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
source /opt/miniconda3/bin/activate
|
| 4 |
+
conda activate testbed
|
| 5 |
+
cd /testbed/repo
|
| 6 |
+
python -c 'import sys; assert sys.version_info[:2] == (3, 10)'
|
| 7 |
+
python -m pip install -e .
|
| 8 |
+
python -m pip install pytest
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/environment/Dockerfile
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Runtime is selected only by an independently qualified immutable amd64 receipt.
|
| 2 |
+
FROM ubuntu:22.04
|
| 3 |
+
RUN false
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/instruction.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Array index extraction returns incorrect tokens
|
| 2 |
+
|
| 3 |
+
#### Description
|
| 4 |
+
|
| 5 |
+
When parsing SQL identifiers with array indices, the `get_array_indices()` method returns incorrect tokens. Instead of extracting just the content inside square brackets, it's including the opening bracket and excluding the closing bracket.
|
| 6 |
+
|
| 7 |
+
#### Steps/Code to Reproduce
|
| 8 |
+
|
| 9 |
+
```python
|
| 10 |
+
import sqlparse
|
| 11 |
+
|
| 12 |
+
# Simple array index
|
| 13 |
+
p = sqlparse.parse('col[1]')[0].tokens
|
| 14 |
+
identifier = p[0]
|
| 15 |
+
indices = list(identifier.get_array_indices())
|
| 16 |
+
print("Expected: '1'")
|
| 17 |
+
print(f"Actual: '{indices[0][0].value}'")
|
| 18 |
+
|
| 19 |
+
# Schema qualified array index
|
| 20 |
+
p = sqlparse.parse('schema.col[1]')[0].tokens
|
| 21 |
+
identifier = p[0]
|
| 22 |
+
indices = list(identifier.get_array_indices())
|
| 23 |
+
print("Expected: '1'")
|
| 24 |
+
print(f"Actual: '{indices[0][0].value}'")
|
| 25 |
+
|
| 26 |
+
# Aliased array index
|
| 27 |
+
p = sqlparse.parse('col[1] x')[0].tokens
|
| 28 |
+
identifier = p[0]
|
| 29 |
+
indices = list(identifier.get_array_indices())
|
| 30 |
+
print("Expected: '1'")
|
| 31 |
+
print(f"Actual: '{indices[0][0].value}'")
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
The method should return the tokens representing the array index content (e.g., '1'), but instead returns tokens that include the opening bracket.
|
| 35 |
+
|
| 36 |
+
## Environment
|
| 37 |
+
|
| 38 |
+
The repository is at `/testbed/repo`. Its dependencies, including pytest, are installed in the `testbed` conda environment, which comes first on PATH. If `python -m pytest` reports that pytest is missing, use the full interpreter path: `/opt/miniconda3/envs/testbed/bin/python -m pytest <tests>`. Don't install packages: the tests need nothing else, and the sandbox may have no network access.
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/metadata.json
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"all_runtime_and_training_flags": false,
|
| 3 |
+
"official_profile": {
|
| 4 |
+
"eval_sets": [],
|
| 5 |
+
"profile_class": "SqlparseE57923b3",
|
| 6 |
+
"profile_lines": [
|
| 7 |
+
921,
|
| 8 |
+
924
|
| 9 |
+
],
|
| 10 |
+
"profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f",
|
| 11 |
+
"profile_source_path": "swesmith/profiles/python.py",
|
| 12 |
+
"profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286",
|
| 13 |
+
"upstream_commit": "e57923b3aa823c524c807953cecc48cf6eec2cb2",
|
| 14 |
+
"upstream_repo": "andialbrecht/sqlparse"
|
| 15 |
+
},
|
| 16 |
+
"source_healthy_reference_proof": {
|
| 17 |
+
"FAIL_TO_PASS": [
|
| 18 |
+
"tests/test_parse.py::test_simple_1d_array_index",
|
| 19 |
+
"tests/test_parse.py::test_schema_qualified_array_index",
|
| 20 |
+
"tests/test_parse.py::test_aliased_array_index"
|
| 21 |
+
],
|
| 22 |
+
"PASS_TO_PASS": [
|
| 23 |
+
"tests/test_cli.py::test_cli_main_empty",
|
| 24 |
+
"tests/test_cli.py::test_parser_empty",
|
| 25 |
+
"tests/test_cli.py::test_main_help",
|
| 26 |
+
"tests/test_cli.py::test_valid_args",
|
| 27 |
+
"tests/test_cli.py::test_invalid_choice",
|
| 28 |
+
"tests/test_cli.py::test_invalid_args",
|
| 29 |
+
"tests/test_cli.py::test_invalid_infile",
|
| 30 |
+
"tests/test_cli.py::test_invalid_outfile",
|
| 31 |
+
"tests/test_cli.py::test_stdout",
|
| 32 |
+
"tests/test_cli.py::test_script",
|
| 33 |
+
"tests/test_cli.py::test_encoding_stdout[encoding_utf8.sql-utf-8]",
|
| 34 |
+
"tests/test_cli.py::test_encoding_stdout[encoding_gbk.sql-gbk]",
|
| 35 |
+
"tests/test_cli.py::test_encoding_output_file[encoding_utf8.sql-utf-8]",
|
| 36 |
+
"tests/test_cli.py::test_encoding_output_file[encoding_gbk.sql-gbk]",
|
| 37 |
+
"tests/test_cli.py::test_encoding_stdin[encoding_utf8.sql-utf-8]",
|
| 38 |
+
"tests/test_cli.py::test_encoding_stdin[encoding_gbk.sql-gbk]",
|
| 39 |
+
"tests/test_cli.py::test_encoding",
|
| 40 |
+
"tests/test_format.py::TestFormat::test_keywordcase",
|
| 41 |
+
"tests/test_format.py::TestFormat::test_keywordcase_invalid_option",
|
| 42 |
+
"tests/test_format.py::TestFormat::test_identifiercase",
|
| 43 |
+
"tests/test_format.py::TestFormat::test_identifiercase_invalid_option",
|
| 44 |
+
"tests/test_format.py::TestFormat::test_identifiercase_quotes",
|
| 45 |
+
"tests/test_format.py::TestFormat::test_strip_comments_single",
|
| 46 |
+
"tests/test_format.py::TestFormat::test_strip_comments_invalid_option",
|
| 47 |
+
"tests/test_format.py::TestFormat::test_strip_comments_multi",
|
| 48 |
+
"tests/test_format.py::TestFormat::test_strip_comments_preserves_linebreak",
|
| 49 |
+
"tests/test_format.py::TestFormat::test_strip_comments_preserves_whitespace",
|
| 50 |
+
"tests/test_format.py::TestFormat::test_strip_comments_preserves_hint",
|
| 51 |
+
"tests/test_format.py::TestFormat::test_strip_ws",
|
| 52 |
+
"tests/test_format.py::TestFormat::test_strip_ws_invalid_option",
|
| 53 |
+
"tests/test_format.py::TestFormat::test_preserve_ws",
|
| 54 |
+
"tests/test_format.py::TestFormat::test_notransform_of_quoted_crlf",
|
| 55 |
+
"tests/test_format.py::TestFormatReindentAligned::test_basic",
|
| 56 |
+
"tests/test_format.py::TestFormatReindentAligned::test_joins",
|
| 57 |
+
"tests/test_format.py::TestFormatReindentAligned::test_case_statement",
|
| 58 |
+
"tests/test_format.py::TestFormatReindentAligned::test_case_statement_with_between",
|
| 59 |
+
"tests/test_format.py::TestFormatReindentAligned::test_group_by",
|
| 60 |
+
"tests/test_format.py::TestFormatReindentAligned::test_group_by_subquery",
|
| 61 |
+
"tests/test_format.py::TestFormatReindentAligned::test_window_functions",
|
| 62 |
+
"tests/test_format.py::TestSpacesAroundOperators::test_basic",
|
| 63 |
+
"tests/test_format.py::TestSpacesAroundOperators::test_bools",
|
| 64 |
+
"tests/test_format.py::TestSpacesAroundOperators::test_nested",
|
| 65 |
+
"tests/test_format.py::TestSpacesAroundOperators::test_wildcard_vs_mult",
|
| 66 |
+
"tests/test_format.py::TestFormatReindent::test_option",
|
| 67 |
+
"tests/test_format.py::TestFormatReindent::test_stmts",
|
| 68 |
+
"tests/test_format.py::TestFormatReindent::test_keywords",
|
| 69 |
+
"tests/test_format.py::TestFormatReindent::test_keywords_between",
|
| 70 |
+
"tests/test_format.py::TestFormatReindent::test_parenthesis",
|
| 71 |
+
"tests/test_format.py::TestFormatReindent::test_where",
|
| 72 |
+
"tests/test_format.py::TestFormatReindent::test_join",
|
| 73 |
+
"tests/test_format.py::TestFormatReindent::test_identifier_list",
|
| 74 |
+
"tests/test_format.py::TestFormatReindent::test_identifier_list_with_wrap_after",
|
| 75 |
+
"tests/test_format.py::TestFormatReindent::test_identifier_list_comment_first",
|
| 76 |
+
"tests/test_format.py::TestFormatReindent::test_identifier_list_with_functions",
|
| 77 |
+
"tests/test_format.py::TestFormatReindent::test_long_identifier_list_with_functions",
|
| 78 |
+
"tests/test_format.py::TestFormatReindent::test_case",
|
| 79 |
+
"tests/test_format.py::TestFormatReindent::test_case2",
|
| 80 |
+
"tests/test_format.py::TestFormatReindent::test_nested_identifier_list",
|
| 81 |
+
"tests/test_format.py::TestFormatReindent::test_duplicate_linebreaks",
|
| 82 |
+
"tests/test_format.py::TestFormatReindent::test_keywordfunctions",
|
| 83 |
+
"tests/test_format.py::TestFormatReindent::test_identifier_and_functions",
|
| 84 |
+
"tests/test_format.py::TestFormatReindent::test_insert_values",
|
| 85 |
+
"tests/test_format.py::TestOutputFormat::test_python",
|
| 86 |
+
"tests/test_format.py::TestOutputFormat::test_python_multiple_statements",
|
| 87 |
+
"tests/test_format.py::TestOutputFormat::test_php",
|
| 88 |
+
"tests/test_format.py::TestOutputFormat::test_sql",
|
| 89 |
+
"tests/test_format.py::TestOutputFormat::test_invalid_option",
|
| 90 |
+
"tests/test_format.py::test_format_column_ordering",
|
| 91 |
+
"tests/test_format.py::test_truncate_strings",
|
| 92 |
+
"tests/test_format.py::test_truncate_strings_invalid_option2[bar]",
|
| 93 |
+
"tests/test_format.py::test_truncate_strings_invalid_option2[-1]",
|
| 94 |
+
"tests/test_format.py::test_truncate_strings_invalid_option2[0]",
|
| 95 |
+
"tests/test_format.py::test_having_produces_newline",
|
| 96 |
+
"tests/test_format.py::test_format_right_margin_invalid_option[ten]",
|
| 97 |
+
"tests/test_format.py::test_format_right_margin_invalid_option[2]",
|
| 98 |
+
"tests/test_format.py::test_format_json_ops",
|
| 99 |
+
"tests/test_format.py::test_strip_ws_removes_trailing_ws_in_groups",
|
| 100 |
+
"tests/test_grouping.py::test_grouping_parenthesis",
|
| 101 |
+
"tests/test_grouping.py::test_grouping_identifiers",
|
| 102 |
+
"tests/test_grouping.py::test_grouping_identifier_wildcard",
|
| 103 |
+
"tests/test_grouping.py::test_grouping_identifier_name_wildcard",
|
| 104 |
+
"tests/test_grouping.py::test_grouping_identifier_invalid",
|
| 105 |
+
"tests/test_grouping.py::test_grouping_identifier_invalid_in_middle",
|
| 106 |
+
"tests/test_grouping.py::test_grouping_identifier_as_invalid",
|
| 107 |
+
"tests/test_grouping.py::test_grouping_identifier_function",
|
| 108 |
+
"tests/test_grouping.py::test_grouping_operation[foo+100]",
|
| 109 |
+
"tests/test_grouping.py::test_grouping_operation[foo*100]",
|
| 110 |
+
"tests/test_grouping.py::test_grouping_identifier_list",
|
| 111 |
+
"tests/test_grouping.py::test_grouping_identifier_list_subquery",
|
| 112 |
+
"tests/test_grouping.py::test_grouping_identifier_list_case",
|
| 113 |
+
"tests/test_grouping.py::test_grouping_identifier_list_other",
|
| 114 |
+
"tests/test_grouping.py::test_grouping_identifier_list_with_inline_comments",
|
| 115 |
+
"tests/test_grouping.py::test_grouping_identifiers_with_operators",
|
| 116 |
+
"tests/test_grouping.py::test_grouping_identifier_list_with_order",
|
| 117 |
+
"tests/test_grouping.py::test_grouping_nested_identifier_with_order",
|
| 118 |
+
"tests/test_grouping.py::test_grouping_where",
|
| 119 |
+
"tests/test_grouping.py::test_returning_kw_ends_where_clause",
|
| 120 |
+
"tests/test_grouping.py::test_into_kw_ends_where_clause",
|
| 121 |
+
"tests/test_grouping.py::test_grouping_alias",
|
| 122 |
+
"tests/test_grouping.py::test_grouping_alias_case",
|
| 123 |
+
"tests/test_grouping.py::test_grouping_alias_ctas",
|
| 124 |
+
"tests/test_grouping.py::test_grouping_subquery_no_parens",
|
| 125 |
+
"tests/test_grouping.py::test_grouping_alias_returns_none[foo.bar]",
|
| 126 |
+
"tests/test_grouping.py::test_grouping_idlist_function",
|
| 127 |
+
"tests/test_grouping.py::test_grouping_comparison_exclude",
|
| 128 |
+
"tests/test_grouping.py::test_grouping_function",
|
| 129 |
+
"tests/test_grouping.py::test_grouping_function_not_in",
|
| 130 |
+
"tests/test_grouping.py::test_grouping_varchar",
|
| 131 |
+
"tests/test_grouping.py::test_statement_get_type",
|
| 132 |
+
"tests/test_grouping.py::test_identifier_with_operators",
|
| 133 |
+
"tests/test_grouping.py::test_identifier_with_op_trailing_ws",
|
| 134 |
+
"tests/test_grouping.py::test_identifier_with_string_literals",
|
| 135 |
+
"tests/test_grouping.py::test_identifier_consumes_ordering",
|
| 136 |
+
"tests/test_grouping.py::test_comparison_with_keywords",
|
| 137 |
+
"tests/test_grouping.py::test_comparison_with_floats",
|
| 138 |
+
"tests/test_grouping.py::test_comparison_with_parenthesis",
|
| 139 |
+
"tests/test_grouping.py::test_comparison_with_strings[=]",
|
| 140 |
+
"tests/test_grouping.py::test_comparison_with_strings[!=]",
|
| 141 |
+
"tests/test_grouping.py::test_comparison_with_strings[>]",
|
| 142 |
+
"tests/test_grouping.py::test_comparison_with_strings[<]",
|
| 143 |
+
"tests/test_grouping.py::test_comparison_with_strings[<=]",
|
| 144 |
+
"tests/test_grouping.py::test_comparison_with_strings[>=]",
|
| 145 |
+
"tests/test_grouping.py::test_comparison_with_strings[~]",
|
| 146 |
+
"tests/test_grouping.py::test_comparison_with_strings[~~]",
|
| 147 |
+
"tests/test_grouping.py::test_comparison_with_strings[!~~]",
|
| 148 |
+
"tests/test_grouping.py::test_comparison_with_strings[LIKE]",
|
| 149 |
+
"tests/test_grouping.py::test_comparison_with_strings[ILIKE]",
|
| 150 |
+
"tests/test_grouping.py::test_like_and_ilike_comparison",
|
| 151 |
+
"tests/test_grouping.py::test_comparison_with_functions",
|
| 152 |
+
"tests/test_grouping.py::test_comparison_with_typed_literal",
|
| 153 |
+
"tests/test_grouping.py::test_forloops[FOR]",
|
| 154 |
+
"tests/test_grouping.py::test_forloops[FOREACH]",
|
| 155 |
+
"tests/test_grouping.py::test_nested_for",
|
| 156 |
+
"tests/test_grouping.py::test_begin",
|
| 157 |
+
"tests/test_grouping.py::test_keyword_followed_by_parenthesis",
|
| 158 |
+
"tests/test_grouping.py::test_nested_begin",
|
| 159 |
+
"tests/test_grouping.py::test_aliased_column_without_as",
|
| 160 |
+
"tests/test_grouping.py::test_qualified_function",
|
| 161 |
+
"tests/test_grouping.py::test_aliased_function_without_as",
|
| 162 |
+
"tests/test_grouping.py::test_aliased_literal_without_as",
|
| 163 |
+
"tests/test_grouping.py::test_grouping_as_cte",
|
| 164 |
+
"tests/test_grouping.py::test_grouping_create_table",
|
| 165 |
+
"tests/test_keywords.py::TestSQLREGEX::test_float_numbers[1.0]",
|
| 166 |
+
"tests/test_keywords.py::TestSQLREGEX::test_float_numbers[-1.0]",
|
| 167 |
+
"tests/test_keywords.py::TestSQLREGEX::test_float_numbers[1.]",
|
| 168 |
+
"tests/test_keywords.py::TestSQLREGEX::test_float_numbers[-1.]",
|
| 169 |
+
"tests/test_keywords.py::TestSQLREGEX::test_float_numbers[.1]",
|
| 170 |
+
"tests/test_keywords.py::TestSQLREGEX::test_float_numbers[-.1]",
|
| 171 |
+
"tests/test_parse.py::test_parse_tokenize",
|
| 172 |
+
"tests/test_parse.py::test_parse_multistatement",
|
| 173 |
+
"tests/test_parse.py::test_parse_within",
|
| 174 |
+
"tests/test_parse.py::test_parse_child_of",
|
| 175 |
+
"tests/test_parse.py::test_parse_has_ancestor",
|
| 176 |
+
"tests/test_parse.py::test_parse_float[.5]",
|
| 177 |
+
"tests/test_parse.py::test_parse_float[.51]",
|
| 178 |
+
"tests/test_parse.py::test_parse_float[1.5]",
|
| 179 |
+
"tests/test_parse.py::test_parse_float[12.5]",
|
| 180 |
+
"tests/test_parse.py::test_parse_modulo_not_placeholder",
|
| 181 |
+
"tests/test_parse.py::test_parse_access_symbol",
|
| 182 |
+
"tests/test_parse.py::test_parse_square_brackets_notation_isnt_too_greedy",
|
| 183 |
+
"tests/test_parse.py::test_parse_square_brackets_notation_isnt_too_greedy2",
|
| 184 |
+
"tests/test_parse.py::test_parse_keyword_like_identifier",
|
| 185 |
+
"tests/test_parse.py::test_parse_function_parameter",
|
| 186 |
+
"tests/test_parse.py::test_parse_function_param_single_literal",
|
| 187 |
+
"tests/test_parse.py::test_parse_nested_function",
|
| 188 |
+
"tests/test_parse.py::test_parse_casted_params",
|
| 189 |
+
"tests/test_parse.py::test_parse_div_operator",
|
| 190 |
+
"tests/test_parse.py::test_quoted_identifier",
|
| 191 |
+
"tests/test_parse.py::test_valid_identifier_names[foo]",
|
| 192 |
+
"tests/test_parse.py::test_valid_identifier_names[_foo]",
|
| 193 |
+
"tests/test_parse.py::test_valid_identifier_names[1_data]",
|
| 194 |
+
"tests/test_parse.py::test_valid_identifier_names[\\u696d\\u8005\\u540d\\u7a31]",
|
| 195 |
+
"tests/test_parse.py::test_psql_quotation_marks",
|
| 196 |
+
"tests/test_parse.py::test_double_precision_is_builtin",
|
| 197 |
+
"tests/test_parse.py::test_placeholder[?]",
|
| 198 |
+
"tests/test_parse.py::test_placeholder[:1]",
|
| 199 |
+
"tests/test_parse.py::test_placeholder[:foo]",
|
| 200 |
+
"tests/test_parse.py::test_placeholder[%s]",
|
| 201 |
+
"tests/test_parse.py::test_placeholder[%(foo)s]",
|
| 202 |
+
"tests/test_parse.py::test_scientific_numbers[6.67428E-8-expected0]",
|
| 203 |
+
"tests/test_parse.py::test_scientific_numbers[1.988e33-expected1]",
|
| 204 |
+
"tests/test_parse.py::test_scientific_numbers[1e-12-expected2]",
|
| 205 |
+
"tests/test_parse.py::test_scientific_numbers[e1-None]",
|
| 206 |
+
"tests/test_parse.py::test_single_quotes_are_strings",
|
| 207 |
+
"tests/test_parse.py::test_double_quotes_are_identifiers",
|
| 208 |
+
"tests/test_parse.py::test_single_quotes_with_linebreaks",
|
| 209 |
+
"tests/test_parse.py::test_sqlite_identifiers",
|
| 210 |
+
"tests/test_parse.py::test_2d_array_index",
|
| 211 |
+
"tests/test_parse.py::test_array_index_function_result",
|
| 212 |
+
"tests/test_parse.py::test_array_literal",
|
| 213 |
+
"tests/test_parse.py::test_typed_array_definition",
|
| 214 |
+
"tests/test_parse.py::test_names_and_special_names[foo]",
|
| 215 |
+
"tests/test_parse.py::test_names_and_special_names[@foo]",
|
| 216 |
+
"tests/test_parse.py::test_names_and_special_names[#foo]",
|
| 217 |
+
"tests/test_parse.py::test_names_and_special_names[##foo]",
|
| 218 |
+
"tests/test_parse.py::test_get_token_at_offset",
|
| 219 |
+
"tests/test_parse.py::test_pprint",
|
| 220 |
+
"tests/test_parse.py::test_wildcard_multiplication",
|
| 221 |
+
"tests/test_parse.py::test_stmt_tokens_parents",
|
| 222 |
+
"tests/test_parse.py::test_dbldollar_as_literal[$$foo$$-True]",
|
| 223 |
+
"tests/test_parse.py::test_dbldollar_as_literal[$_$foo$_$-True]",
|
| 224 |
+
"tests/test_parse.py::test_non_ascii",
|
| 225 |
+
"tests/test_parse.py::test_get_real_name",
|
| 226 |
+
"tests/test_parse.py::test_from_subquery",
|
| 227 |
+
"tests/test_parse.py::test_parenthesis",
|
| 228 |
+
"tests/test_parse.py::test_configurable_keywords",
|
| 229 |
+
"tests/test_parse.py::test_configurable_regex",
|
| 230 |
+
"tests/test_parse.py::test_json_operators[->]",
|
| 231 |
+
"tests/test_parse.py::test_json_operators[->>]",
|
| 232 |
+
"tests/test_parse.py::test_json_operators[#>]",
|
| 233 |
+
"tests/test_parse.py::test_json_operators[#>>]",
|
| 234 |
+
"tests/test_parse.py::test_json_operators[@>]",
|
| 235 |
+
"tests/test_parse.py::test_json_operators[<@]",
|
| 236 |
+
"tests/test_parse.py::test_json_operators[||]",
|
| 237 |
+
"tests/test_parse.py::test_json_operators[-]",
|
| 238 |
+
"tests/test_parse.py::test_json_operators[#-]",
|
| 239 |
+
"tests/test_regressions.py::test_issue9",
|
| 240 |
+
"tests/test_regressions.py::test_issue13",
|
| 241 |
+
"tests/test_regressions.py::test_issue26[--hello]",
|
| 242 |
+
"tests/test_regressions.py::test_issue26[--hello\\n]",
|
| 243 |
+
"tests/test_regressions.py::test_issue26[--]",
|
| 244 |
+
"tests/test_regressions.py::test_issue26[--\\n]",
|
| 245 |
+
"tests/test_regressions.py::test_issue34[create]",
|
| 246 |
+
"tests/test_regressions.py::test_issue34[CREATE]",
|
| 247 |
+
"tests/test_regressions.py::test_issue35",
|
| 248 |
+
"tests/test_regressions.py::test_issue38",
|
| 249 |
+
"tests/test_regressions.py::test_issue39",
|
| 250 |
+
"tests/test_regressions.py::test_issue40",
|
| 251 |
+
"tests/test_regressions.py::test_issue83",
|
| 252 |
+
"tests/test_regressions.py::test_comment_encoding_when_reindent",
|
| 253 |
+
"tests/test_regressions.py::test_parse_sql_with_binary",
|
| 254 |
+
"tests/test_regressions.py::test_dont_alias_keywords",
|
| 255 |
+
"tests/test_regressions.py::test_format_accepts_encoding",
|
| 256 |
+
"tests/test_regressions.py::test_stream",
|
| 257 |
+
"tests/test_regressions.py::test_issue90",
|
| 258 |
+
"tests/test_regressions.py::test_except_formatting",
|
| 259 |
+
"tests/test_regressions.py::test_null_with_as",
|
| 260 |
+
"tests/test_regressions.py::test_issue190_open_file",
|
| 261 |
+
"tests/test_regressions.py::test_issue193_splitting_function",
|
| 262 |
+
"tests/test_regressions.py::test_issue194_splitting_function",
|
| 263 |
+
"tests/test_regressions.py::test_issue186_get_type",
|
| 264 |
+
"tests/test_regressions.py::test_issue212_py2unicode",
|
| 265 |
+
"tests/test_regressions.py::test_issue213_leadingws",
|
| 266 |
+
"tests/test_regressions.py::test_issue227_gettype_cte",
|
| 267 |
+
"tests/test_regressions.py::test_issue207_runaway_format",
|
| 268 |
+
"tests/test_regressions.py::test_token_next_doesnt_ignore_skip_cm",
|
| 269 |
+
"tests/test_regressions.py::test_issue284_as_grouping[AS]",
|
| 270 |
+
"tests/test_regressions.py::test_issue315_utf8_by_default",
|
| 271 |
+
"tests/test_regressions.py::test_issue322_concurrently_is_keyword",
|
| 272 |
+
"tests/test_regressions.py::test_issue469_copy_as_psql_command",
|
| 273 |
+
"tests/test_regressions.py::test_issue485_split_multi",
|
| 274 |
+
"tests/test_regressions.py::test_issue489_tzcasts",
|
| 275 |
+
"tests/test_regressions.py::test_issue562_tzcasts",
|
| 276 |
+
"tests/test_regressions.py::test_as_in_parentheses_indents",
|
| 277 |
+
"tests/test_regressions.py::test_format_invalid_where_clause",
|
| 278 |
+
"tests/test_regressions.py::test_splitting_at_and_backticks_issue588",
|
| 279 |
+
"tests/test_regressions.py::test_comment_between_cte_clauses_issue632",
|
| 280 |
+
"tests/test_regressions.py::test_copy_issue672",
|
| 281 |
+
"tests/test_regressions.py::test_primary_key_issue740",
|
| 282 |
+
"tests/test_regressions.py::test_max_recursion",
|
| 283 |
+
"tests/test_split.py::test_split_semicolon",
|
| 284 |
+
"tests/test_split.py::test_split_backslash",
|
| 285 |
+
"tests/test_split.py::test_split_create_function[function.sql]",
|
| 286 |
+
"tests/test_split.py::test_split_create_function[function_psql.sql]",
|
| 287 |
+
"tests/test_split.py::test_split_create_function[function_psql2.sql]",
|
| 288 |
+
"tests/test_split.py::test_split_create_function[function_psql3.sql]",
|
| 289 |
+
"tests/test_split.py::test_split_create_function[function_psql4.sql]",
|
| 290 |
+
"tests/test_split.py::test_split_dashcomments",
|
| 291 |
+
"tests/test_split.py::test_split_begintag",
|
| 292 |
+
"tests/test_split.py::test_split_begintag_2",
|
| 293 |
+
"tests/test_split.py::test_split_dropif",
|
| 294 |
+
"tests/test_split.py::test_split_comment_with_umlaut",
|
| 295 |
+
"tests/test_split.py::test_split_comment_end_of_line",
|
| 296 |
+
"tests/test_split.py::test_split_casewhen",
|
| 297 |
+
"tests/test_split.py::test_split_casewhen_procedure",
|
| 298 |
+
"tests/test_split.py::test_split_cursor_declare",
|
| 299 |
+
"tests/test_split.py::test_split_if_function",
|
| 300 |
+
"tests/test_split.py::test_split_stream",
|
| 301 |
+
"tests/test_split.py::test_split_encoding_parsestream",
|
| 302 |
+
"tests/test_split.py::test_split_unicode_parsestream",
|
| 303 |
+
"tests/test_split.py::test_split_simple",
|
| 304 |
+
"tests/test_split.py::test_split_ignores_empty_newlines",
|
| 305 |
+
"tests/test_split.py::test_split_quotes_with_new_line",
|
| 306 |
+
"tests/test_split.py::test_split_mysql_handler_for",
|
| 307 |
+
"tests/test_split.py::test_split_strip_semicolon_procedure",
|
| 308 |
+
"tests/test_split.py::test_split_multiple_case_in_begin",
|
| 309 |
+
"tests/test_tokenize.py::test_tokenize_simple",
|
| 310 |
+
"tests/test_tokenize.py::test_tokenize_backticks",
|
| 311 |
+
"tests/test_tokenize.py::test_tokenize_linebreaks[foo\\nbar\\n]",
|
| 312 |
+
"tests/test_tokenize.py::test_tokenize_linebreaks[foo\\rbar\\r]",
|
| 313 |
+
"tests/test_tokenize.py::test_tokenize_linebreaks[foo\\r\\nbar\\r\\n]",
|
| 314 |
+
"tests/test_tokenize.py::test_tokenize_linebreaks[foo\\r\\nbar\\n]",
|
| 315 |
+
"tests/test_tokenize.py::test_tokenize_inline_keywords",
|
| 316 |
+
"tests/test_tokenize.py::test_tokenize_negative_numbers",
|
| 317 |
+
"tests/test_tokenize.py::test_token_str",
|
| 318 |
+
"tests/test_tokenize.py::test_token_repr",
|
| 319 |
+
"tests/test_tokenize.py::test_token_flatten",
|
| 320 |
+
"tests/test_tokenize.py::test_tokenlist_repr",
|
| 321 |
+
"tests/test_tokenize.py::test_single_quotes",
|
| 322 |
+
"tests/test_tokenize.py::test_tokenlist_first",
|
| 323 |
+
"tests/test_tokenize.py::test_tokenlist_token_matching",
|
| 324 |
+
"tests/test_tokenize.py::test_stream_simple",
|
| 325 |
+
"tests/test_tokenize.py::test_stream_error",
|
| 326 |
+
"tests/test_tokenize.py::test_parse_join[JOIN]",
|
| 327 |
+
"tests/test_tokenize.py::test_parse_union",
|
| 328 |
+
"tests/test_tokenize.py::test_parse_endifloop[END\\t\\nIF]",
|
| 329 |
+
"tests/test_tokenize.py::test_parse_endifloop[END\\t\\nLOOP]",
|
| 330 |
+
"tests/test_tokenize.py::test_parse_order[ASC]",
|
| 331 |
+
"tests/test_tokenize.py::test_parse_order[DESC]",
|
| 332 |
+
"tests/test_tokenize.py::test_parse_identifiers[foo]",
|
| 333 |
+
"tests/test_tokenize.py::test_parse_identifiers[Foo]",
|
| 334 |
+
"tests/test_tokenize.py::test_parse_identifiers[FOO]",
|
| 335 |
+
"tests/test_tokenize.py::test_parse_identifiers[v$name]",
|
| 336 |
+
"tests/test_tokenize.py::test_parse_group_by",
|
| 337 |
+
"tests/test_tokenize.py::test_parse_order_by",
|
| 338 |
+
"tests/test_tokenize.py::test_parse_window_as",
|
| 339 |
+
"tests/test_tokenize.py::test_like_and_ilike_parsed_as_comparisons[LIKE]",
|
| 340 |
+
"tests/test_tokenize.py::test_like_and_ilike_parsed_as_comparisons[ILIKE]",
|
| 341 |
+
"tests/test_tokenize.py::test_near_like_and_ilike_parsed_appropriately[LIKEaaa]",
|
| 342 |
+
"tests/test_tokenize.py::test_near_like_and_ilike_parsed_appropriately[bILIKE]",
|
| 343 |
+
"tests/test_tokenize.py::test_near_like_and_ilike_parsed_appropriately[aaILIKEbb]",
|
| 344 |
+
"tests/test_tokenize.py::test_near_like_and_ilike_parsed_appropriately[NOTLIKE]",
|
| 345 |
+
"tests/test_tokenize.py::test_near_like_and_ilike_parsed_appropriately[NOTILIKE]",
|
| 346 |
+
"tests/test_tokenize.py::test_cli_commands",
|
| 347 |
+
"tests/test_utils.py::test_remove_quotes[None-None]",
|
| 348 |
+
"tests/test_utils.py::test_remove_quotes['foo'-foo]",
|
| 349 |
+
"tests/test_utils.py::test_remove_quotes[\"foo\"-foo]",
|
| 350 |
+
"tests/test_utils.py::test_remove_quotes[`foo`-foo]"
|
| 351 |
+
],
|
| 352 |
+
"all_git_blobs_modes_verified": true,
|
| 353 |
+
"cloud_launch_ready": false,
|
| 354 |
+
"commits": {
|
| 355 |
+
"bug": "847515f1ec7cf0a3e76b4e89f1c26198c4cf0519",
|
| 356 |
+
"healthy": "d802518f3673051449163fc84fe1455448f79b3b",
|
| 357 |
+
"learner": "d2dc9af40ebbd7e109b5c549fd80de8e9bcbee2d"
|
| 358 |
+
},
|
| 359 |
+
"existing_squirrel_snapshot_reused": false,
|
| 360 |
+
"full_transfer_allowlist": [
|
| 361 |
+
"/testbed/.flake8",
|
| 362 |
+
"/testbed/.github/CODE_OF_CONDUCT.md",
|
| 363 |
+
"/testbed/.github/ISSUE_TEMPLATE/bug_report.md",
|
| 364 |
+
"/testbed/.github/ISSUE_TEMPLATE/config.yml",
|
| 365 |
+
"/testbed/.github/ISSUE_TEMPLATE/feature_request.md",
|
| 366 |
+
"/testbed/.github/PULL_REQUEST_TEMPLATE.md",
|
| 367 |
+
"/testbed/.gitignore",
|
| 368 |
+
"/testbed/.readthedocs.yaml",
|
| 369 |
+
"/testbed/AUTHORS",
|
| 370 |
+
"/testbed/CHANGELOG",
|
| 371 |
+
"/testbed/CONTRIBUTING.md",
|
| 372 |
+
"/testbed/LICENSE",
|
| 373 |
+
"/testbed/Makefile",
|
| 374 |
+
"/testbed/README.rst",
|
| 375 |
+
"/testbed/SECURITY.md",
|
| 376 |
+
"/testbed/TODO",
|
| 377 |
+
"/testbed/docs/Makefile",
|
| 378 |
+
"/testbed/docs/source/analyzing.rst",
|
| 379 |
+
"/testbed/docs/source/api.rst",
|
| 380 |
+
"/testbed/docs/source/changes.rst",
|
| 381 |
+
"/testbed/docs/source/conf.py",
|
| 382 |
+
"/testbed/docs/source/extending.rst",
|
| 383 |
+
"/testbed/docs/source/index.rst",
|
| 384 |
+
"/testbed/docs/source/indices.rst",
|
| 385 |
+
"/testbed/docs/source/intro.rst",
|
| 386 |
+
"/testbed/docs/source/license.rst",
|
| 387 |
+
"/testbed/docs/source/ui.rst",
|
| 388 |
+
"/testbed/docs/sqlformat.1",
|
| 389 |
+
"/testbed/examples/column_defs_lowlevel.py",
|
| 390 |
+
"/testbed/examples/extract_table_names.py",
|
| 391 |
+
"/testbed/pyproject.toml",
|
| 392 |
+
"/testbed/sqlparse/__init__.py",
|
| 393 |
+
"/testbed/sqlparse/__main__.py",
|
| 394 |
+
"/testbed/sqlparse/cli.py",
|
| 395 |
+
"/testbed/sqlparse/engine/__init__.py",
|
| 396 |
+
"/testbed/sqlparse/engine/filter_stack.py",
|
| 397 |
+
"/testbed/sqlparse/engine/grouping.py",
|
| 398 |
+
"/testbed/sqlparse/engine/statement_splitter.py",
|
| 399 |
+
"/testbed/sqlparse/exceptions.py",
|
| 400 |
+
"/testbed/sqlparse/filters/__init__.py",
|
| 401 |
+
"/testbed/sqlparse/filters/aligned_indent.py",
|
| 402 |
+
"/testbed/sqlparse/filters/others.py",
|
| 403 |
+
"/testbed/sqlparse/filters/output.py",
|
| 404 |
+
"/testbed/sqlparse/filters/reindent.py",
|
| 405 |
+
"/testbed/sqlparse/filters/right_margin.py",
|
| 406 |
+
"/testbed/sqlparse/filters/tokens.py",
|
| 407 |
+
"/testbed/sqlparse/formatter.py",
|
| 408 |
+
"/testbed/sqlparse/keywords.py",
|
| 409 |
+
"/testbed/sqlparse/lexer.py",
|
| 410 |
+
"/testbed/sqlparse/sql.py",
|
| 411 |
+
"/testbed/sqlparse/tokens.py",
|
| 412 |
+
"/testbed/sqlparse/utils.py",
|
| 413 |
+
"/testbed/tests/__init__.py",
|
| 414 |
+
"/testbed/tests/conftest.py",
|
| 415 |
+
"/testbed/tests/files/_Make_DirEntry.sql",
|
| 416 |
+
"/testbed/tests/files/begintag.sql",
|
| 417 |
+
"/testbed/tests/files/begintag_2.sql",
|
| 418 |
+
"/testbed/tests/files/casewhen_procedure.sql",
|
| 419 |
+
"/testbed/tests/files/dashcomment.sql",
|
| 420 |
+
"/testbed/tests/files/encoding_gbk.sql",
|
| 421 |
+
"/testbed/tests/files/encoding_utf8.sql",
|
| 422 |
+
"/testbed/tests/files/function.sql",
|
| 423 |
+
"/testbed/tests/files/function_psql.sql",
|
| 424 |
+
"/testbed/tests/files/function_psql2.sql",
|
| 425 |
+
"/testbed/tests/files/function_psql3.sql",
|
| 426 |
+
"/testbed/tests/files/function_psql4.sql",
|
| 427 |
+
"/testbed/tests/files/huge_select.sql",
|
| 428 |
+
"/testbed/tests/files/multiple_case_in_begin.sql",
|
| 429 |
+
"/testbed/tests/files/mysql_handler.sql",
|
| 430 |
+
"/testbed/tests/files/stream.sql",
|
| 431 |
+
"/testbed/tests/files/test_cp1251.sql",
|
| 432 |
+
"/testbed/tests/test_cli.py",
|
| 433 |
+
"/testbed/tests/test_format.py",
|
| 434 |
+
"/testbed/tests/test_grouping.py",
|
| 435 |
+
"/testbed/tests/test_keywords.py",
|
| 436 |
+
"/testbed/tests/test_regressions.py",
|
| 437 |
+
"/testbed/tests/test_split.py",
|
| 438 |
+
"/testbed/tests/test_tokenize.py",
|
| 439 |
+
"/testbed/tests/test_utils.py"
|
| 440 |
+
],
|
| 441 |
+
"healthy_stage_meaning": "Direct parent of the mutation; no source or test execution has been performed",
|
| 442 |
+
"mutation_matches_dataset_and_git_blobs": true,
|
| 443 |
+
"official_profile": {
|
| 444 |
+
"eval_sets": [],
|
| 445 |
+
"profile_class": "SqlparseE57923b3",
|
| 446 |
+
"profile_lines": [
|
| 447 |
+
921,
|
| 448 |
+
924
|
| 449 |
+
],
|
| 450 |
+
"profile_source_commit": "9b74ac08118a85c39c356802f7961893af73e07f",
|
| 451 |
+
"profile_source_path": "swesmith/profiles/python.py",
|
| 452 |
+
"profile_source_sha256": "eadf29551ca2e706950d3f2311b47a3d08c2ccee3c8dd217fa299014a08e4286",
|
| 453 |
+
"upstream_commit": "e57923b3aa823c524c807953cecc48cf6eec2cb2",
|
| 454 |
+
"upstream_repo": "andialbrecht/sqlparse"
|
| 455 |
+
},
|
| 456 |
+
"original_source_commit": "e57923b3aa823c524c807953cecc48cf6eec2cb2",
|
| 457 |
+
"private_test_paths": [
|
| 458 |
+
"tests/test_parse.py"
|
| 459 |
+
],
|
| 460 |
+
"private_tests_unchanged": true,
|
| 461 |
+
"profile_mapping_basis": "Explicit upstream repo and full commit fields parsed from pinned official Python profile AST, not basename inference",
|
| 462 |
+
"qwen_calibrated": false,
|
| 463 |
+
"runtime_qualified": false,
|
| 464 |
+
"source_paths": [
|
| 465 |
+
"sqlparse/sql.py"
|
| 466 |
+
],
|
| 467 |
+
"source_repo": "swesmith/andialbrecht__sqlparse.e57923b3",
|
| 468 |
+
"source_stages_bytes": 923190,
|
| 469 |
+
"task_id": "andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky",
|
| 470 |
+
"transfer_limitation": "Existing regular files only; new arbitrary file additions need a qualified patch adapter",
|
| 471 |
+
"upstream_repo": "andialbrecht/sqlparse"
|
| 472 |
+
},
|
| 473 |
+
"source_record": {
|
| 474 |
+
"anti_training_canary": false,
|
| 475 |
+
"anti_training_reviewed": true,
|
| 476 |
+
"candidate_id": "swesmith-py:andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky",
|
| 477 |
+
"cloud_launch_ready": false,
|
| 478 |
+
"eligibility": {
|
| 479 |
+
"reasons": [],
|
| 480 |
+
"semantic_nonoverlap_established": false,
|
| 481 |
+
"status": "eligible_for_controls",
|
| 482 |
+
"training_admissible": false,
|
| 483 |
+
"warnings": []
|
| 484 |
+
},
|
| 485 |
+
"healthy_mirror_commit": "d802518f3673051449163fc84fe1455448f79b3b",
|
| 486 |
+
"instruction_sha256": "22a97bfee4be839b24bba2990225421f6864528da5588ad59d23cafae4a7bf4b",
|
| 487 |
+
"is_fork": true,
|
| 488 |
+
"learner_path": "tasks/cfbfcdb7704d2b47a19931a3/learner",
|
| 489 |
+
"license_evidence": {
|
| 490 |
+
"source_code": {
|
| 491 |
+
"actual_upstream_commit": "e57923b3aa823c524c807953cecc48cf6eec2cb2",
|
| 492 |
+
"actual_upstream_url": "https://raw.githubusercontent.com/andialbrecht/sqlparse/e57923b3aa823c524c807953cecc48cf6eec2cb2/LICENSE",
|
| 493 |
+
"reviewed": true,
|
| 494 |
+
"sha256": "c1938235b80d39e93138eae89edc3af67e18ecbc40d266529fa57b2dce426310",
|
| 495 |
+
"spdx": "BSD-3-Clause",
|
| 496 |
+
"training_allowed": true,
|
| 497 |
+
"url": "https://raw.githubusercontent.com/swesmith/andialbrecht__sqlparse.e57923b3/d2dc9af40ebbd7e109b5c549fd80de8e9bcbee2d/LICENSE"
|
| 498 |
+
},
|
| 499 |
+
"task_bundle": {
|
| 500 |
+
"reviewed": true,
|
| 501 |
+
"sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808",
|
| 502 |
+
"spdx": "MIT",
|
| 503 |
+
"training_allowed": true,
|
| 504 |
+
"url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md"
|
| 505 |
+
}
|
| 506 |
+
},
|
| 507 |
+
"original_source_commit": "e57923b3aa823c524c807953cecc48cf6eec2cb2",
|
| 508 |
+
"patch_sha256": "82c507cd8533e0f0975e86b6f20aa802f9f5e23726bf98648e36e5ffb2a57f11",
|
| 509 |
+
"provenance_path": "tasks/cfbfcdb7704d2b47a19931a3/source-proof.json",
|
| 510 |
+
"repository_lineage": [
|
| 511 |
+
"swesmith/andialbrecht__sqlparse.e57923b3",
|
| 512 |
+
"andialbrecht/sqlparse"
|
| 513 |
+
],
|
| 514 |
+
"rfc008_complete": false,
|
| 515 |
+
"runtime_qualified": false,
|
| 516 |
+
"semantic_nonoverlap_established": false,
|
| 517 |
+
"source_commit": "d2dc9af40ebbd7e109b5c549fd80de8e9bcbee2d",
|
| 518 |
+
"source_dataset": "SWE-bench/SWE-smith-py",
|
| 519 |
+
"source_head_commit": "847515f1ec7cf0a3e76b4e89f1c26198c4cf0519",
|
| 520 |
+
"source_kind": "mutation",
|
| 521 |
+
"source_repo": "swesmith/andialbrecht__sqlparse.e57923b3",
|
| 522 |
+
"source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e",
|
| 523 |
+
"source_split": "train",
|
| 524 |
+
"target_model_calibrated": false,
|
| 525 |
+
"task_id": "andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky",
|
| 526 |
+
"task_sha256": "28af98c3ad20f79631e694193f4fd20fc4dd73f46175235e3b283a5216a4323e",
|
| 527 |
+
"training_admissible": false,
|
| 528 |
+
"upstream_identity_reviewed": true,
|
| 529 |
+
"upstream_repo": "andialbrecht/sqlparse",
|
| 530 |
+
"usage": "quarantine_only"
|
| 531 |
+
},
|
| 532 |
+
"task_kind": "original-source-mutation"
|
| 533 |
+
}
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/provenance.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"generated_reference": false,
|
| 3 |
+
"healthy_reference_delta_sha256": "c2db1a5d5faa728cd7c8fe1be739d7f8148826bedd46b3f662ecfe05ad46b67c",
|
| 4 |
+
"native_pytest_ids_preserved": true,
|
| 5 |
+
"original_source_code_license": {
|
| 6 |
+
"actual_upstream_commit": "e57923b3aa823c524c807953cecc48cf6eec2cb2",
|
| 7 |
+
"actual_upstream_url": "https://raw.githubusercontent.com/andialbrecht/sqlparse/e57923b3aa823c524c807953cecc48cf6eec2cb2/LICENSE",
|
| 8 |
+
"reviewed": true,
|
| 9 |
+
"sha256": "c1938235b80d39e93138eae89edc3af67e18ecbc40d266529fa57b2dce426310",
|
| 10 |
+
"spdx": "BSD-3-Clause",
|
| 11 |
+
"training_allowed": true,
|
| 12 |
+
"url": "https://raw.githubusercontent.com/swesmith/andialbrecht__sqlparse.e57923b3/d2dc9af40ebbd7e109b5c549fd80de8e9bcbee2d/LICENSE"
|
| 13 |
+
},
|
| 14 |
+
"provided_reference": true,
|
| 15 |
+
"qwen_calibrated": false,
|
| 16 |
+
"runtime_qualified": false,
|
| 17 |
+
"source_completion_sha256": "535fea9c295e324b6614c71eeb6e56f8304ee8d168dddd724d93149020a06dba",
|
| 18 |
+
"source_index_sha256": "a8bacb23b190ac8227d8d322773176a10ed65e6b16cccd869cb625a465522876",
|
| 19 |
+
"source_proof_sha256": "8cec1a84eb63090a7ace3c4260fe6ab38a1f3c6853a76f62548e414a36d29d69",
|
| 20 |
+
"source_record": {
|
| 21 |
+
"anti_training_canary": false,
|
| 22 |
+
"anti_training_reviewed": true,
|
| 23 |
+
"candidate_id": "swesmith-py:andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky",
|
| 24 |
+
"cloud_launch_ready": false,
|
| 25 |
+
"eligibility": {
|
| 26 |
+
"reasons": [],
|
| 27 |
+
"semantic_nonoverlap_established": false,
|
| 28 |
+
"status": "eligible_for_controls",
|
| 29 |
+
"training_admissible": false,
|
| 30 |
+
"warnings": []
|
| 31 |
+
},
|
| 32 |
+
"healthy_mirror_commit": "d802518f3673051449163fc84fe1455448f79b3b",
|
| 33 |
+
"instruction_sha256": "22a97bfee4be839b24bba2990225421f6864528da5588ad59d23cafae4a7bf4b",
|
| 34 |
+
"is_fork": true,
|
| 35 |
+
"learner_path": "tasks/cfbfcdb7704d2b47a19931a3/learner",
|
| 36 |
+
"license_evidence": {
|
| 37 |
+
"source_code": {
|
| 38 |
+
"actual_upstream_commit": "e57923b3aa823c524c807953cecc48cf6eec2cb2",
|
| 39 |
+
"actual_upstream_url": "https://raw.githubusercontent.com/andialbrecht/sqlparse/e57923b3aa823c524c807953cecc48cf6eec2cb2/LICENSE",
|
| 40 |
+
"reviewed": true,
|
| 41 |
+
"sha256": "c1938235b80d39e93138eae89edc3af67e18ecbc40d266529fa57b2dce426310",
|
| 42 |
+
"spdx": "BSD-3-Clause",
|
| 43 |
+
"training_allowed": true,
|
| 44 |
+
"url": "https://raw.githubusercontent.com/swesmith/andialbrecht__sqlparse.e57923b3/d2dc9af40ebbd7e109b5c549fd80de8e9bcbee2d/LICENSE"
|
| 45 |
+
},
|
| 46 |
+
"task_bundle": {
|
| 47 |
+
"reviewed": true,
|
| 48 |
+
"sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808",
|
| 49 |
+
"spdx": "MIT",
|
| 50 |
+
"training_allowed": true,
|
| 51 |
+
"url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md"
|
| 52 |
+
}
|
| 53 |
+
},
|
| 54 |
+
"original_source_commit": "e57923b3aa823c524c807953cecc48cf6eec2cb2",
|
| 55 |
+
"patch_sha256": "82c507cd8533e0f0975e86b6f20aa802f9f5e23726bf98648e36e5ffb2a57f11",
|
| 56 |
+
"provenance_path": "tasks/cfbfcdb7704d2b47a19931a3/source-proof.json",
|
| 57 |
+
"repository_lineage": [
|
| 58 |
+
"swesmith/andialbrecht__sqlparse.e57923b3",
|
| 59 |
+
"andialbrecht/sqlparse"
|
| 60 |
+
],
|
| 61 |
+
"rfc008_complete": false,
|
| 62 |
+
"runtime_qualified": false,
|
| 63 |
+
"semantic_nonoverlap_established": false,
|
| 64 |
+
"source_commit": "d2dc9af40ebbd7e109b5c549fd80de8e9bcbee2d",
|
| 65 |
+
"source_dataset": "SWE-bench/SWE-smith-py",
|
| 66 |
+
"source_head_commit": "847515f1ec7cf0a3e76b4e89f1c26198c4cf0519",
|
| 67 |
+
"source_kind": "mutation",
|
| 68 |
+
"source_repo": "swesmith/andialbrecht__sqlparse.e57923b3",
|
| 69 |
+
"source_revision": "77cab9055d42ab4a5c25c89a8f937096db13558e",
|
| 70 |
+
"source_split": "train",
|
| 71 |
+
"target_model_calibrated": false,
|
| 72 |
+
"task_id": "andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky",
|
| 73 |
+
"task_sha256": "28af98c3ad20f79631e694193f4fd20fc4dd73f46175235e3b283a5216a4323e",
|
| 74 |
+
"training_admissible": false,
|
| 75 |
+
"upstream_identity_reviewed": true,
|
| 76 |
+
"upstream_repo": "andialbrecht/sqlparse",
|
| 77 |
+
"usage": "quarantine_only"
|
| 78 |
+
},
|
| 79 |
+
"task_bundle_license": {
|
| 80 |
+
"reviewed": true,
|
| 81 |
+
"sha256": "18afda407941c9d3c65ff530bedd3bc93f3a13d9504ee5728e959fb43ffce808",
|
| 82 |
+
"spdx": "MIT",
|
| 83 |
+
"training_allowed": true,
|
| 84 |
+
"url": "https://huggingface.co/datasets/SWE-bench/SWE-smith-py/raw/77cab9055d42ab4a5c25c89a8f937096db13558e/README.md"
|
| 85 |
+
},
|
| 86 |
+
"training_admissible": false,
|
| 87 |
+
"trusted_tests_sha256": "ea16a768523e5e923d71ad99188edd31f721472432f18fb42d7e93c417d066cf"
|
| 88 |
+
}
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/provided-gold.diff
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
diff --git a/sqlparse/sql.py b/sqlparse/sql.py
|
| 2 |
+
index 76f7f9caabd3583f7deec7a5698b731e962c13af..10373751335ee0e59f6efe5f6e7da5a74b50e41a 100644
|
| 3 |
+
--- a/sqlparse/sql.py
|
| 4 |
+
+++ b/sqlparse/sql.py
|
| 5 |
+
@@ -472,8 +472,8 @@
|
| 6 |
+
|
| 7 |
+
for token in self.tokens:
|
| 8 |
+
if isinstance(token, SquareBrackets):
|
| 9 |
+
- # Use incorrect slicing to alter the extraction logic
|
| 10 |
+
- yield token.tokens[0:-2]
|
| 11 |
+
+ # Use [1:-1] index to discard the square brackets
|
| 12 |
+
+ yield token.tokens[1:-1]
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class IdentifierList(TokenList):
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/solution/solve.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
cd /testbed/repo
|
| 4 |
+
cat > /tmp/openenv-reference.diff <<'OPENENV_REFERENCE'
|
| 5 |
+
diff --git a/sqlparse/sql.py b/sqlparse/sql.py
|
| 6 |
+
index 76f7f9caabd3583f7deec7a5698b731e962c13af..10373751335ee0e59f6efe5f6e7da5a74b50e41a 100644
|
| 7 |
+
--- a/sqlparse/sql.py
|
| 8 |
+
+++ b/sqlparse/sql.py
|
| 9 |
+
@@ -472,8 +472,8 @@
|
| 10 |
+
|
| 11 |
+
for token in self.tokens:
|
| 12 |
+
if isinstance(token, SquareBrackets):
|
| 13 |
+
- # Use incorrect slicing to alter the extraction logic
|
| 14 |
+
- yield token.tokens[0:-2]
|
| 15 |
+
+ # Use [1:-1] index to discard the square brackets
|
| 16 |
+
+ yield token.tokens[1:-1]
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class IdentifierList(TokenList):
|
| 20 |
+
OPENENV_REFERENCE
|
| 21 |
+
/usr/bin/git -c core.hooksPath=/dev/null -c core.fsmonitor=false apply --whitespace=nowarn /tmp/openenv-reference.diff
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/task.toml
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version = "1.0"
|
| 2 |
+
|
| 3 |
+
[agent]
|
| 4 |
+
timeout_sec = 1800.0
|
| 5 |
+
|
| 6 |
+
[verifier]
|
| 7 |
+
timeout_sec = 900.0
|
| 8 |
+
|
| 9 |
+
[environment]
|
| 10 |
+
docker_image = "ghcr.io/younesbelkada/scale800@sha256:4768b096a82c07f82dfe781c4846d60bca52b7d8427d0543a8452d457d4f0fb2"
|
| 11 |
+
build_timeout_sec = 600.0
|
| 12 |
+
cpus = 2
|
| 13 |
+
memory_mb = 8192
|
| 14 |
+
storage_mb = 16384
|
| 15 |
+
|
| 16 |
+
[metadata]
|
| 17 |
+
author_name = "SWE-smith source adapter"
|
| 18 |
+
category = "bugfix"
|
| 19 |
+
tags = ["swe", "python", "mutation-repair"]
|
| 20 |
+
|
| 21 |
+
[environment.env]
|
| 22 |
+
# The image's PATH with the testbed env first: the project and pytest are installed there, and the agent's
|
| 23 |
+
# non-interactive shells never run `conda activate`
|
| 24 |
+
PATH = "/opt/miniconda3/envs/testbed/bin:/opt/miniconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/check_pytest.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Distinguish real pytest failures from missing/setup/verifier evidence."""
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import re
|
| 6 |
+
import xml.etree.ElementTree as ET
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def matches(case, target):
|
| 11 |
+
parts = target.split("::")
|
| 12 |
+
module = parts[0].removesuffix(".py").replace("/", ".")
|
| 13 |
+
classname = case.get("classname", "")
|
| 14 |
+
name = case.get("name", "")
|
| 15 |
+
if not (classname == module or classname.startswith(module + ".")):
|
| 16 |
+
return False
|
| 17 |
+
selector = parts[-1] if len(parts) > 1 else ""
|
| 18 |
+
classes = parts[1:-1]
|
| 19 |
+
if classes and classname != module + "." + ".".join(classes):
|
| 20 |
+
return False
|
| 21 |
+
return (
|
| 22 |
+
not selector
|
| 23 |
+
or name == selector
|
| 24 |
+
or ("[" not in selector and name.startswith(selector + "["))
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def assess(root, expected, native_exit):
|
| 29 |
+
all_cases = []
|
| 30 |
+
actual_failure = False
|
| 31 |
+
for group in ("pass-to-pass", "fail-to-pass"):
|
| 32 |
+
path = Path(root) / (group + ".xml")
|
| 33 |
+
if not path.exists():
|
| 34 |
+
if actual_failure:
|
| 35 |
+
continue
|
| 36 |
+
raise ValueError("Missing preceding pytest panel")
|
| 37 |
+
if actual_failure:
|
| 38 |
+
raise ValueError(
|
| 39 |
+
"Pytest evidence continued after the native stop-on-failure"
|
| 40 |
+
)
|
| 41 |
+
raw = path.read_bytes()
|
| 42 |
+
if not 0 < len(raw) <= 4 * 1024**2 or re.search(
|
| 43 |
+
rb"<!\s*(?:DOCTYPE|ENTITY)", raw, re.I
|
| 44 |
+
):
|
| 45 |
+
raise ValueError("Unbounded or unsafe pytest XML")
|
| 46 |
+
tree = ET.fromstring(raw)
|
| 47 |
+
cases = list(tree.iter("testcase"))
|
| 48 |
+
if len(cases) > 20000:
|
| 49 |
+
raise ValueError("Too many pytest cases")
|
| 50 |
+
identities = [(c.get("classname"), c.get("name")) for c in cases]
|
| 51 |
+
if len(identities) != len(set(identities)):
|
| 52 |
+
raise ValueError("Duplicate pytest case evidence")
|
| 53 |
+
targets = expected[group]
|
| 54 |
+
if any(not any(matches(case, t) for t in targets) for case in cases):
|
| 55 |
+
raise ValueError("Unexpected pytest case")
|
| 56 |
+
all_cases.extend(cases)
|
| 57 |
+
failures = [c for c in cases if c.find("failure") is not None]
|
| 58 |
+
if any(
|
| 59 |
+
c.find("error") is not None or c.find("skipped") is not None for c in cases
|
| 60 |
+
):
|
| 61 |
+
raise ValueError("Pytest collection/error/skip is not a completed panel")
|
| 62 |
+
actual_failure = actual_failure or bool(failures)
|
| 63 |
+
if not failures and any(
|
| 64 |
+
not any(matches(case, t) for case in cases) for t in targets
|
| 65 |
+
):
|
| 66 |
+
raise ValueError("Declared pytest target never ran")
|
| 67 |
+
if actual_failure:
|
| 68 |
+
if native_exit == 0:
|
| 69 |
+
raise ValueError("Native verifier exit disagrees with pytest failure")
|
| 70 |
+
return {"reward": 0, "valid_test_failure": True, "cases": len(all_cases)}
|
| 71 |
+
if native_exit != 0:
|
| 72 |
+
raise ValueError("Setup or native verifier failed without a real test failure")
|
| 73 |
+
for group in ("pass-to-pass", "fail-to-pass"):
|
| 74 |
+
if not (Path(root) / (group + ".xml")).is_file():
|
| 75 |
+
raise ValueError("Missing completed pytest panel")
|
| 76 |
+
return {"reward": 1, "valid_test_failure": False, "cases": len(all_cases)}
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
if __name__ == "__main__":
|
| 80 |
+
p = argparse.ArgumentParser()
|
| 81 |
+
p.add_argument("--root", required=True)
|
| 82 |
+
p.add_argument("--expected", required=True)
|
| 83 |
+
p.add_argument("--native-exit", type=int, required=True)
|
| 84 |
+
a = p.parse_args()
|
| 85 |
+
result = assess(a.root, json.loads(Path(a.expected).read_text()), a.native_exit)
|
| 86 |
+
reward = Path(a.root) / "reward.txt"
|
| 87 |
+
if reward.read_text().strip() != str(result["reward"]):
|
| 88 |
+
raise ValueError("Native raw reward disagrees with pytest evidence")
|
| 89 |
+
(Path(a.root) / "pytest-evidence.json").write_text(
|
| 90 |
+
json.dumps(result, sort_keys=True) + "\n"
|
| 91 |
+
)
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/expected-panels.json
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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_parse.py::test_aliased_array_index"
|
| 6 |
+
],
|
| 7 |
+
"pass-to-pass": [
|
| 8 |
+
"tests/test_cli.py::test_cli_main_empty",
|
| 9 |
+
"tests/test_cli.py::test_parser_empty",
|
| 10 |
+
"tests/test_cli.py::test_main_help",
|
| 11 |
+
"tests/test_cli.py::test_valid_args",
|
| 12 |
+
"tests/test_cli.py::test_invalid_choice",
|
| 13 |
+
"tests/test_cli.py::test_invalid_args",
|
| 14 |
+
"tests/test_cli.py::test_invalid_infile",
|
| 15 |
+
"tests/test_cli.py::test_invalid_outfile",
|
| 16 |
+
"tests/test_cli.py::test_stdout",
|
| 17 |
+
"tests/test_cli.py::test_script",
|
| 18 |
+
"tests/test_cli.py::test_encoding_stdout[encoding_utf8.sql-utf-8]",
|
| 19 |
+
"tests/test_cli.py::test_encoding_stdout[encoding_gbk.sql-gbk]",
|
| 20 |
+
"tests/test_cli.py::test_encoding_output_file[encoding_utf8.sql-utf-8]",
|
| 21 |
+
"tests/test_cli.py::test_encoding_output_file[encoding_gbk.sql-gbk]",
|
| 22 |
+
"tests/test_cli.py::test_encoding_stdin[encoding_utf8.sql-utf-8]",
|
| 23 |
+
"tests/test_cli.py::test_encoding_stdin[encoding_gbk.sql-gbk]",
|
| 24 |
+
"tests/test_cli.py::test_encoding",
|
| 25 |
+
"tests/test_format.py::TestFormat::test_keywordcase",
|
| 26 |
+
"tests/test_format.py::TestFormat::test_keywordcase_invalid_option",
|
| 27 |
+
"tests/test_format.py::TestFormat::test_identifiercase",
|
| 28 |
+
"tests/test_format.py::TestFormat::test_identifiercase_invalid_option",
|
| 29 |
+
"tests/test_format.py::TestFormat::test_identifiercase_quotes",
|
| 30 |
+
"tests/test_format.py::TestFormat::test_strip_comments_single",
|
| 31 |
+
"tests/test_format.py::TestFormat::test_strip_comments_invalid_option",
|
| 32 |
+
"tests/test_format.py::TestFormat::test_strip_comments_multi",
|
| 33 |
+
"tests/test_format.py::TestFormat::test_strip_comments_preserves_linebreak",
|
| 34 |
+
"tests/test_format.py::TestFormat::test_strip_comments_preserves_whitespace",
|
| 35 |
+
"tests/test_format.py::TestFormat::test_strip_comments_preserves_hint",
|
| 36 |
+
"tests/test_format.py::TestFormat::test_strip_ws",
|
| 37 |
+
"tests/test_format.py::TestFormat::test_strip_ws_invalid_option",
|
| 38 |
+
"tests/test_format.py::TestFormat::test_preserve_ws",
|
| 39 |
+
"tests/test_format.py::TestFormat::test_notransform_of_quoted_crlf",
|
| 40 |
+
"tests/test_format.py::TestFormatReindentAligned::test_basic",
|
| 41 |
+
"tests/test_format.py::TestFormatReindentAligned::test_joins",
|
| 42 |
+
"tests/test_format.py::TestFormatReindentAligned::test_case_statement",
|
| 43 |
+
"tests/test_format.py::TestFormatReindentAligned::test_case_statement_with_between",
|
| 44 |
+
"tests/test_format.py::TestFormatReindentAligned::test_group_by",
|
| 45 |
+
"tests/test_format.py::TestFormatReindentAligned::test_group_by_subquery",
|
| 46 |
+
"tests/test_format.py::TestFormatReindentAligned::test_window_functions",
|
| 47 |
+
"tests/test_format.py::TestSpacesAroundOperators::test_basic",
|
| 48 |
+
"tests/test_format.py::TestSpacesAroundOperators::test_bools",
|
| 49 |
+
"tests/test_format.py::TestSpacesAroundOperators::test_nested",
|
| 50 |
+
"tests/test_format.py::TestSpacesAroundOperators::test_wildcard_vs_mult",
|
| 51 |
+
"tests/test_format.py::TestFormatReindent::test_option",
|
| 52 |
+
"tests/test_format.py::TestFormatReindent::test_stmts",
|
| 53 |
+
"tests/test_format.py::TestFormatReindent::test_keywords",
|
| 54 |
+
"tests/test_format.py::TestFormatReindent::test_keywords_between",
|
| 55 |
+
"tests/test_format.py::TestFormatReindent::test_parenthesis",
|
| 56 |
+
"tests/test_format.py::TestFormatReindent::test_where",
|
| 57 |
+
"tests/test_format.py::TestFormatReindent::test_join",
|
| 58 |
+
"tests/test_format.py::TestFormatReindent::test_identifier_list",
|
| 59 |
+
"tests/test_format.py::TestFormatReindent::test_identifier_list_with_wrap_after",
|
| 60 |
+
"tests/test_format.py::TestFormatReindent::test_identifier_list_comment_first",
|
| 61 |
+
"tests/test_format.py::TestFormatReindent::test_identifier_list_with_functions",
|
| 62 |
+
"tests/test_format.py::TestFormatReindent::test_long_identifier_list_with_functions",
|
| 63 |
+
"tests/test_format.py::TestFormatReindent::test_case",
|
| 64 |
+
"tests/test_format.py::TestFormatReindent::test_case2",
|
| 65 |
+
"tests/test_format.py::TestFormatReindent::test_nested_identifier_list",
|
| 66 |
+
"tests/test_format.py::TestFormatReindent::test_duplicate_linebreaks",
|
| 67 |
+
"tests/test_format.py::TestFormatReindent::test_keywordfunctions",
|
| 68 |
+
"tests/test_format.py::TestFormatReindent::test_identifier_and_functions",
|
| 69 |
+
"tests/test_format.py::TestFormatReindent::test_insert_values",
|
| 70 |
+
"tests/test_format.py::TestOutputFormat::test_python",
|
| 71 |
+
"tests/test_format.py::TestOutputFormat::test_python_multiple_statements",
|
| 72 |
+
"tests/test_format.py::TestOutputFormat::test_php",
|
| 73 |
+
"tests/test_format.py::TestOutputFormat::test_sql",
|
| 74 |
+
"tests/test_format.py::TestOutputFormat::test_invalid_option",
|
| 75 |
+
"tests/test_format.py::test_format_column_ordering",
|
| 76 |
+
"tests/test_format.py::test_truncate_strings",
|
| 77 |
+
"tests/test_format.py::test_truncate_strings_invalid_option2[bar]",
|
| 78 |
+
"tests/test_format.py::test_truncate_strings_invalid_option2[-1]",
|
| 79 |
+
"tests/test_format.py::test_truncate_strings_invalid_option2[0]",
|
| 80 |
+
"tests/test_format.py::test_having_produces_newline",
|
| 81 |
+
"tests/test_format.py::test_format_right_margin_invalid_option[ten]",
|
| 82 |
+
"tests/test_format.py::test_format_right_margin_invalid_option[2]",
|
| 83 |
+
"tests/test_format.py::test_format_json_ops",
|
| 84 |
+
"tests/test_format.py::test_strip_ws_removes_trailing_ws_in_groups",
|
| 85 |
+
"tests/test_grouping.py::test_grouping_parenthesis",
|
| 86 |
+
"tests/test_grouping.py::test_grouping_identifiers",
|
| 87 |
+
"tests/test_grouping.py::test_grouping_identifier_wildcard",
|
| 88 |
+
"tests/test_grouping.py::test_grouping_identifier_name_wildcard",
|
| 89 |
+
"tests/test_grouping.py::test_grouping_identifier_invalid",
|
| 90 |
+
"tests/test_grouping.py::test_grouping_identifier_invalid_in_middle",
|
| 91 |
+
"tests/test_grouping.py::test_grouping_identifier_as_invalid",
|
| 92 |
+
"tests/test_grouping.py::test_grouping_identifier_function",
|
| 93 |
+
"tests/test_grouping.py::test_grouping_operation[foo+100]",
|
| 94 |
+
"tests/test_grouping.py::test_grouping_operation[foo*100]",
|
| 95 |
+
"tests/test_grouping.py::test_grouping_identifier_list",
|
| 96 |
+
"tests/test_grouping.py::test_grouping_identifier_list_subquery",
|
| 97 |
+
"tests/test_grouping.py::test_grouping_identifier_list_case",
|
| 98 |
+
"tests/test_grouping.py::test_grouping_identifier_list_other",
|
| 99 |
+
"tests/test_grouping.py::test_grouping_identifier_list_with_inline_comments",
|
| 100 |
+
"tests/test_grouping.py::test_grouping_identifiers_with_operators",
|
| 101 |
+
"tests/test_grouping.py::test_grouping_identifier_list_with_order",
|
| 102 |
+
"tests/test_grouping.py::test_grouping_nested_identifier_with_order",
|
| 103 |
+
"tests/test_grouping.py::test_grouping_where",
|
| 104 |
+
"tests/test_grouping.py::test_returning_kw_ends_where_clause",
|
| 105 |
+
"tests/test_grouping.py::test_into_kw_ends_where_clause",
|
| 106 |
+
"tests/test_grouping.py::test_grouping_alias",
|
| 107 |
+
"tests/test_grouping.py::test_grouping_alias_case",
|
| 108 |
+
"tests/test_grouping.py::test_grouping_alias_ctas",
|
| 109 |
+
"tests/test_grouping.py::test_grouping_subquery_no_parens",
|
| 110 |
+
"tests/test_grouping.py::test_grouping_alias_returns_none[foo.bar]",
|
| 111 |
+
"tests/test_grouping.py::test_grouping_idlist_function",
|
| 112 |
+
"tests/test_grouping.py::test_grouping_comparison_exclude",
|
| 113 |
+
"tests/test_grouping.py::test_grouping_function",
|
| 114 |
+
"tests/test_grouping.py::test_grouping_function_not_in",
|
| 115 |
+
"tests/test_grouping.py::test_grouping_varchar",
|
| 116 |
+
"tests/test_grouping.py::test_statement_get_type",
|
| 117 |
+
"tests/test_grouping.py::test_identifier_with_operators",
|
| 118 |
+
"tests/test_grouping.py::test_identifier_with_op_trailing_ws",
|
| 119 |
+
"tests/test_grouping.py::test_identifier_with_string_literals",
|
| 120 |
+
"tests/test_grouping.py::test_identifier_consumes_ordering",
|
| 121 |
+
"tests/test_grouping.py::test_comparison_with_keywords",
|
| 122 |
+
"tests/test_grouping.py::test_comparison_with_floats",
|
| 123 |
+
"tests/test_grouping.py::test_comparison_with_parenthesis",
|
| 124 |
+
"tests/test_grouping.py::test_comparison_with_strings[=]",
|
| 125 |
+
"tests/test_grouping.py::test_comparison_with_strings[!=]",
|
| 126 |
+
"tests/test_grouping.py::test_comparison_with_strings[>]",
|
| 127 |
+
"tests/test_grouping.py::test_comparison_with_strings[<]",
|
| 128 |
+
"tests/test_grouping.py::test_comparison_with_strings[<=]",
|
| 129 |
+
"tests/test_grouping.py::test_comparison_with_strings[>=]",
|
| 130 |
+
"tests/test_grouping.py::test_comparison_with_strings[~]",
|
| 131 |
+
"tests/test_grouping.py::test_comparison_with_strings[~~]",
|
| 132 |
+
"tests/test_grouping.py::test_comparison_with_strings[!~~]",
|
| 133 |
+
"tests/test_grouping.py::test_comparison_with_strings[LIKE]",
|
| 134 |
+
"tests/test_grouping.py::test_comparison_with_strings[ILIKE]",
|
| 135 |
+
"tests/test_grouping.py::test_like_and_ilike_comparison",
|
| 136 |
+
"tests/test_grouping.py::test_comparison_with_functions",
|
| 137 |
+
"tests/test_grouping.py::test_comparison_with_typed_literal",
|
| 138 |
+
"tests/test_grouping.py::test_forloops[FOR]",
|
| 139 |
+
"tests/test_grouping.py::test_forloops[FOREACH]",
|
| 140 |
+
"tests/test_grouping.py::test_nested_for",
|
| 141 |
+
"tests/test_grouping.py::test_begin",
|
| 142 |
+
"tests/test_grouping.py::test_keyword_followed_by_parenthesis",
|
| 143 |
+
"tests/test_grouping.py::test_nested_begin",
|
| 144 |
+
"tests/test_grouping.py::test_aliased_column_without_as",
|
| 145 |
+
"tests/test_grouping.py::test_qualified_function",
|
| 146 |
+
"tests/test_grouping.py::test_aliased_function_without_as",
|
| 147 |
+
"tests/test_grouping.py::test_aliased_literal_without_as",
|
| 148 |
+
"tests/test_grouping.py::test_grouping_as_cte",
|
| 149 |
+
"tests/test_grouping.py::test_grouping_create_table",
|
| 150 |
+
"tests/test_keywords.py::TestSQLREGEX::test_float_numbers[1.0]",
|
| 151 |
+
"tests/test_keywords.py::TestSQLREGEX::test_float_numbers[-1.0]",
|
| 152 |
+
"tests/test_keywords.py::TestSQLREGEX::test_float_numbers[1.]",
|
| 153 |
+
"tests/test_keywords.py::TestSQLREGEX::test_float_numbers[-1.]",
|
| 154 |
+
"tests/test_keywords.py::TestSQLREGEX::test_float_numbers[.1]",
|
| 155 |
+
"tests/test_keywords.py::TestSQLREGEX::test_float_numbers[-.1]",
|
| 156 |
+
"tests/test_parse.py::test_parse_tokenize",
|
| 157 |
+
"tests/test_parse.py::test_parse_multistatement",
|
| 158 |
+
"tests/test_parse.py::test_parse_within",
|
| 159 |
+
"tests/test_parse.py::test_parse_child_of",
|
| 160 |
+
"tests/test_parse.py::test_parse_has_ancestor",
|
| 161 |
+
"tests/test_parse.py::test_parse_float[.5]",
|
| 162 |
+
"tests/test_parse.py::test_parse_float[.51]",
|
| 163 |
+
"tests/test_parse.py::test_parse_float[1.5]",
|
| 164 |
+
"tests/test_parse.py::test_parse_float[12.5]",
|
| 165 |
+
"tests/test_parse.py::test_parse_modulo_not_placeholder",
|
| 166 |
+
"tests/test_parse.py::test_parse_access_symbol",
|
| 167 |
+
"tests/test_parse.py::test_parse_square_brackets_notation_isnt_too_greedy",
|
| 168 |
+
"tests/test_parse.py::test_parse_square_brackets_notation_isnt_too_greedy2",
|
| 169 |
+
"tests/test_parse.py::test_parse_keyword_like_identifier",
|
| 170 |
+
"tests/test_parse.py::test_parse_function_parameter",
|
| 171 |
+
"tests/test_parse.py::test_parse_function_param_single_literal",
|
| 172 |
+
"tests/test_parse.py::test_parse_nested_function",
|
| 173 |
+
"tests/test_parse.py::test_parse_casted_params",
|
| 174 |
+
"tests/test_parse.py::test_parse_div_operator",
|
| 175 |
+
"tests/test_parse.py::test_quoted_identifier",
|
| 176 |
+
"tests/test_parse.py::test_valid_identifier_names[foo]",
|
| 177 |
+
"tests/test_parse.py::test_valid_identifier_names[_foo]",
|
| 178 |
+
"tests/test_parse.py::test_valid_identifier_names[1_data]",
|
| 179 |
+
"tests/test_parse.py::test_valid_identifier_names[\\u696d\\u8005\\u540d\\u7a31]",
|
| 180 |
+
"tests/test_parse.py::test_psql_quotation_marks",
|
| 181 |
+
"tests/test_parse.py::test_double_precision_is_builtin",
|
| 182 |
+
"tests/test_parse.py::test_placeholder[?]",
|
| 183 |
+
"tests/test_parse.py::test_placeholder[:1]",
|
| 184 |
+
"tests/test_parse.py::test_placeholder[:foo]",
|
| 185 |
+
"tests/test_parse.py::test_placeholder[%s]",
|
| 186 |
+
"tests/test_parse.py::test_placeholder[%(foo)s]",
|
| 187 |
+
"tests/test_parse.py::test_scientific_numbers[6.67428E-8-expected0]",
|
| 188 |
+
"tests/test_parse.py::test_scientific_numbers[1.988e33-expected1]",
|
| 189 |
+
"tests/test_parse.py::test_scientific_numbers[1e-12-expected2]",
|
| 190 |
+
"tests/test_parse.py::test_scientific_numbers[e1-None]",
|
| 191 |
+
"tests/test_parse.py::test_single_quotes_are_strings",
|
| 192 |
+
"tests/test_parse.py::test_double_quotes_are_identifiers",
|
| 193 |
+
"tests/test_parse.py::test_single_quotes_with_linebreaks",
|
| 194 |
+
"tests/test_parse.py::test_sqlite_identifiers",
|
| 195 |
+
"tests/test_parse.py::test_2d_array_index",
|
| 196 |
+
"tests/test_parse.py::test_array_index_function_result",
|
| 197 |
+
"tests/test_parse.py::test_array_literal",
|
| 198 |
+
"tests/test_parse.py::test_typed_array_definition",
|
| 199 |
+
"tests/test_parse.py::test_names_and_special_names[foo]",
|
| 200 |
+
"tests/test_parse.py::test_names_and_special_names[@foo]",
|
| 201 |
+
"tests/test_parse.py::test_names_and_special_names[#foo]",
|
| 202 |
+
"tests/test_parse.py::test_names_and_special_names[##foo]",
|
| 203 |
+
"tests/test_parse.py::test_get_token_at_offset",
|
| 204 |
+
"tests/test_parse.py::test_pprint",
|
| 205 |
+
"tests/test_parse.py::test_wildcard_multiplication",
|
| 206 |
+
"tests/test_parse.py::test_stmt_tokens_parents",
|
| 207 |
+
"tests/test_parse.py::test_dbldollar_as_literal[$$foo$$-True]",
|
| 208 |
+
"tests/test_parse.py::test_dbldollar_as_literal[$_$foo$_$-True]",
|
| 209 |
+
"tests/test_parse.py::test_non_ascii",
|
| 210 |
+
"tests/test_parse.py::test_get_real_name",
|
| 211 |
+
"tests/test_parse.py::test_from_subquery",
|
| 212 |
+
"tests/test_parse.py::test_parenthesis",
|
| 213 |
+
"tests/test_parse.py::test_configurable_keywords",
|
| 214 |
+
"tests/test_parse.py::test_configurable_regex",
|
| 215 |
+
"tests/test_parse.py::test_json_operators[->]",
|
| 216 |
+
"tests/test_parse.py::test_json_operators[->>]",
|
| 217 |
+
"tests/test_parse.py::test_json_operators[#>]",
|
| 218 |
+
"tests/test_parse.py::test_json_operators[#>>]",
|
| 219 |
+
"tests/test_parse.py::test_json_operators[@>]",
|
| 220 |
+
"tests/test_parse.py::test_json_operators[<@]",
|
| 221 |
+
"tests/test_parse.py::test_json_operators[||]",
|
| 222 |
+
"tests/test_parse.py::test_json_operators[-]",
|
| 223 |
+
"tests/test_parse.py::test_json_operators[#-]",
|
| 224 |
+
"tests/test_regressions.py::test_issue9",
|
| 225 |
+
"tests/test_regressions.py::test_issue13",
|
| 226 |
+
"tests/test_regressions.py::test_issue26[--hello]",
|
| 227 |
+
"tests/test_regressions.py::test_issue26[--hello\\n]",
|
| 228 |
+
"tests/test_regressions.py::test_issue26[--]",
|
| 229 |
+
"tests/test_regressions.py::test_issue26[--\\n]",
|
| 230 |
+
"tests/test_regressions.py::test_issue34[create]",
|
| 231 |
+
"tests/test_regressions.py::test_issue34[CREATE]",
|
| 232 |
+
"tests/test_regressions.py::test_issue35",
|
| 233 |
+
"tests/test_regressions.py::test_issue38",
|
| 234 |
+
"tests/test_regressions.py::test_issue39",
|
| 235 |
+
"tests/test_regressions.py::test_issue40",
|
| 236 |
+
"tests/test_regressions.py::test_issue83",
|
| 237 |
+
"tests/test_regressions.py::test_comment_encoding_when_reindent",
|
| 238 |
+
"tests/test_regressions.py::test_parse_sql_with_binary",
|
| 239 |
+
"tests/test_regressions.py::test_dont_alias_keywords",
|
| 240 |
+
"tests/test_regressions.py::test_format_accepts_encoding",
|
| 241 |
+
"tests/test_regressions.py::test_stream",
|
| 242 |
+
"tests/test_regressions.py::test_issue90",
|
| 243 |
+
"tests/test_regressions.py::test_except_formatting",
|
| 244 |
+
"tests/test_regressions.py::test_null_with_as",
|
| 245 |
+
"tests/test_regressions.py::test_issue190_open_file",
|
| 246 |
+
"tests/test_regressions.py::test_issue193_splitting_function",
|
| 247 |
+
"tests/test_regressions.py::test_issue194_splitting_function",
|
| 248 |
+
"tests/test_regressions.py::test_issue186_get_type",
|
| 249 |
+
"tests/test_regressions.py::test_issue212_py2unicode",
|
| 250 |
+
"tests/test_regressions.py::test_issue213_leadingws",
|
| 251 |
+
"tests/test_regressions.py::test_issue227_gettype_cte",
|
| 252 |
+
"tests/test_regressions.py::test_issue207_runaway_format",
|
| 253 |
+
"tests/test_regressions.py::test_token_next_doesnt_ignore_skip_cm",
|
| 254 |
+
"tests/test_regressions.py::test_issue284_as_grouping[AS]",
|
| 255 |
+
"tests/test_regressions.py::test_issue315_utf8_by_default",
|
| 256 |
+
"tests/test_regressions.py::test_issue322_concurrently_is_keyword",
|
| 257 |
+
"tests/test_regressions.py::test_issue469_copy_as_psql_command",
|
| 258 |
+
"tests/test_regressions.py::test_issue485_split_multi",
|
| 259 |
+
"tests/test_regressions.py::test_issue489_tzcasts",
|
| 260 |
+
"tests/test_regressions.py::test_issue562_tzcasts",
|
| 261 |
+
"tests/test_regressions.py::test_as_in_parentheses_indents",
|
| 262 |
+
"tests/test_regressions.py::test_format_invalid_where_clause",
|
| 263 |
+
"tests/test_regressions.py::test_splitting_at_and_backticks_issue588",
|
| 264 |
+
"tests/test_regressions.py::test_comment_between_cte_clauses_issue632",
|
| 265 |
+
"tests/test_regressions.py::test_copy_issue672",
|
| 266 |
+
"tests/test_regressions.py::test_primary_key_issue740",
|
| 267 |
+
"tests/test_regressions.py::test_max_recursion",
|
| 268 |
+
"tests/test_split.py::test_split_semicolon",
|
| 269 |
+
"tests/test_split.py::test_split_backslash",
|
| 270 |
+
"tests/test_split.py::test_split_create_function[function.sql]",
|
| 271 |
+
"tests/test_split.py::test_split_create_function[function_psql.sql]",
|
| 272 |
+
"tests/test_split.py::test_split_create_function[function_psql2.sql]",
|
| 273 |
+
"tests/test_split.py::test_split_create_function[function_psql3.sql]",
|
| 274 |
+
"tests/test_split.py::test_split_create_function[function_psql4.sql]",
|
| 275 |
+
"tests/test_split.py::test_split_dashcomments",
|
| 276 |
+
"tests/test_split.py::test_split_begintag",
|
| 277 |
+
"tests/test_split.py::test_split_begintag_2",
|
| 278 |
+
"tests/test_split.py::test_split_dropif",
|
| 279 |
+
"tests/test_split.py::test_split_comment_with_umlaut",
|
| 280 |
+
"tests/test_split.py::test_split_comment_end_of_line",
|
| 281 |
+
"tests/test_split.py::test_split_casewhen",
|
| 282 |
+
"tests/test_split.py::test_split_casewhen_procedure",
|
| 283 |
+
"tests/test_split.py::test_split_cursor_declare",
|
| 284 |
+
"tests/test_split.py::test_split_if_function",
|
| 285 |
+
"tests/test_split.py::test_split_stream",
|
| 286 |
+
"tests/test_split.py::test_split_encoding_parsestream",
|
| 287 |
+
"tests/test_split.py::test_split_unicode_parsestream",
|
| 288 |
+
"tests/test_split.py::test_split_simple",
|
| 289 |
+
"tests/test_split.py::test_split_ignores_empty_newlines",
|
| 290 |
+
"tests/test_split.py::test_split_quotes_with_new_line",
|
| 291 |
+
"tests/test_split.py::test_split_mysql_handler_for",
|
| 292 |
+
"tests/test_split.py::test_split_strip_semicolon_procedure",
|
| 293 |
+
"tests/test_split.py::test_split_multiple_case_in_begin",
|
| 294 |
+
"tests/test_tokenize.py::test_tokenize_simple",
|
| 295 |
+
"tests/test_tokenize.py::test_tokenize_backticks",
|
| 296 |
+
"tests/test_tokenize.py::test_tokenize_linebreaks[foo\\nbar\\n]",
|
| 297 |
+
"tests/test_tokenize.py::test_tokenize_linebreaks[foo\\rbar\\r]",
|
| 298 |
+
"tests/test_tokenize.py::test_tokenize_linebreaks[foo\\r\\nbar\\r\\n]",
|
| 299 |
+
"tests/test_tokenize.py::test_tokenize_linebreaks[foo\\r\\nbar\\n]",
|
| 300 |
+
"tests/test_tokenize.py::test_tokenize_inline_keywords",
|
| 301 |
+
"tests/test_tokenize.py::test_tokenize_negative_numbers",
|
| 302 |
+
"tests/test_tokenize.py::test_token_str",
|
| 303 |
+
"tests/test_tokenize.py::test_token_repr",
|
| 304 |
+
"tests/test_tokenize.py::test_token_flatten",
|
| 305 |
+
"tests/test_tokenize.py::test_tokenlist_repr",
|
| 306 |
+
"tests/test_tokenize.py::test_single_quotes",
|
| 307 |
+
"tests/test_tokenize.py::test_tokenlist_first",
|
| 308 |
+
"tests/test_tokenize.py::test_tokenlist_token_matching",
|
| 309 |
+
"tests/test_tokenize.py::test_stream_simple",
|
| 310 |
+
"tests/test_tokenize.py::test_stream_error",
|
| 311 |
+
"tests/test_tokenize.py::test_parse_join[JOIN]",
|
| 312 |
+
"tests/test_tokenize.py::test_parse_union",
|
| 313 |
+
"tests/test_tokenize.py::test_parse_endifloop[END\\t\\nIF]",
|
| 314 |
+
"tests/test_tokenize.py::test_parse_endifloop[END\\t\\nLOOP]",
|
| 315 |
+
"tests/test_tokenize.py::test_parse_order[ASC]",
|
| 316 |
+
"tests/test_tokenize.py::test_parse_order[DESC]",
|
| 317 |
+
"tests/test_tokenize.py::test_parse_identifiers[foo]",
|
| 318 |
+
"tests/test_tokenize.py::test_parse_identifiers[Foo]",
|
| 319 |
+
"tests/test_tokenize.py::test_parse_identifiers[FOO]",
|
| 320 |
+
"tests/test_tokenize.py::test_parse_identifiers[v$name]",
|
| 321 |
+
"tests/test_tokenize.py::test_parse_group_by",
|
| 322 |
+
"tests/test_tokenize.py::test_parse_order_by",
|
| 323 |
+
"tests/test_tokenize.py::test_parse_window_as",
|
| 324 |
+
"tests/test_tokenize.py::test_like_and_ilike_parsed_as_comparisons[LIKE]",
|
| 325 |
+
"tests/test_tokenize.py::test_like_and_ilike_parsed_as_comparisons[ILIKE]",
|
| 326 |
+
"tests/test_tokenize.py::test_near_like_and_ilike_parsed_appropriately[LIKEaaa]",
|
| 327 |
+
"tests/test_tokenize.py::test_near_like_and_ilike_parsed_appropriately[bILIKE]",
|
| 328 |
+
"tests/test_tokenize.py::test_near_like_and_ilike_parsed_appropriately[aaILIKEbb]",
|
| 329 |
+
"tests/test_tokenize.py::test_near_like_and_ilike_parsed_appropriately[NOTLIKE]",
|
| 330 |
+
"tests/test_tokenize.py::test_near_like_and_ilike_parsed_appropriately[NOTILIKE]",
|
| 331 |
+
"tests/test_tokenize.py::test_cli_commands",
|
| 332 |
+
"tests/test_utils.py::test_remove_quotes[None-None]",
|
| 333 |
+
"tests/test_utils.py::test_remove_quotes['foo'-foo]",
|
| 334 |
+
"tests/test_utils.py::test_remove_quotes[\"foo\"-foo]",
|
| 335 |
+
"tests/test_utils.py::test_remove_quotes[`foo`-foo]"
|
| 336 |
+
]
|
| 337 |
+
}
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/grade.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Trusted private pytest panel runner. Installed only in a fresh grader Job."""
|
| 2 |
+
|
| 3 |
+
import hashlib
|
| 4 |
+
import importlib.util
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
import shutil
|
| 8 |
+
import stat
|
| 9 |
+
import subprocess
|
| 10 |
+
from pathlib import Path, PurePosixPath
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def sha(raw):
|
| 14 |
+
return hashlib.sha256(raw).hexdigest()
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def safe(value):
|
| 18 |
+
path = PurePosixPath(value)
|
| 19 |
+
if (
|
| 20 |
+
path.is_absolute()
|
| 21 |
+
or path.as_posix() != value
|
| 22 |
+
or not path.parts
|
| 23 |
+
or any(part in {".", "..", ".git"} for part in path.parts)
|
| 24 |
+
):
|
| 25 |
+
raise ValueError("Unsafe trusted test path")
|
| 26 |
+
return path
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def restore(worktree, private, manifest):
|
| 30 |
+
worktree, private = Path(worktree), Path(private)
|
| 31 |
+
captured = {}
|
| 32 |
+
for name, expected in manifest["files"].items():
|
| 33 |
+
path = private / safe(name)
|
| 34 |
+
info = path.lstat()
|
| 35 |
+
raw = path.read_bytes() if stat.S_ISREG(info.st_mode) else b""
|
| 36 |
+
if (
|
| 37 |
+
not stat.S_ISREG(info.st_mode)
|
| 38 |
+
or len(raw) != expected["bytes"]
|
| 39 |
+
or sha(raw) != expected["sha256"]
|
| 40 |
+
or stat.S_IMODE(info.st_mode) != expected["mode"]
|
| 41 |
+
):
|
| 42 |
+
raise ValueError("Trusted private test bytes or modes drifted")
|
| 43 |
+
captured[name] = (raw, expected["mode"])
|
| 44 |
+
# Capture and verify every private byte before changing the submitted tree.
|
| 45 |
+
for name in manifest["directory_roots"]:
|
| 46 |
+
destination = worktree / safe(name)
|
| 47 |
+
if destination.is_symlink():
|
| 48 |
+
raise ValueError("Submitted test directory is a symlink")
|
| 49 |
+
for parent in destination.parents:
|
| 50 |
+
if parent == worktree:
|
| 51 |
+
break
|
| 52 |
+
if parent.is_symlink():
|
| 53 |
+
raise ValueError("Submitted test parent is a symlink")
|
| 54 |
+
if destination.exists():
|
| 55 |
+
if not destination.is_dir():
|
| 56 |
+
raise ValueError("Submitted test directory is not a directory")
|
| 57 |
+
shutil.rmtree(destination)
|
| 58 |
+
for name, (raw, mode) in captured.items():
|
| 59 |
+
destination = worktree / safe(name)
|
| 60 |
+
for parent in destination.parents:
|
| 61 |
+
if parent == worktree:
|
| 62 |
+
break
|
| 63 |
+
if parent.is_symlink():
|
| 64 |
+
raise ValueError("Submitted test parent is a symlink")
|
| 65 |
+
if destination.is_symlink():
|
| 66 |
+
raise ValueError("Submitted trusted file is a symlink")
|
| 67 |
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
| 68 |
+
destination.write_bytes(raw)
|
| 69 |
+
destination.chmod(mode)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def run(worktree, private_root, output, invoke=None):
|
| 73 |
+
private_root, output, worktree = Path(private_root), Path(output), Path(worktree)
|
| 74 |
+
expected = json.loads((private_root / "expected-panels.json").read_bytes())
|
| 75 |
+
config = json.loads((private_root / "panel-config.json").read_bytes())
|
| 76 |
+
manifest = json.loads((private_root / "trusted-inventory.json").read_bytes())
|
| 77 |
+
restore(worktree, private_root / "trusted", manifest)
|
| 78 |
+
output.mkdir(parents=True, exist_ok=True)
|
| 79 |
+
for name in (
|
| 80 |
+
"reward.txt",
|
| 81 |
+
"pass-to-pass.xml",
|
| 82 |
+
"fail-to-pass.xml",
|
| 83 |
+
"pytest-evidence.json",
|
| 84 |
+
):
|
| 85 |
+
(output / name).unlink(missing_ok=True)
|
| 86 |
+
environment = dict(os.environ)
|
| 87 |
+
for key in ("PYTEST_ADDOPTS", "PYTEST_DISABLE_PLUGIN_AUTOLOAD", "PYTHONPATH"):
|
| 88 |
+
environment.pop(key, None)
|
| 89 |
+
commands, native_exit = [], 0
|
| 90 |
+
invoke = invoke or subprocess.run
|
| 91 |
+
for group in ("pass-to-pass", "fail-to-pass"):
|
| 92 |
+
if (
|
| 93 |
+
not isinstance(expected[group], list)
|
| 94 |
+
or not expected[group]
|
| 95 |
+
or any(
|
| 96 |
+
not isinstance(target, str) or not target for target in expected[group]
|
| 97 |
+
)
|
| 98 |
+
):
|
| 99 |
+
raise ValueError("Frozen native pytest selectors are incomplete")
|
| 100 |
+
command = [
|
| 101 |
+
*config["official_pytest_argv"],
|
| 102 |
+
"--override-ini=addopts=",
|
| 103 |
+
"--junitxml=" + str(output / (group + ".xml")),
|
| 104 |
+
*expected[group],
|
| 105 |
+
]
|
| 106 |
+
result = invoke(command, cwd=worktree, env=environment, check=False)
|
| 107 |
+
native_exit = result.returncode
|
| 108 |
+
commands.append({"group": group, "argv": command, "exit_code": native_exit})
|
| 109 |
+
if native_exit != 0:
|
| 110 |
+
break
|
| 111 |
+
(output / "pytest-commands.json").write_text(
|
| 112 |
+
json.dumps(commands, sort_keys=True) + "\n"
|
| 113 |
+
)
|
| 114 |
+
spec = importlib.util.spec_from_file_location(
|
| 115 |
+
"trusted_pytest_result", private_root / "check_pytest.py"
|
| 116 |
+
)
|
| 117 |
+
checker = importlib.util.module_from_spec(spec)
|
| 118 |
+
spec.loader.exec_module(checker)
|
| 119 |
+
result = checker.assess(output, expected, native_exit)
|
| 120 |
+
(output / "reward.txt").write_text(str(result["reward"]) + "\n")
|
| 121 |
+
(output / "pytest-evidence.json").write_text(
|
| 122 |
+
json.dumps(result, sort_keys=True) + "\n"
|
| 123 |
+
)
|
| 124 |
+
return result
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
if __name__ == "__main__":
|
| 128 |
+
run("/testbed/repo", "/tests", "/logs/verifier")
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/panel-config.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"dependency_installation_pinned": false,
|
| 3 |
+
"official_install_cmds": [
|
| 4 |
+
"python -m pip install -e ."
|
| 5 |
+
],
|
| 6 |
+
"official_pytest_argv": [
|
| 7 |
+
"pytest",
|
| 8 |
+
"--disable-warnings",
|
| 9 |
+
"--color=no",
|
| 10 |
+
"--tb=no",
|
| 11 |
+
"--verbose"
|
| 12 |
+
],
|
| 13 |
+
"official_test_command": "source /opt/miniconda3/bin/activate; conda activate testbed; pytest --disable-warnings --color=no --tb=no --verbose",
|
| 14 |
+
"panel_normalization": "Override project addopts only to execute the exact frozen native panels; add JUnit output, preserve official pytest options and all selectors.",
|
| 15 |
+
"python_version": "3.10",
|
| 16 |
+
"source_bound_test_dependency_cmds": [
|
| 17 |
+
"python -m pip install pytest"
|
| 18 |
+
],
|
| 19 |
+
"test_dependency_source_sha256": {
|
| 20 |
+
"pyproject.toml": "f45ed1a6a2c302a1b5a63cba825e9ad451c511427317faf52cf94492cb9f3144"
|
| 21 |
+
}
|
| 22 |
+
}
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/test.sh
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -Eeuo pipefail
|
| 3 |
+
source /opt/miniconda3/bin/activate
|
| 4 |
+
conda activate testbed
|
| 5 |
+
cd /testbed/repo
|
| 6 |
+
exec python -I /tests/grade.py
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted-inventory.json
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"directory_roots": [
|
| 3 |
+
"tests"
|
| 4 |
+
],
|
| 5 |
+
"files": {
|
| 6 |
+
"pyproject.toml": {
|
| 7 |
+
"bytes": 2671,
|
| 8 |
+
"mode": 420,
|
| 9 |
+
"sha256": "f45ed1a6a2c302a1b5a63cba825e9ad451c511427317faf52cf94492cb9f3144"
|
| 10 |
+
},
|
| 11 |
+
"tests/__init__.py": {
|
| 12 |
+
"bytes": 0,
|
| 13 |
+
"mode": 420,
|
| 14 |
+
"sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
| 15 |
+
},
|
| 16 |
+
"tests/conftest.py": {
|
| 17 |
+
"bytes": 1571,
|
| 18 |
+
"mode": 420,
|
| 19 |
+
"sha256": "78a520624361004ba4d9928e332b8df9e99279bff81d73aa735e58b8fc4d7f60"
|
| 20 |
+
},
|
| 21 |
+
"tests/files/_Make_DirEntry.sql": {
|
| 22 |
+
"bytes": 109,
|
| 23 |
+
"mode": 420,
|
| 24 |
+
"sha256": "477c6e434484000c6d34d8a1189b636c8595a906bbfdaead27110d33be192361"
|
| 25 |
+
},
|
| 26 |
+
"tests/files/begintag.sql": {
|
| 27 |
+
"bytes": 45,
|
| 28 |
+
"mode": 420,
|
| 29 |
+
"sha256": "eaf3ccbbe3e8a519ec00d95e875cf2063da21be757e85fdd15c3e11627ca350f"
|
| 30 |
+
},
|
| 31 |
+
"tests/files/begintag_2.sql": {
|
| 32 |
+
"bytes": 357,
|
| 33 |
+
"mode": 420,
|
| 34 |
+
"sha256": "d2deb7406afd541424617d618413d632b079bd650622a58d797df197f92eead2"
|
| 35 |
+
},
|
| 36 |
+
"tests/files/casewhen_procedure.sql": {
|
| 37 |
+
"bytes": 150,
|
| 38 |
+
"mode": 420,
|
| 39 |
+
"sha256": "e2fffb5d1c32f750b652231ef6a8267797f91d902dd5fbd09cdafa1490d7a9f5"
|
| 40 |
+
},
|
| 41 |
+
"tests/files/dashcomment.sql": {
|
| 42 |
+
"bytes": 88,
|
| 43 |
+
"mode": 420,
|
| 44 |
+
"sha256": "77d2a0426573b95fea0f33ff300d29d8779d69f4d6aae52588d45832cc97a7f9"
|
| 45 |
+
},
|
| 46 |
+
"tests/files/encoding_gbk.sql": {
|
| 47 |
+
"bytes": 50,
|
| 48 |
+
"mode": 420,
|
| 49 |
+
"sha256": "b46e2aa2afd9973c1ecf6a1778b65c1b9c32eac1679d2dd733bff93bd8f71403"
|
| 50 |
+
},
|
| 51 |
+
"tests/files/encoding_utf8.sql": {
|
| 52 |
+
"bytes": 76,
|
| 53 |
+
"mode": 420,
|
| 54 |
+
"sha256": "abd229df1799a0e3cacf0262439ac446a6f9e1475a061a836d54f7bf71537dce"
|
| 55 |
+
},
|
| 56 |
+
"tests/files/function.sql": {
|
| 57 |
+
"bytes": 187,
|
| 58 |
+
"mode": 420,
|
| 59 |
+
"sha256": "f7ebcddcfa7366ac9ef1f2042e85980b9d1b709376504fbcac2fbaf31d500438"
|
| 60 |
+
},
|
| 61 |
+
"tests/files/function_psql.sql": {
|
| 62 |
+
"bytes": 3066,
|
| 63 |
+
"mode": 420,
|
| 64 |
+
"sha256": "374d3ad5a85b295656c80891414575d2e914b7d44441cf0c301c8ba7823ba6e2"
|
| 65 |
+
},
|
| 66 |
+
"tests/files/function_psql2.sql": {
|
| 67 |
+
"bytes": 177,
|
| 68 |
+
"mode": 420,
|
| 69 |
+
"sha256": "ca09b0d5ec71d6b14c3547bd1f50bbb43a3c41c67a82ea7da7925b4a360978eb"
|
| 70 |
+
},
|
| 71 |
+
"tests/files/function_psql3.sql": {
|
| 72 |
+
"bytes": 171,
|
| 73 |
+
"mode": 420,
|
| 74 |
+
"sha256": "ab11189f23be717c821e84b61a43d65be26898aab0ddc3312dd4c017460e8eb2"
|
| 75 |
+
},
|
| 76 |
+
"tests/files/function_psql4.sql": {
|
| 77 |
+
"bytes": 221,
|
| 78 |
+
"mode": 420,
|
| 79 |
+
"sha256": "855912b6749f5252ee5a9d0a701e3fd00e8436b50953d4cb21ad66e8bab836dc"
|
| 80 |
+
},
|
| 81 |
+
"tests/files/huge_select.sql": {
|
| 82 |
+
"bytes": 9434,
|
| 83 |
+
"mode": 420,
|
| 84 |
+
"sha256": "2833206b9559cbbac1bb0cb9c15fb66a593528ec47ae5b8168a56550903658e7"
|
| 85 |
+
},
|
| 86 |
+
"tests/files/multiple_case_in_begin.sql": {
|
| 87 |
+
"bytes": 193,
|
| 88 |
+
"mode": 420,
|
| 89 |
+
"sha256": "120212421cbff79b576e173d5e6f2bdd45d8a7e06cfc8379e595cdea6ee58cec"
|
| 90 |
+
},
|
| 91 |
+
"tests/files/mysql_handler.sql": {
|
| 92 |
+
"bytes": 134,
|
| 93 |
+
"mode": 420,
|
| 94 |
+
"sha256": "70142d797ca7acf904e77aaec0587fd578f5ce134860fd81fbe98166fcd87157"
|
| 95 |
+
},
|
| 96 |
+
"tests/files/stream.sql": {
|
| 97 |
+
"bytes": 44,
|
| 98 |
+
"mode": 420,
|
| 99 |
+
"sha256": "8d1fdb5798c601f75f6bbcc750d07544ea47452e78687151a39fd7eb3c4a64bb"
|
| 100 |
+
},
|
| 101 |
+
"tests/files/test_cp1251.sql": {
|
| 102 |
+
"bytes": 49,
|
| 103 |
+
"mode": 420,
|
| 104 |
+
"sha256": "46f1d9cafe3b6f90ee79096e434f4509f5fa725f9c1b307e9180b8e2318a90b2"
|
| 105 |
+
},
|
| 106 |
+
"tests/test_cli.py": {
|
| 107 |
+
"bytes": 3521,
|
| 108 |
+
"mode": 420,
|
| 109 |
+
"sha256": "2283827e9658c1d785ee377a792f209bcc66ef411784706ffdf24c50030c2d46"
|
| 110 |
+
},
|
| 111 |
+
"tests/test_format.py": {
|
| 112 |
+
"bytes": 28438,
|
| 113 |
+
"mode": 420,
|
| 114 |
+
"sha256": "becba5a71cf4890844f0d602dbafc1a1a8337e6cd207cd966c9a71808baf7a46"
|
| 115 |
+
},
|
| 116 |
+
"tests/test_grouping.py": {
|
| 117 |
+
"bytes": 23973,
|
| 118 |
+
"mode": 420,
|
| 119 |
+
"sha256": "355a2dc8089f4f396c52f7922f0e10e4f1eb1c6c2a5d3ea47c3ae86d8d1cccd3"
|
| 120 |
+
},
|
| 121 |
+
"tests/test_keywords.py": {
|
| 122 |
+
"bytes": 447,
|
| 123 |
+
"mode": 420,
|
| 124 |
+
"sha256": "149f6845de1ae252a0265cf3e91086c6259c131c0f7f7a7518ea628e7ad399a3"
|
| 125 |
+
},
|
| 126 |
+
"tests/test_parse.py": {
|
| 127 |
+
"bytes": 18335,
|
| 128 |
+
"mode": 420,
|
| 129 |
+
"sha256": "f979f4024d44443d50a17a0169ace2f6fd8693e2e513529f222f6e56e2898838"
|
| 130 |
+
},
|
| 131 |
+
"tests/test_regressions.py": {
|
| 132 |
+
"bytes": 14896,
|
| 133 |
+
"mode": 420,
|
| 134 |
+
"sha256": "2c7c6c70fb416836e46fe752463e280022ebe5c1ecdd7ec18795862644bcb70e"
|
| 135 |
+
},
|
| 136 |
+
"tests/test_split.py": {
|
| 137 |
+
"bytes": 6147,
|
| 138 |
+
"mode": 420,
|
| 139 |
+
"sha256": "28d8917cc41d1755e78416e79c9ad6bd9e781938ed0ad09a12e41d771fab3d48"
|
| 140 |
+
},
|
| 141 |
+
"tests/test_tokenize.py": {
|
| 142 |
+
"bytes": 6364,
|
| 143 |
+
"mode": 420,
|
| 144 |
+
"sha256": "a26ee60a83832e0dee1420ef2f7df84de3d19ce8a92e69fc4f2cc39c91fa8db3"
|
| 145 |
+
},
|
| 146 |
+
"tests/test_utils.py": {
|
| 147 |
+
"bytes": 268,
|
| 148 |
+
"mode": 420,
|
| 149 |
+
"sha256": "49ae35e7607af5c8a9b83b6f14f47c30d8fcdc27da06a677fd92bef3e55ab998"
|
| 150 |
+
}
|
| 151 |
+
}
|
| 152 |
+
}
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/pyproject.toml
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[build-system]
|
| 2 |
+
requires = ["hatchling"]
|
| 3 |
+
build-backend = "hatchling.build"
|
| 4 |
+
|
| 5 |
+
[project]
|
| 6 |
+
name = "sqlparse"
|
| 7 |
+
description = "A non-validating SQL parser."
|
| 8 |
+
authors = [{name = "Andi Albrecht", email = "albrecht.andi@gmail.com"}]
|
| 9 |
+
readme = "README.rst"
|
| 10 |
+
dynamic = ["version"]
|
| 11 |
+
classifiers = [
|
| 12 |
+
"Development Status :: 5 - Production/Stable",
|
| 13 |
+
"Intended Audience :: Developers",
|
| 14 |
+
"License :: OSI Approved :: BSD License",
|
| 15 |
+
"Operating System :: OS Independent",
|
| 16 |
+
"Programming Language :: Python",
|
| 17 |
+
"Programming Language :: Python :: 3",
|
| 18 |
+
"Programming Language :: Python :: 3 :: Only",
|
| 19 |
+
"Programming Language :: Python :: 3.8",
|
| 20 |
+
"Programming Language :: Python :: 3.9",
|
| 21 |
+
"Programming Language :: Python :: 3.10",
|
| 22 |
+
"Programming Language :: Python :: 3.11",
|
| 23 |
+
"Programming Language :: Python :: 3.12",
|
| 24 |
+
"Programming Language :: Python :: 3.13",
|
| 25 |
+
"Programming Language :: Python :: Implementation :: CPython",
|
| 26 |
+
"Programming Language :: Python :: Implementation :: PyPy",
|
| 27 |
+
"Topic :: Database",
|
| 28 |
+
"Topic :: Software Development",
|
| 29 |
+
]
|
| 30 |
+
requires-python = ">=3.8"
|
| 31 |
+
|
| 32 |
+
[project.urls]
|
| 33 |
+
Home = "https://github.com/andialbrecht/sqlparse"
|
| 34 |
+
Documentation = "https://sqlparse.readthedocs.io/"
|
| 35 |
+
"Release Notes" = "https://sqlparse.readthedocs.io/en/latest/changes.html"
|
| 36 |
+
Source = "https://github.com/andialbrecht/sqlparse"
|
| 37 |
+
Tracker = "https://github.com/andialbrecht/sqlparse/issues"
|
| 38 |
+
|
| 39 |
+
[project.scripts]
|
| 40 |
+
sqlformat = "sqlparse.__main__:main"
|
| 41 |
+
|
| 42 |
+
[project.optional-dependencies]
|
| 43 |
+
dev = [
|
| 44 |
+
"hatch",
|
| 45 |
+
"build",
|
| 46 |
+
]
|
| 47 |
+
doc = [
|
| 48 |
+
"sphinx",
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
+
[tool.hatch.version]
|
| 52 |
+
path = "sqlparse/__init__.py"
|
| 53 |
+
|
| 54 |
+
[tool.hatch.envs.default]
|
| 55 |
+
dependencies = [
|
| 56 |
+
"coverage[toml]>=6.5",
|
| 57 |
+
"pytest",
|
| 58 |
+
# switch to ruff, but fix problems first
|
| 59 |
+
# but check defaults!
|
| 60 |
+
# https://hatch.pypa.io/1.9/config/static-analysis/#default-settings
|
| 61 |
+
"flake8",
|
| 62 |
+
]
|
| 63 |
+
[tool.hatch.envs.default.scripts]
|
| 64 |
+
unittest = "pytest {args:tests}"
|
| 65 |
+
test-cov = "coverage run -m pytest {args:tests}"
|
| 66 |
+
cov-report = [
|
| 67 |
+
"- coverage combine",
|
| 68 |
+
"coverage report",
|
| 69 |
+
]
|
| 70 |
+
cov = [
|
| 71 |
+
"test-cov",
|
| 72 |
+
"cov-report",
|
| 73 |
+
]
|
| 74 |
+
check = "flake8 sqlparse/"
|
| 75 |
+
test = ["check", "unittest"]
|
| 76 |
+
|
| 77 |
+
[[tool.hatch.envs.all.matrix]]
|
| 78 |
+
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]
|
| 79 |
+
|
| 80 |
+
[tool.hatch.envs.types]
|
| 81 |
+
dependencies = [
|
| 82 |
+
"mypy>=1.0.0",
|
| 83 |
+
]
|
| 84 |
+
[tool.hatch.envs.types.scripts]
|
| 85 |
+
check = "mypy --install-types --non-interactive {args:sqlparse tests}"
|
| 86 |
+
|
| 87 |
+
[tool.coverage.run]
|
| 88 |
+
source_pkgs = ["sqlparse", "tests"]
|
| 89 |
+
branch = true
|
| 90 |
+
parallel = true
|
| 91 |
+
omit = [
|
| 92 |
+
"sqlparse/__main__.py",
|
| 93 |
+
]
|
| 94 |
+
|
| 95 |
+
[tool.coverage.paths]
|
| 96 |
+
sqlparse = ["sqlparse"]
|
| 97 |
+
tests = ["tests"]
|
| 98 |
+
|
| 99 |
+
[tool.coverage.report]
|
| 100 |
+
exclude_lines = [
|
| 101 |
+
"no cov",
|
| 102 |
+
"if __name__ == .__main__.:",
|
| 103 |
+
"if TYPE_CHECKING:",
|
| 104 |
+
]
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/__init__.py
ADDED
|
File without changes
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/conftest.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Helpers for testing."""
|
| 2 |
+
|
| 3 |
+
import io
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
DIR_PATH = os.path.dirname(__file__)
|
| 9 |
+
FILES_DIR = os.path.join(DIR_PATH, 'files')
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@pytest.fixture()
|
| 13 |
+
def filepath():
|
| 14 |
+
"""Returns full file path for test files."""
|
| 15 |
+
|
| 16 |
+
def make_filepath(filename):
|
| 17 |
+
# https://stackoverflow.com/questions/18011902/py-test-pass-a-parameter-to-a-fixture-function
|
| 18 |
+
# Alternate solution is to use parametrization `indirect=True`
|
| 19 |
+
# https://stackoverflow.com/questions/18011902/py-test-pass-a-parameter-to-a-fixture-function/33879151#33879151
|
| 20 |
+
# Syntax is noisy and requires specific variable names
|
| 21 |
+
return os.path.join(FILES_DIR, filename)
|
| 22 |
+
|
| 23 |
+
return make_filepath
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@pytest.fixture()
|
| 27 |
+
def load_file(filepath):
|
| 28 |
+
"""Opens filename with encoding and return its contents."""
|
| 29 |
+
|
| 30 |
+
def make_load_file(filename, encoding='utf-8'):
|
| 31 |
+
# https://stackoverflow.com/questions/18011902/py-test-pass-a-parameter-to-a-fixture-function
|
| 32 |
+
# Alternate solution is to use parametrization `indirect=True`
|
| 33 |
+
# https://stackoverflow.com/questions/18011902/py-test-pass-a-parameter-to-a-fixture-function/33879151#33879151
|
| 34 |
+
# Syntax is noisy and requires specific variable names
|
| 35 |
+
# And seems to be limited to only 1 argument.
|
| 36 |
+
with open(filepath(filename), encoding=encoding) as f:
|
| 37 |
+
return f.read().strip()
|
| 38 |
+
|
| 39 |
+
return make_load_file
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
@pytest.fixture()
|
| 43 |
+
def get_stream(filepath):
|
| 44 |
+
def make_stream(filename, encoding='utf-8'):
|
| 45 |
+
return open(filepath(filename), encoding=encoding)
|
| 46 |
+
|
| 47 |
+
return make_stream
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/_Make_DirEntry.sql
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-- Make a new dir entry
|
| 2 |
+
-- and return its inode
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
INSERT INTO dir_entries(type)
|
| 6 |
+
VALUES(:type)
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/begintag.sql
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
begin;
|
| 2 |
+
update foo
|
| 3 |
+
set bar = 1;
|
| 4 |
+
commit;
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/begintag_2.sql
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CREATE TRIGGER IF NOT EXISTS remove_if_it_was_the_last_file_link
|
| 2 |
+
-- Delete the direntry when is removed it's last static link
|
| 3 |
+
AFTER DELETE ON links
|
| 4 |
+
WHEN NOT EXISTS
|
| 5 |
+
(
|
| 6 |
+
SELECT * FROM links
|
| 7 |
+
WHERE child_entry = OLD.child_entry
|
| 8 |
+
LIMIT 1
|
| 9 |
+
)
|
| 10 |
+
BEGIN
|
| 11 |
+
DELETE FROM dir_entries
|
| 12 |
+
WHERE dir_entries.inode = OLD.child_entry;
|
| 13 |
+
END;
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/casewhen_procedure.sql
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
create procedure procName()
|
| 2 |
+
begin
|
| 3 |
+
select case when column = 'value' then column else 0 end;
|
| 4 |
+
end;
|
| 5 |
+
create procedure procName()
|
| 6 |
+
begin
|
| 7 |
+
select 1;
|
| 8 |
+
end;
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/dashcomment.sql
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
select * from user;
|
| 2 |
+
--select * from host;
|
| 3 |
+
select * from user;
|
| 4 |
+
select * -- foo;
|
| 5 |
+
from foo;
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/encoding_gbk.sql
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
select *
|
| 2 |
+
from foo
|
| 3 |
+
where bar = '������ϲ�����Լ���'
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/encoding_utf8.sql
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
select *
|
| 2 |
+
from foo
|
| 3 |
+
where bar = '齐天大圣.カラフルな雲.사랑해요'
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/function.sql
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CREATE OR REPLACE FUNCTION foo(
|
| 2 |
+
p_in1 VARCHAR
|
| 3 |
+
, p_in2 INTEGER
|
| 4 |
+
) RETURNS INTEGER AS
|
| 5 |
+
|
| 6 |
+
DECLARE
|
| 7 |
+
v_foo INTEGER;
|
| 8 |
+
BEGIN
|
| 9 |
+
SELECT *
|
| 10 |
+
FROM foo
|
| 11 |
+
INTO v_foo;
|
| 12 |
+
RETURN v_foo.id;
|
| 13 |
+
END;
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/function_psql.sql
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CREATE OR REPLACE FUNCTION public.delete_data (
|
| 2 |
+
p_tabelle VARCHAR
|
| 3 |
+
, p_key VARCHAR
|
| 4 |
+
, p_value INTEGER
|
| 5 |
+
) RETURNS INTEGER AS
|
| 6 |
+
$$
|
| 7 |
+
DECLARE
|
| 8 |
+
p_retval INTEGER;
|
| 9 |
+
v_constraint RECORD;
|
| 10 |
+
v_count INTEGER;
|
| 11 |
+
v_data RECORD;
|
| 12 |
+
v_fieldname VARCHAR;
|
| 13 |
+
v_sql VARCHAR;
|
| 14 |
+
v_key VARCHAR;
|
| 15 |
+
v_value INTEGER;
|
| 16 |
+
BEGIN
|
| 17 |
+
v_sql := 'SELECT COUNT(*) FROM ' || p_tabelle || ' WHERE ' || p_key || ' = ' || p_value;
|
| 18 |
+
--RAISE NOTICE '%', v_sql;
|
| 19 |
+
EXECUTE v_sql INTO v_count;
|
| 20 |
+
IF v_count::integer != 0 THEN
|
| 21 |
+
SELECT att.attname
|
| 22 |
+
INTO v_key
|
| 23 |
+
FROM pg_attribute att
|
| 24 |
+
LEFT JOIN pg_constraint con ON con.conrelid = att.attrelid
|
| 25 |
+
AND con.conkey[1] = att.attnum
|
| 26 |
+
AND con.contype = 'p', pg_type typ, pg_class rel, pg_namespace ns
|
| 27 |
+
WHERE att.attrelid = rel.oid
|
| 28 |
+
AND att.attnum > 0
|
| 29 |
+
AND typ.oid = att.atttypid
|
| 30 |
+
AND att.attisdropped = false
|
| 31 |
+
AND rel.relname = p_tabelle
|
| 32 |
+
AND con.conkey[1] = 1
|
| 33 |
+
AND ns.oid = rel.relnamespace
|
| 34 |
+
AND ns.nspname = 'public'
|
| 35 |
+
ORDER BY att.attnum;
|
| 36 |
+
v_sql := 'SELECT ' || v_key || ' AS id FROM ' || p_tabelle || ' WHERE ' || p_key || ' = ' || p_value;
|
| 37 |
+
FOR v_data IN EXECUTE v_sql
|
| 38 |
+
LOOP
|
| 39 |
+
--RAISE NOTICE ' -> % %', p_tabelle, v_data.id;
|
| 40 |
+
FOR v_constraint IN SELECT t.constraint_name
|
| 41 |
+
, t.constraint_type
|
| 42 |
+
, t.table_name
|
| 43 |
+
, c.column_name
|
| 44 |
+
FROM public.v_table_constraints t
|
| 45 |
+
, public.v_constraint_columns c
|
| 46 |
+
WHERE t.constraint_name = c.constraint_name
|
| 47 |
+
AND t.constraint_type = 'FOREIGN KEY'
|
| 48 |
+
AND c.table_name = p_tabelle
|
| 49 |
+
AND t.table_schema = 'public'
|
| 50 |
+
AND c.table_schema = 'public'
|
| 51 |
+
LOOP
|
| 52 |
+
v_fieldname := substring(v_constraint.constraint_name from 1 for length(v_constraint.constraint_name) - length(v_constraint.column_name) - 1);
|
| 53 |
+
IF (v_constraint.table_name = p_tabelle) AND (p_value = v_data.id) THEN
|
| 54 |
+
--RAISE NOTICE 'Skip (Selbstverweis)';
|
| 55 |
+
CONTINUE;
|
| 56 |
+
ELSE
|
| 57 |
+
PERFORM delete_data(v_constraint.table_name::varchar, v_fieldname::varchar, v_data.id::integer);
|
| 58 |
+
END IF;
|
| 59 |
+
END LOOP;
|
| 60 |
+
END LOOP;
|
| 61 |
+
v_sql := 'DELETE FROM ' || p_tabelle || ' WHERE ' || p_key || ' = ' || p_value;
|
| 62 |
+
--RAISE NOTICE '%', v_sql;
|
| 63 |
+
EXECUTE v_sql;
|
| 64 |
+
p_retval := 1;
|
| 65 |
+
ELSE
|
| 66 |
+
--RAISE NOTICE ' -> Keine Sätze gefunden';
|
| 67 |
+
p_retval := 0;
|
| 68 |
+
END IF;
|
| 69 |
+
RETURN p_retval;
|
| 70 |
+
END;
|
| 71 |
+
$$
|
| 72 |
+
LANGUAGE plpgsql;
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/function_psql2.sql
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CREATE OR REPLACE FUNCTION update_something() RETURNS void AS
|
| 2 |
+
$body$
|
| 3 |
+
BEGIN
|
| 4 |
+
raise notice 'foo';
|
| 5 |
+
END;
|
| 6 |
+
$body$
|
| 7 |
+
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/function_psql3.sql
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CREATE OR REPLACE FUNCTION foo() RETURNS integer AS
|
| 2 |
+
$body$
|
| 3 |
+
DECLARE
|
| 4 |
+
BEGIN
|
| 5 |
+
select * from foo;
|
| 6 |
+
END;
|
| 7 |
+
$body$
|
| 8 |
+
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/function_psql4.sql
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CREATE FUNCTION doubledollarinbody(var1 text) RETURNS text
|
| 2 |
+
/* see issue277 */
|
| 3 |
+
LANGUAGE plpgsql
|
| 4 |
+
AS $_$
|
| 5 |
+
DECLARE
|
| 6 |
+
str text;
|
| 7 |
+
BEGIN
|
| 8 |
+
str = $$'foo'$$||var1;
|
| 9 |
+
execute 'select '||str into str;
|
| 10 |
+
return str;
|
| 11 |
+
END
|
| 12 |
+
$_$;
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/huge_select.sql
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
select case when i = 0 then 1 else 0 end as col0, case when i = 1 then 1 else 1 end as col1, case when i = 2 then 1 else 2 end as col2, case when i = 3 then 1 else 3 end as col3, case when i = 4 then 1 else 4 end as col4, case when i = 5 then 1 else 5 end as col5, case when i = 6 then 1 else 6 end as col6, case when i = 7 then 1 else 7 end as col7, case when i = 8 then 1 else 8 end as col8, case when i = 9 then 1 else 9 end as col9, case when i = 10 then 1 else 10 end as col10, case when i = 11 then 1 else 11 end as col11, case when i = 12 then 1 else 12 end as col12, case when i = 13 then 1 else 13 end as col13, case when i = 14 then 1 else 14 end as col14, case when i = 15 then 1 else 15 end as col15, case when i = 16 then 1 else 16 end as col16, case when i = 17 then 1 else 17 end as col17, case when i = 18 then 1 else 18 end as col18, case when i = 19 then 1 else 19 end as col19, case when i = 20 then 1 else 20 end as col20, case when i = 21 then 1 else 21 end as col21, case when i = 22 then 1 else 22 end as col22 from foo UNION select case when i = 0 then 1 else 0 end as col0, case when i = 1 then 1 else 1 end as col1, case when i = 2 then 1 else 2 end as col2, case when i = 3 then 1 else 3 end as col3, case when i = 4 then 1 else 4 end as col4, case when i = 5 then 1 else 5 end as col5, case when i = 6 then 1 else 6 end as col6, case when i = 7 then 1 else 7 end as col7, case when i = 8 then 1 else 8 end as col8, case when i = 9 then 1 else 9 end as col9, case when i = 10 then 1 else 10 end as col10, case when i = 11 then 1 else 11 end as col11, case when i = 12 then 1 else 12 end as col12, case when i = 13 then 1 else 13 end as col13, case when i = 14 then 1 else 14 end as col14, case when i = 15 then 1 else 15 end as col15, case when i = 16 then 1 else 16 end as col16, case when i = 17 then 1 else 17 end as col17, case when i = 18 then 1 else 18 end as col18, case when i = 19 then 1 else 19 end as col19, case when i = 20 then 1 else 20 end as col20, case when i = 21 then 1 else 21 end as col21, case when i = 22 then 1 else 22 end as col22 from foo UNION select case when i = 0 then 1 else 0 end as col0, case when i = 1 then 1 else 1 end as col1, case when i = 2 then 1 else 2 end as col2, case when i = 3 then 1 else 3 end as col3, case when i = 4 then 1 else 4 end as col4, case when i = 5 then 1 else 5 end as col5, case when i = 6 then 1 else 6 end as col6, case when i = 7 then 1 else 7 end as col7, case when i = 8 then 1 else 8 end as col8, case when i = 9 then 1 else 9 end as col9, case when i = 10 then 1 else 10 end as col10, case when i = 11 then 1 else 11 end as col11, case when i = 12 then 1 else 12 end as col12, case when i = 13 then 1 else 13 end as col13, case when i = 14 then 1 else 14 end as col14, case when i = 15 then 1 else 15 end as col15, case when i = 16 then 1 else 16 end as col16, case when i = 17 then 1 else 17 end as col17, case when i = 18 then 1 else 18 end as col18, case when i = 19 then 1 else 19 end as col19, case when i = 20 then 1 else 20 end as col20, case when i = 21 then 1 else 21 end as col21, case when i = 22 then 1 else 22 end as col22 from foo UNION select case when i = 0 then 1 else 0 end as col0, case when i = 1 then 1 else 1 end as col1, case when i = 2 then 1 else 2 end as col2, case when i = 3 then 1 else 3 end as col3, case when i = 4 then 1 else 4 end as col4, case when i = 5 then 1 else 5 end as col5, case when i = 6 then 1 else 6 end as col6, case when i = 7 then 1 else 7 end as col7, case when i = 8 then 1 else 8 end as col8, case when i = 9 then 1 else 9 end as col9, case when i = 10 then 1 else 10 end as col10, case when i = 11 then 1 else 11 end as col11, case when i = 12 then 1 else 12 end as col12, case when i = 13 then 1 else 13 end as col13, case when i = 14 then 1 else 14 end as col14, case when i = 15 then 1 else 15 end as col15, case when i = 16 then 1 else 16 end as col16, case when i = 17 then 1 else 17 end as col17, case when i = 18 then 1 else 18 end as col18, case when i = 19 then 1 else 19 end as col19, case when i = 20 then 1 else 20 end as col20, case when i = 21 then 1 else 21 end as col21, case when i = 22 then 1 else 22 end as col22 from foo UNION select case when i = 0 then 1 else 0 end as col0, case when i = 1 then 1 else 1 end as col1, case when i = 2 then 1 else 2 end as col2, case when i = 3 then 1 else 3 end as col3, case when i = 4 then 1 else 4 end as col4, case when i = 5 then 1 else 5 end as col5, case when i = 6 then 1 else 6 end as col6, case when i = 7 then 1 else 7 end as col7, case when i = 8 then 1 else 8 end as col8, case when i = 9 then 1 else 9 end as col9, case when i = 10 then 1 else 10 end as col10, case when i = 11 then 1 else 11 end as col11, case when i = 12 then 1 else 12 end as col12, case when i = 13 then 1 else 13 end as col13, case when i = 14 then 1 else 14 end as col14, case when i = 15 then 1 else 15 end as col15, case when i = 16 then 1 else 16 end as col16, case when i = 17 then 1 else 17 end as col17, case when i = 18 then 1 else 18 end as col18, case when i = 19 then 1 else 19 end as col19, case when i = 20 then 1 else 20 end as col20, case when i = 21 then 1 else 21 end as col21, case when i = 22 then 1 else 22 end as col22 from foo UNION select case when i = 0 then 1 else 0 end as col0, case when i = 1 then 1 else 1 end as col1, case when i = 2 then 1 else 2 end as col2, case when i = 3 then 1 else 3 end as col3, case when i = 4 then 1 else 4 end as col4, case when i = 5 then 1 else 5 end as col5, case when i = 6 then 1 else 6 end as col6, case when i = 7 then 1 else 7 end as col7, case when i = 8 then 1 else 8 end as col8, case when i = 9 then 1 else 9 end as col9, case when i = 10 then 1 else 10 end as col10, case when i = 11 then 1 else 11 end as col11, case when i = 12 then 1 else 12 end as col12, case when i = 13 then 1 else 13 end as col13, case when i = 14 then 1 else 14 end as col14, case when i = 15 then 1 else 15 end as col15, case when i = 16 then 1 else 16 end as col16, case when i = 17 then 1 else 17 end as col17, case when i = 18 then 1 else 18 end as col18, case when i = 19 then 1 else 19 end as col19, case when i = 20 then 1 else 20 end as col20, case when i = 21 then 1 else 21 end as col21, case when i = 22 then 1 else 22 end as col22 from foo UNION select case when i = 0 then 1 else 0 end as col0, case when i = 1 then 1 else 1 end as col1, case when i = 2 then 1 else 2 end as col2, case when i = 3 then 1 else 3 end as col3, case when i = 4 then 1 else 4 end as col4, case when i = 5 then 1 else 5 end as col5, case when i = 6 then 1 else 6 end as col6, case when i = 7 then 1 else 7 end as col7, case when i = 8 then 1 else 8 end as col8, case when i = 9 then 1 else 9 end as col9, case when i = 10 then 1 else 10 end as col10, case when i = 11 then 1 else 11 end as col11, case when i = 12 then 1 else 12 end as col12, case when i = 13 then 1 else 13 end as col13, case when i = 14 then 1 else 14 end as col14, case when i = 15 then 1 else 15 end as col15, case when i = 16 then 1 else 16 end as col16, case when i = 17 then 1 else 17 end as col17, case when i = 18 then 1 else 18 end as col18, case when i = 19 then 1 else 19 end as col19, case when i = 20 then 1 else 20 end as col20, case when i = 21 then 1 else 21 end as col21, case when i = 22 then 1 else 22 end as col22 from foo UNION select case when i = 0 then 1 else 0 end as col0, case when i = 1 then 1 else 1 end as col1, case when i = 2 then 1 else 2 end as col2, case when i = 3 then 1 else 3 end as col3, case when i = 4 then 1 else 4 end as col4, case when i = 5 then 1 else 5 end as col5, case when i = 6 then 1 else 6 end as col6, case when i = 7 then 1 else 7 end as col7, case when i = 8 then 1 else 8 end as col8, case when i = 9 then 1 else 9 end as col9, case when i = 10 then 1 else 10 end as col10, case when i = 11 then 1 else 11 end as col11, case when i = 12 then 1 else 12 end as col12, case when i = 13 then 1 else 13 end as col13, case when i = 14 then 1 else 14 end as col14, case when i = 15 then 1 else 15 end as col15, case when i = 16 then 1 else 16 end as col16, case when i = 17 then 1 else 17 end as col17, case when i = 18 then 1 else 18 end as col18, case when i = 19 then 1 else 19 end as col19, case when i = 20 then 1 else 20 end as col20, case when i = 21 then 1 else 21 end as col21, case when i = 22 then 1 else 22 end as col22 from foo UNION select case when i = 0 then 1 else 0 end as col0, case when i = 1 then 1 else 1 end as col1, case when i = 2 then 1 else 2 end as col2, case when i = 3 then 1 else 3 end as col3, case when i = 4 then 1 else 4 end as col4, case when i = 5 then 1 else 5 end as col5, case when i = 6 then 1 else 6 end as col6, case when i = 7 then 1 else 7 end as col7, case when i = 8 then 1 else 8 end as col8, case when i = 9 then 1 else 9 end as col9, case when i = 10 then 1 else 10 end as col10, case when i = 11 then 1 else 11 end as col11, case when i = 12 then 1 else 12 end as col12, case when i = 13 then 1 else 13 end as col13, case when i = 14 then 1 else 14 end as col14, case when i = 15 then 1 else 15 end as col15, case when i = 16 then 1 else 16 end as col16, case when i = 17 then 1 else 17 end as col17, case when i = 18 then 1 else 18 end as col18, case when i = 19 then 1 else 19 end as col19, case when i = 20 then 1 else 20 end as col20, case when i = 21 then 1 else 21 end as col21, case when i = 22 then 1 else 22 end as col22 from foo
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/multiple_case_in_begin.sql
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CREATE TRIGGER mytrig
|
| 2 |
+
AFTER UPDATE OF vvv ON mytable
|
| 3 |
+
BEGIN
|
| 4 |
+
UPDATE aa
|
| 5 |
+
SET mycola = (CASE WHEN (A=1) THEN 2 END);
|
| 6 |
+
UPDATE bb
|
| 7 |
+
SET mycolb = (CASE WHEN (B=1) THEN 5 END);
|
| 8 |
+
END;
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/mysql_handler.sql
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
create procedure proc1()
|
| 2 |
+
begin
|
| 3 |
+
declare handler for foo begin end;
|
| 4 |
+
select 1;
|
| 5 |
+
end;
|
| 6 |
+
|
| 7 |
+
create procedure proc2()
|
| 8 |
+
begin
|
| 9 |
+
select 1;
|
| 10 |
+
end;
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/stream.sql
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-- this file is streamed in
|
| 2 |
+
insert into foo
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/files/test_cp1251.sql
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
insert into foo values (1); -- ����� ��� �������
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_cli.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
import sqlparse
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def test_cli_main_empty():
|
| 10 |
+
with pytest.raises(SystemExit):
|
| 11 |
+
sqlparse.cli.main([])
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def test_parser_empty():
|
| 15 |
+
with pytest.raises(SystemExit):
|
| 16 |
+
parser = sqlparse.cli.create_parser()
|
| 17 |
+
parser.parse_args([])
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def test_main_help():
|
| 21 |
+
# Call with the --help option as a basic sanity check.
|
| 22 |
+
with pytest.raises(SystemExit) as exinfo:
|
| 23 |
+
sqlparse.cli.main(["--help", ])
|
| 24 |
+
assert exinfo.value.code == 0
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_valid_args(filepath):
|
| 28 |
+
# test doesn't abort
|
| 29 |
+
path = filepath('function.sql')
|
| 30 |
+
assert sqlparse.cli.main([path, '-r']) is not None
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def test_invalid_choice(filepath):
|
| 34 |
+
path = filepath('function.sql')
|
| 35 |
+
with pytest.raises(SystemExit):
|
| 36 |
+
sqlparse.cli.main([path, '-l', 'Spanish'])
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def test_invalid_args(filepath, capsys):
|
| 40 |
+
path = filepath('function.sql')
|
| 41 |
+
sqlparse.cli.main([path, '-r', '--indent_width', '0'])
|
| 42 |
+
_, err = capsys.readouterr()
|
| 43 |
+
assert err == ("[ERROR] Invalid options: indent_width requires "
|
| 44 |
+
"a positive integer\n")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def test_invalid_infile(filepath, capsys):
|
| 48 |
+
path = filepath('missing.sql')
|
| 49 |
+
sqlparse.cli.main([path, '-r'])
|
| 50 |
+
_, err = capsys.readouterr()
|
| 51 |
+
assert err[:22] == "[ERROR] Failed to read"
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def test_invalid_outfile(filepath, capsys):
|
| 55 |
+
path = filepath('function.sql')
|
| 56 |
+
outpath = filepath('/missing/function.sql')
|
| 57 |
+
sqlparse.cli.main([path, '-r', '-o', outpath])
|
| 58 |
+
_, err = capsys.readouterr()
|
| 59 |
+
assert err[:22] == "[ERROR] Failed to open"
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def test_stdout(filepath, load_file, capsys):
|
| 63 |
+
path = filepath('begintag.sql')
|
| 64 |
+
expected = load_file('begintag.sql')
|
| 65 |
+
sqlparse.cli.main([path])
|
| 66 |
+
out, _ = capsys.readouterr()
|
| 67 |
+
assert out == expected
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def test_script():
|
| 71 |
+
# Call with the --help option as a basic sanity check.
|
| 72 |
+
cmd = [sys.executable, '-m', 'sqlparse.cli', '--help']
|
| 73 |
+
assert subprocess.call(cmd) == 0
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
@pytest.mark.parametrize('fpath, encoding', (
|
| 77 |
+
('encoding_utf8.sql', 'utf-8'),
|
| 78 |
+
('encoding_gbk.sql', 'gbk'),
|
| 79 |
+
))
|
| 80 |
+
def test_encoding_stdout(fpath, encoding, filepath, load_file, capfd):
|
| 81 |
+
path = filepath(fpath)
|
| 82 |
+
expected = load_file(fpath, encoding)
|
| 83 |
+
sqlparse.cli.main([path, '--encoding', encoding])
|
| 84 |
+
out, _ = capfd.readouterr()
|
| 85 |
+
assert out == expected
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
@pytest.mark.parametrize('fpath, encoding', (
|
| 89 |
+
('encoding_utf8.sql', 'utf-8'),
|
| 90 |
+
('encoding_gbk.sql', 'gbk'),
|
| 91 |
+
))
|
| 92 |
+
def test_encoding_output_file(fpath, encoding, filepath, load_file, tmpdir):
|
| 93 |
+
in_path = filepath(fpath)
|
| 94 |
+
expected = load_file(fpath, encoding)
|
| 95 |
+
out_path = tmpdir.dirname + '/encoding_out.sql'
|
| 96 |
+
sqlparse.cli.main([in_path, '--encoding', encoding, '-o', out_path])
|
| 97 |
+
out = load_file(out_path, encoding)
|
| 98 |
+
assert out == expected
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
@pytest.mark.parametrize('fpath, encoding', (
|
| 102 |
+
('encoding_utf8.sql', 'utf-8'),
|
| 103 |
+
('encoding_gbk.sql', 'gbk'),
|
| 104 |
+
))
|
| 105 |
+
def test_encoding_stdin(fpath, encoding, filepath, load_file, capfd):
|
| 106 |
+
path = filepath(fpath)
|
| 107 |
+
expected = load_file(fpath, encoding)
|
| 108 |
+
old_stdin = sys.stdin
|
| 109 |
+
with open(path) as f:
|
| 110 |
+
sys.stdin = f
|
| 111 |
+
sqlparse.cli.main(['-', '--encoding', encoding])
|
| 112 |
+
sys.stdin = old_stdin
|
| 113 |
+
out, _ = capfd.readouterr()
|
| 114 |
+
assert out == expected
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def test_encoding(filepath, capsys):
|
| 118 |
+
path = filepath('test_cp1251.sql')
|
| 119 |
+
expected = 'insert into foo values (1); -- Песня про надежду\n'
|
| 120 |
+
sqlparse.cli.main([path, '--encoding=cp1251'])
|
| 121 |
+
out, _ = capsys.readouterr()
|
| 122 |
+
assert out == expected
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_format.py
ADDED
|
@@ -0,0 +1,774 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
import sqlparse
|
| 4 |
+
from sqlparse.exceptions import SQLParseError
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TestFormat:
|
| 8 |
+
def test_keywordcase(self):
|
| 9 |
+
sql = 'select * from bar; -- select foo\n'
|
| 10 |
+
res = sqlparse.format(sql, keyword_case='upper')
|
| 11 |
+
assert res == 'SELECT * FROM bar; -- select foo\n'
|
| 12 |
+
res = sqlparse.format(sql, keyword_case='capitalize')
|
| 13 |
+
assert res == 'Select * From bar; -- select foo\n'
|
| 14 |
+
res = sqlparse.format(sql.upper(), keyword_case='lower')
|
| 15 |
+
assert res == 'select * from BAR; -- SELECT FOO\n'
|
| 16 |
+
|
| 17 |
+
def test_keywordcase_invalid_option(self):
|
| 18 |
+
sql = 'select * from bar; -- select foo\n'
|
| 19 |
+
with pytest.raises(SQLParseError):
|
| 20 |
+
sqlparse.format(sql, keyword_case='foo')
|
| 21 |
+
|
| 22 |
+
def test_identifiercase(self):
|
| 23 |
+
sql = 'select * from bar; -- select foo\n'
|
| 24 |
+
res = sqlparse.format(sql, identifier_case='upper')
|
| 25 |
+
assert res == 'select * from BAR; -- select foo\n'
|
| 26 |
+
res = sqlparse.format(sql, identifier_case='capitalize')
|
| 27 |
+
assert res == 'select * from Bar; -- select foo\n'
|
| 28 |
+
res = sqlparse.format(sql.upper(), identifier_case='lower')
|
| 29 |
+
assert res == 'SELECT * FROM bar; -- SELECT FOO\n'
|
| 30 |
+
|
| 31 |
+
def test_identifiercase_invalid_option(self):
|
| 32 |
+
sql = 'select * from bar; -- select foo\n'
|
| 33 |
+
with pytest.raises(SQLParseError):
|
| 34 |
+
sqlparse.format(sql, identifier_case='foo')
|
| 35 |
+
|
| 36 |
+
def test_identifiercase_quotes(self):
|
| 37 |
+
sql = 'select * from "foo"."bar"'
|
| 38 |
+
res = sqlparse.format(sql, identifier_case="upper")
|
| 39 |
+
assert res == 'select * from "foo"."bar"'
|
| 40 |
+
|
| 41 |
+
def test_strip_comments_single(self):
|
| 42 |
+
sql = 'select *-- statement starts here\nfrom foo'
|
| 43 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 44 |
+
assert res == 'select *\nfrom foo'
|
| 45 |
+
sql = 'select * -- statement starts here\nfrom foo'
|
| 46 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 47 |
+
assert res == 'select *\nfrom foo'
|
| 48 |
+
sql = 'select-- foo\nfrom -- bar\nwhere'
|
| 49 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 50 |
+
assert res == 'select\nfrom\nwhere'
|
| 51 |
+
sql = 'select *-- statement starts here\n\nfrom foo'
|
| 52 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 53 |
+
assert res == 'select *\n\nfrom foo'
|
| 54 |
+
sql = 'select * from foo-- statement starts here\nwhere'
|
| 55 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 56 |
+
assert res == 'select * from foo\nwhere'
|
| 57 |
+
sql = 'select a-- statement starts here\nfrom foo'
|
| 58 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 59 |
+
assert res == 'select a\nfrom foo'
|
| 60 |
+
sql = '--comment\nselect a-- statement starts here\n' \
|
| 61 |
+
'from foo--comment\nf'
|
| 62 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 63 |
+
assert res == 'select a\nfrom foo\nf'
|
| 64 |
+
|
| 65 |
+
def test_strip_comments_invalid_option(self):
|
| 66 |
+
sql = 'select-- foo\nfrom -- bar\nwhere'
|
| 67 |
+
with pytest.raises(SQLParseError):
|
| 68 |
+
sqlparse.format(sql, strip_comments=None)
|
| 69 |
+
|
| 70 |
+
def test_strip_comments_multi(self):
|
| 71 |
+
sql = '/* sql starts here */\nselect'
|
| 72 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 73 |
+
assert res == 'select'
|
| 74 |
+
sql = '/* sql starts here */ select'
|
| 75 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 76 |
+
assert res == ' select' # note whitespace is preserved, see issue 772
|
| 77 |
+
sql = '/*\n * sql starts here\n */\nselect'
|
| 78 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 79 |
+
assert res == 'select'
|
| 80 |
+
sql = 'select (/* sql starts here */ select 2)'
|
| 81 |
+
res = sqlparse.format(sql, strip_comments=True, strip_whitespace=True)
|
| 82 |
+
assert res == 'select (select 2)'
|
| 83 |
+
sql = 'select (/* sql /* starts here */ select 2)'
|
| 84 |
+
res = sqlparse.format(sql, strip_comments=True, strip_whitespace=True)
|
| 85 |
+
assert res == 'select (select 2)'
|
| 86 |
+
|
| 87 |
+
def test_strip_comments_preserves_linebreak(self):
|
| 88 |
+
sql = 'select * -- a comment\r\nfrom foo'
|
| 89 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 90 |
+
assert res == 'select *\nfrom foo'
|
| 91 |
+
sql = 'select * -- a comment\nfrom foo'
|
| 92 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 93 |
+
assert res == 'select *\nfrom foo'
|
| 94 |
+
sql = 'select * -- a comment\rfrom foo'
|
| 95 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 96 |
+
assert res == 'select *\nfrom foo'
|
| 97 |
+
sql = 'select * -- a comment\r\n\r\nfrom foo'
|
| 98 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 99 |
+
assert res == 'select *\n\nfrom foo'
|
| 100 |
+
sql = 'select * -- a comment\n\nfrom foo'
|
| 101 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 102 |
+
assert res == 'select *\n\nfrom foo'
|
| 103 |
+
|
| 104 |
+
def test_strip_comments_preserves_whitespace(self):
|
| 105 |
+
sql = 'SELECT 1/*bar*/ AS foo' # see issue772
|
| 106 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 107 |
+
assert res == 'SELECT 1 AS foo'
|
| 108 |
+
|
| 109 |
+
def test_strip_comments_preserves_hint(self):
|
| 110 |
+
sql = 'select --+full(u)'
|
| 111 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 112 |
+
assert res == sql
|
| 113 |
+
sql = '#+ hint\nselect * from foo'
|
| 114 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 115 |
+
assert res == sql
|
| 116 |
+
sql = 'select --+full(u)\n--comment simple'
|
| 117 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 118 |
+
assert res == 'select --+full(u)\n'
|
| 119 |
+
sql = '#+ hint\nselect * from foo\n# comment simple'
|
| 120 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 121 |
+
assert res == '#+ hint\nselect * from foo\n'
|
| 122 |
+
sql = 'SELECT /*+cluster(T)*/* FROM T_EEE T where A >:1'
|
| 123 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 124 |
+
assert res == sql
|
| 125 |
+
sql = 'insert /*+ DIRECT */ into sch.table_name as select * from foo'
|
| 126 |
+
res = sqlparse.format(sql, strip_comments=True)
|
| 127 |
+
assert res == sql
|
| 128 |
+
|
| 129 |
+
def test_strip_ws(self):
|
| 130 |
+
f = lambda sql: sqlparse.format(sql, strip_whitespace=True)
|
| 131 |
+
s = 'select\n* from foo\n\twhere ( 1 = 2 )\n'
|
| 132 |
+
assert f(s) == 'select * from foo where (1 = 2)'
|
| 133 |
+
s = 'select -- foo\nfrom bar\n'
|
| 134 |
+
assert f(s) == 'select -- foo\nfrom bar'
|
| 135 |
+
|
| 136 |
+
def test_strip_ws_invalid_option(self):
|
| 137 |
+
s = 'select -- foo\nfrom bar\n'
|
| 138 |
+
with pytest.raises(SQLParseError):
|
| 139 |
+
sqlparse.format(s, strip_whitespace=None)
|
| 140 |
+
|
| 141 |
+
def test_preserve_ws(self):
|
| 142 |
+
# preserve at least one whitespace after subgroups
|
| 143 |
+
f = lambda sql: sqlparse.format(sql, strip_whitespace=True)
|
| 144 |
+
s = 'select\n* /* foo */ from bar '
|
| 145 |
+
assert f(s) == 'select * /* foo */ from bar'
|
| 146 |
+
|
| 147 |
+
def test_notransform_of_quoted_crlf(self):
|
| 148 |
+
# Make sure that CR/CR+LF characters inside string literals don't get
|
| 149 |
+
# affected by the formatter.
|
| 150 |
+
|
| 151 |
+
s1 = "SELECT some_column LIKE 'value\r'"
|
| 152 |
+
s2 = "SELECT some_column LIKE 'value\r'\r\nWHERE id = 1\n"
|
| 153 |
+
s3 = "SELECT some_column LIKE 'value\\'\r' WHERE id = 1\r"
|
| 154 |
+
s4 = "SELECT some_column LIKE 'value\\\\\\'\r' WHERE id = 1\r\n"
|
| 155 |
+
|
| 156 |
+
f = lambda x: sqlparse.format(x)
|
| 157 |
+
|
| 158 |
+
# Because of the use of
|
| 159 |
+
assert f(s1) == "SELECT some_column LIKE 'value\r'"
|
| 160 |
+
assert f(s2) == "SELECT some_column LIKE 'value\r'\nWHERE id = 1\n"
|
| 161 |
+
assert f(s3) == "SELECT some_column LIKE 'value\\'\r' WHERE id = 1\n"
|
| 162 |
+
assert (f(s4)
|
| 163 |
+
== "SELECT some_column LIKE 'value\\\\\\'\r' WHERE id = 1\n")
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
class TestFormatReindentAligned:
|
| 167 |
+
@staticmethod
|
| 168 |
+
def formatter(sql):
|
| 169 |
+
return sqlparse.format(sql, reindent_aligned=True)
|
| 170 |
+
|
| 171 |
+
def test_basic(self):
|
| 172 |
+
sql = """
|
| 173 |
+
select a, b as bb,c from table
|
| 174 |
+
join (select a * 2 as a from new_table) other
|
| 175 |
+
on table.a = other.a
|
| 176 |
+
where c is true
|
| 177 |
+
and b between 3 and 4
|
| 178 |
+
or d is 'blue'
|
| 179 |
+
limit 10
|
| 180 |
+
"""
|
| 181 |
+
|
| 182 |
+
assert self.formatter(sql) == '\n'.join([
|
| 183 |
+
'select a,',
|
| 184 |
+
' b as bb,',
|
| 185 |
+
' c',
|
| 186 |
+
' from table',
|
| 187 |
+
' join (',
|
| 188 |
+
' select a * 2 as a',
|
| 189 |
+
' from new_table',
|
| 190 |
+
' ) other',
|
| 191 |
+
' on table.a = other.a',
|
| 192 |
+
' where c is true',
|
| 193 |
+
' and b between 3 and 4',
|
| 194 |
+
" or d is 'blue'",
|
| 195 |
+
' limit 10'])
|
| 196 |
+
|
| 197 |
+
def test_joins(self):
|
| 198 |
+
sql = """
|
| 199 |
+
select * from a
|
| 200 |
+
join b on a.one = b.one
|
| 201 |
+
left join c on c.two = a.two and c.three = a.three
|
| 202 |
+
full outer join d on d.three = a.three
|
| 203 |
+
cross join e on e.four = a.four
|
| 204 |
+
join f using (one, two, three)
|
| 205 |
+
"""
|
| 206 |
+
assert self.formatter(sql) == '\n'.join([
|
| 207 |
+
'select *',
|
| 208 |
+
' from a',
|
| 209 |
+
' join b',
|
| 210 |
+
' on a.one = b.one',
|
| 211 |
+
' left join c',
|
| 212 |
+
' on c.two = a.two',
|
| 213 |
+
' and c.three = a.three',
|
| 214 |
+
' full outer join d',
|
| 215 |
+
' on d.three = a.three',
|
| 216 |
+
' cross join e',
|
| 217 |
+
' on e.four = a.four',
|
| 218 |
+
' join f using (one, two, three)'])
|
| 219 |
+
|
| 220 |
+
def test_case_statement(self):
|
| 221 |
+
sql = """
|
| 222 |
+
select a,
|
| 223 |
+
case when a = 0
|
| 224 |
+
then 1
|
| 225 |
+
when bb = 1 then 1
|
| 226 |
+
when c = 2 then 2
|
| 227 |
+
else 0 end as d,
|
| 228 |
+
extra_col
|
| 229 |
+
from table
|
| 230 |
+
where c is true
|
| 231 |
+
and b between 3 and 4
|
| 232 |
+
"""
|
| 233 |
+
assert self.formatter(sql) == '\n'.join([
|
| 234 |
+
'select a,',
|
| 235 |
+
' case when a = 0 then 1',
|
| 236 |
+
' when bb = 1 then 1',
|
| 237 |
+
' when c = 2 then 2',
|
| 238 |
+
' else 0',
|
| 239 |
+
' end as d,',
|
| 240 |
+
' extra_col',
|
| 241 |
+
' from table',
|
| 242 |
+
' where c is true',
|
| 243 |
+
' and b between 3 and 4'])
|
| 244 |
+
|
| 245 |
+
def test_case_statement_with_between(self):
|
| 246 |
+
sql = """
|
| 247 |
+
select a,
|
| 248 |
+
case when a = 0
|
| 249 |
+
then 1
|
| 250 |
+
when bb = 1 then 1
|
| 251 |
+
when c = 2 then 2
|
| 252 |
+
when d between 3 and 5 then 3
|
| 253 |
+
else 0 end as d,
|
| 254 |
+
extra_col
|
| 255 |
+
from table
|
| 256 |
+
where c is true
|
| 257 |
+
and b between 3 and 4
|
| 258 |
+
"""
|
| 259 |
+
assert self.formatter(sql) == '\n'.join([
|
| 260 |
+
'select a,',
|
| 261 |
+
' case when a = 0 then 1',
|
| 262 |
+
' when bb = 1 then 1',
|
| 263 |
+
' when c = 2 then 2',
|
| 264 |
+
' when d between 3 and 5 then 3',
|
| 265 |
+
' else 0',
|
| 266 |
+
' end as d,',
|
| 267 |
+
' extra_col',
|
| 268 |
+
' from table',
|
| 269 |
+
' where c is true',
|
| 270 |
+
' and b between 3 and 4'])
|
| 271 |
+
|
| 272 |
+
def test_group_by(self):
|
| 273 |
+
sql = """
|
| 274 |
+
select a, b, c, sum(x) as sum_x, count(y) as cnt_y
|
| 275 |
+
from table
|
| 276 |
+
group by a,b,c
|
| 277 |
+
having sum(x) > 1
|
| 278 |
+
and count(y) > 5
|
| 279 |
+
order by 3,2,1
|
| 280 |
+
"""
|
| 281 |
+
assert self.formatter(sql) == '\n'.join([
|
| 282 |
+
'select a,',
|
| 283 |
+
' b,',
|
| 284 |
+
' c,',
|
| 285 |
+
' sum(x) as sum_x,',
|
| 286 |
+
' count(y) as cnt_y',
|
| 287 |
+
' from table',
|
| 288 |
+
' group by a,',
|
| 289 |
+
' b,',
|
| 290 |
+
' c',
|
| 291 |
+
'having sum(x) > 1',
|
| 292 |
+
' and count(y) > 5',
|
| 293 |
+
' order by 3,',
|
| 294 |
+
' 2,',
|
| 295 |
+
' 1'])
|
| 296 |
+
|
| 297 |
+
def test_group_by_subquery(self):
|
| 298 |
+
# TODO: add subquery alias when test_identifier_list_subquery fixed
|
| 299 |
+
sql = """
|
| 300 |
+
select *, sum_b + 2 as mod_sum
|
| 301 |
+
from (
|
| 302 |
+
select a, sum(b) as sum_b
|
| 303 |
+
from table
|
| 304 |
+
group by a,z)
|
| 305 |
+
order by 1,2
|
| 306 |
+
"""
|
| 307 |
+
assert self.formatter(sql) == '\n'.join([
|
| 308 |
+
'select *,',
|
| 309 |
+
' sum_b + 2 as mod_sum',
|
| 310 |
+
' from (',
|
| 311 |
+
' select a,',
|
| 312 |
+
' sum(b) as sum_b',
|
| 313 |
+
' from table',
|
| 314 |
+
' group by a,',
|
| 315 |
+
' z',
|
| 316 |
+
' )',
|
| 317 |
+
' order by 1,',
|
| 318 |
+
' 2'])
|
| 319 |
+
|
| 320 |
+
def test_window_functions(self):
|
| 321 |
+
sql = """
|
| 322 |
+
select a,
|
| 323 |
+
SUM(a) OVER (PARTITION BY b ORDER BY c ROWS
|
| 324 |
+
BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as sum_a,
|
| 325 |
+
ROW_NUMBER() OVER
|
| 326 |
+
(PARTITION BY b, c ORDER BY d DESC) as row_num
|
| 327 |
+
from table"""
|
| 328 |
+
assert self.formatter(sql) == '\n'.join([
|
| 329 |
+
'select a,',
|
| 330 |
+
' SUM(a) OVER (PARTITION BY b ORDER BY c ROWS '
|
| 331 |
+
'BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) as sum_a,',
|
| 332 |
+
' ROW_NUMBER() OVER '
|
| 333 |
+
'(PARTITION BY b, c ORDER BY d DESC) as row_num',
|
| 334 |
+
' from table'])
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
class TestSpacesAroundOperators:
|
| 338 |
+
@staticmethod
|
| 339 |
+
def formatter(sql):
|
| 340 |
+
return sqlparse.format(sql, use_space_around_operators=True)
|
| 341 |
+
|
| 342 |
+
def test_basic(self):
|
| 343 |
+
sql = ('select a+b as d from table '
|
| 344 |
+
'where (c-d)%2= 1 and e> 3.0/4 and z^2 <100')
|
| 345 |
+
assert self.formatter(sql) == (
|
| 346 |
+
'select a + b as d from table '
|
| 347 |
+
'where (c - d) % 2 = 1 and e > 3.0 / 4 and z ^ 2 < 100')
|
| 348 |
+
|
| 349 |
+
def test_bools(self):
|
| 350 |
+
sql = 'select * from table where a &&b or c||d'
|
| 351 |
+
assert self.formatter(
|
| 352 |
+
sql) == 'select * from table where a && b or c || d'
|
| 353 |
+
|
| 354 |
+
def test_nested(self):
|
| 355 |
+
sql = 'select *, case when a-b then c end from table'
|
| 356 |
+
assert self.formatter(
|
| 357 |
+
sql) == 'select *, case when a - b then c end from table'
|
| 358 |
+
|
| 359 |
+
def test_wildcard_vs_mult(self):
|
| 360 |
+
sql = 'select a*b-c from table'
|
| 361 |
+
assert self.formatter(sql) == 'select a * b - c from table'
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
class TestFormatReindent:
|
| 365 |
+
def test_option(self):
|
| 366 |
+
with pytest.raises(SQLParseError):
|
| 367 |
+
sqlparse.format('foo', reindent=2)
|
| 368 |
+
with pytest.raises(SQLParseError):
|
| 369 |
+
sqlparse.format('foo', indent_tabs=2)
|
| 370 |
+
with pytest.raises(SQLParseError):
|
| 371 |
+
sqlparse.format('foo', reindent=True, indent_width='foo')
|
| 372 |
+
with pytest.raises(SQLParseError):
|
| 373 |
+
sqlparse.format('foo', reindent=True, indent_width=-12)
|
| 374 |
+
with pytest.raises(SQLParseError):
|
| 375 |
+
sqlparse.format('foo', reindent=True, wrap_after='foo')
|
| 376 |
+
with pytest.raises(SQLParseError):
|
| 377 |
+
sqlparse.format('foo', reindent=True, wrap_after=-12)
|
| 378 |
+
with pytest.raises(SQLParseError):
|
| 379 |
+
sqlparse.format('foo', reindent=True, comma_first='foo')
|
| 380 |
+
|
| 381 |
+
def test_stmts(self):
|
| 382 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 383 |
+
s = 'select foo; select bar'
|
| 384 |
+
assert f(s) == 'select foo;\n\nselect bar'
|
| 385 |
+
s = 'select foo'
|
| 386 |
+
assert f(s) == 'select foo'
|
| 387 |
+
s = 'select foo; -- test\n select bar'
|
| 388 |
+
assert f(s) == 'select foo; -- test\n\nselect bar'
|
| 389 |
+
|
| 390 |
+
def test_keywords(self):
|
| 391 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 392 |
+
s = 'select * from foo union select * from bar;'
|
| 393 |
+
assert f(s) == '\n'.join([
|
| 394 |
+
'select *',
|
| 395 |
+
'from foo',
|
| 396 |
+
'union',
|
| 397 |
+
'select *',
|
| 398 |
+
'from bar;'])
|
| 399 |
+
|
| 400 |
+
def test_keywords_between(self):
|
| 401 |
+
# issue 14
|
| 402 |
+
# don't break AND after BETWEEN
|
| 403 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 404 |
+
s = 'and foo between 1 and 2 and bar = 3'
|
| 405 |
+
assert f(s) == '\n'.join([
|
| 406 |
+
'',
|
| 407 |
+
'and foo between 1 and 2',
|
| 408 |
+
'and bar = 3'])
|
| 409 |
+
|
| 410 |
+
def test_parenthesis(self):
|
| 411 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 412 |
+
s = 'select count(*) from (select * from foo);'
|
| 413 |
+
assert f(s) == '\n'.join([
|
| 414 |
+
'select count(*)',
|
| 415 |
+
'from',
|
| 416 |
+
' (select *',
|
| 417 |
+
' from foo);'])
|
| 418 |
+
assert f("select f(1)") == 'select f(1)'
|
| 419 |
+
assert f("select f( 1 )") == 'select f(1)'
|
| 420 |
+
assert f("select f(\n\n\n1\n\n\n)") == 'select f(1)'
|
| 421 |
+
assert f("select f(\n\n\n 1 \n\n\n)") == 'select f(1)'
|
| 422 |
+
assert f("select f(\n\n\n 1 \n\n\n)") == 'select f(1)'
|
| 423 |
+
|
| 424 |
+
def test_where(self):
|
| 425 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 426 |
+
s = 'select * from foo where bar = 1 and baz = 2 or bzz = 3;'
|
| 427 |
+
assert f(s) == '\n'.join([
|
| 428 |
+
'select *',
|
| 429 |
+
'from foo',
|
| 430 |
+
'where bar = 1',
|
| 431 |
+
' and baz = 2',
|
| 432 |
+
' or bzz = 3;'])
|
| 433 |
+
|
| 434 |
+
s = 'select * from foo where bar = 1 and (baz = 2 or bzz = 3);'
|
| 435 |
+
assert f(s) == '\n'.join([
|
| 436 |
+
'select *',
|
| 437 |
+
'from foo',
|
| 438 |
+
'where bar = 1',
|
| 439 |
+
' and (baz = 2',
|
| 440 |
+
' or bzz = 3);'])
|
| 441 |
+
|
| 442 |
+
def test_join(self):
|
| 443 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 444 |
+
s = 'select * from foo join bar on 1 = 2'
|
| 445 |
+
assert f(s) == '\n'.join([
|
| 446 |
+
'select *',
|
| 447 |
+
'from foo',
|
| 448 |
+
'join bar on 1 = 2'])
|
| 449 |
+
s = 'select * from foo inner join bar on 1 = 2'
|
| 450 |
+
assert f(s) == '\n'.join([
|
| 451 |
+
'select *',
|
| 452 |
+
'from foo',
|
| 453 |
+
'inner join bar on 1 = 2'])
|
| 454 |
+
s = 'select * from foo left outer join bar on 1 = 2'
|
| 455 |
+
assert f(s) == '\n'.join([
|
| 456 |
+
'select *',
|
| 457 |
+
'from foo',
|
| 458 |
+
'left outer join bar on 1 = 2'])
|
| 459 |
+
s = 'select * from foo straight_join bar on 1 = 2'
|
| 460 |
+
assert f(s) == '\n'.join([
|
| 461 |
+
'select *',
|
| 462 |
+
'from foo',
|
| 463 |
+
'straight_join bar on 1 = 2'])
|
| 464 |
+
|
| 465 |
+
def test_identifier_list(self):
|
| 466 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 467 |
+
s = 'select foo, bar, baz from table1, table2 where 1 = 2'
|
| 468 |
+
assert f(s) == '\n'.join([
|
| 469 |
+
'select foo,',
|
| 470 |
+
' bar,',
|
| 471 |
+
' baz',
|
| 472 |
+
'from table1,',
|
| 473 |
+
' table2',
|
| 474 |
+
'where 1 = 2'])
|
| 475 |
+
s = 'select a.*, b.id from a, b'
|
| 476 |
+
assert f(s) == '\n'.join([
|
| 477 |
+
'select a.*,',
|
| 478 |
+
' b.id',
|
| 479 |
+
'from a,',
|
| 480 |
+
' b'])
|
| 481 |
+
|
| 482 |
+
def test_identifier_list_with_wrap_after(self):
|
| 483 |
+
f = lambda sql: sqlparse.format(sql, reindent=True, wrap_after=14)
|
| 484 |
+
s = 'select foo, bar, baz from table1, table2 where 1 = 2'
|
| 485 |
+
assert f(s) == '\n'.join([
|
| 486 |
+
'select foo, bar,',
|
| 487 |
+
' baz',
|
| 488 |
+
'from table1, table2',
|
| 489 |
+
'where 1 = 2'])
|
| 490 |
+
|
| 491 |
+
def test_identifier_list_comment_first(self):
|
| 492 |
+
f = lambda sql: sqlparse.format(sql, reindent=True, comma_first=True)
|
| 493 |
+
# not the 3: It cleans up whitespace too!
|
| 494 |
+
s = 'select foo, bar, baz from table where foo in (1, 2,3)'
|
| 495 |
+
assert f(s) == '\n'.join([
|
| 496 |
+
'select foo',
|
| 497 |
+
' , bar',
|
| 498 |
+
' , baz',
|
| 499 |
+
'from table',
|
| 500 |
+
'where foo in (1',
|
| 501 |
+
' , 2',
|
| 502 |
+
' , 3)'])
|
| 503 |
+
|
| 504 |
+
def test_identifier_list_with_functions(self):
|
| 505 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 506 |
+
s = ("select 'abc' as foo, coalesce(col1, col2)||col3 as bar,"
|
| 507 |
+
"col3 from my_table")
|
| 508 |
+
assert f(s) == '\n'.join([
|
| 509 |
+
"select 'abc' as foo,",
|
| 510 |
+
" coalesce(col1, col2)||col3 as bar,",
|
| 511 |
+
" col3",
|
| 512 |
+
"from my_table"])
|
| 513 |
+
|
| 514 |
+
def test_long_identifier_list_with_functions(self):
|
| 515 |
+
f = lambda sql: sqlparse.format(sql, reindent=True, wrap_after=30)
|
| 516 |
+
s = ("select 'abc' as foo, json_build_object('a', a,"
|
| 517 |
+
"'b', b, 'c', c, 'd', d, 'e', e) as col2"
|
| 518 |
+
"col3 from my_table")
|
| 519 |
+
assert f(s) == '\n'.join([
|
| 520 |
+
"select 'abc' as foo,",
|
| 521 |
+
" json_build_object('a',",
|
| 522 |
+
" a, 'b', b, 'c', c, 'd', d,",
|
| 523 |
+
" 'e', e) as col2col3",
|
| 524 |
+
"from my_table"])
|
| 525 |
+
|
| 526 |
+
def test_case(self):
|
| 527 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 528 |
+
s = 'case when foo = 1 then 2 when foo = 3 then 4 else 5 end'
|
| 529 |
+
assert f(s) == '\n'.join([
|
| 530 |
+
'case',
|
| 531 |
+
' when foo = 1 then 2',
|
| 532 |
+
' when foo = 3 then 4',
|
| 533 |
+
' else 5',
|
| 534 |
+
'end'])
|
| 535 |
+
|
| 536 |
+
def test_case2(self):
|
| 537 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 538 |
+
s = 'case(foo) when bar = 1 then 2 else 3 end'
|
| 539 |
+
assert f(s) == '\n'.join([
|
| 540 |
+
'case(foo)',
|
| 541 |
+
' when bar = 1 then 2',
|
| 542 |
+
' else 3',
|
| 543 |
+
'end'])
|
| 544 |
+
|
| 545 |
+
def test_nested_identifier_list(self):
|
| 546 |
+
# issue4
|
| 547 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 548 |
+
s = '(foo as bar, bar1, bar2 as bar3, b4 as b5)'
|
| 549 |
+
assert f(s) == '\n'.join([
|
| 550 |
+
'(foo as bar,',
|
| 551 |
+
' bar1,',
|
| 552 |
+
' bar2 as bar3,',
|
| 553 |
+
' b4 as b5)'])
|
| 554 |
+
|
| 555 |
+
def test_duplicate_linebreaks(self):
|
| 556 |
+
# issue3
|
| 557 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 558 |
+
s = 'select c1 -- column1\nfrom foo'
|
| 559 |
+
assert f(s) == '\n'.join([
|
| 560 |
+
'select c1 -- column1',
|
| 561 |
+
'from foo'])
|
| 562 |
+
s = 'select c1 -- column1\nfrom foo'
|
| 563 |
+
r = sqlparse.format(s, reindent=True, strip_comments=True)
|
| 564 |
+
assert r == '\n'.join([
|
| 565 |
+
'select c1',
|
| 566 |
+
'from foo'])
|
| 567 |
+
s = 'select c1\nfrom foo\norder by c1'
|
| 568 |
+
assert f(s) == '\n'.join([
|
| 569 |
+
'select c1',
|
| 570 |
+
'from foo',
|
| 571 |
+
'order by c1'])
|
| 572 |
+
s = 'select c1 from t1 where (c1 = 1) order by c1'
|
| 573 |
+
assert f(s) == '\n'.join([
|
| 574 |
+
'select c1',
|
| 575 |
+
'from t1',
|
| 576 |
+
'where (c1 = 1)',
|
| 577 |
+
'order by c1'])
|
| 578 |
+
|
| 579 |
+
def test_keywordfunctions(self):
|
| 580 |
+
# issue36
|
| 581 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 582 |
+
s = 'select max(a) b, foo, bar'
|
| 583 |
+
assert f(s) == '\n'.join([
|
| 584 |
+
'select max(a) b,',
|
| 585 |
+
' foo,',
|
| 586 |
+
' bar'])
|
| 587 |
+
|
| 588 |
+
def test_identifier_and_functions(self):
|
| 589 |
+
# issue45
|
| 590 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 591 |
+
s = 'select foo.bar, nvl(1) from dual'
|
| 592 |
+
assert f(s) == '\n'.join([
|
| 593 |
+
'select foo.bar,',
|
| 594 |
+
' nvl(1)',
|
| 595 |
+
'from dual'])
|
| 596 |
+
|
| 597 |
+
def test_insert_values(self):
|
| 598 |
+
# issue 329
|
| 599 |
+
f = lambda sql: sqlparse.format(sql, reindent=True)
|
| 600 |
+
s = 'insert into foo values (1, 2)'
|
| 601 |
+
assert f(s) == '\n'.join([
|
| 602 |
+
'insert into foo',
|
| 603 |
+
'values (1, 2)'])
|
| 604 |
+
|
| 605 |
+
s = 'insert into foo values (1, 2), (3, 4), (5, 6)'
|
| 606 |
+
assert f(s) == '\n'.join([
|
| 607 |
+
'insert into foo',
|
| 608 |
+
'values (1, 2),',
|
| 609 |
+
' (3, 4),',
|
| 610 |
+
' (5, 6)'])
|
| 611 |
+
|
| 612 |
+
s = 'insert into foo(a, b) values (1, 2), (3, 4), (5, 6)'
|
| 613 |
+
assert f(s) == '\n'.join([
|
| 614 |
+
'insert into foo(a, b)',
|
| 615 |
+
'values (1, 2),',
|
| 616 |
+
' (3, 4),',
|
| 617 |
+
' (5, 6)'])
|
| 618 |
+
|
| 619 |
+
f = lambda sql: sqlparse.format(sql, reindent=True,
|
| 620 |
+
comma_first=True)
|
| 621 |
+
s = 'insert into foo values (1, 2)'
|
| 622 |
+
assert f(s) == '\n'.join([
|
| 623 |
+
'insert into foo',
|
| 624 |
+
'values (1, 2)'])
|
| 625 |
+
|
| 626 |
+
s = 'insert into foo values (1, 2), (3, 4), (5, 6)'
|
| 627 |
+
assert f(s) == '\n'.join([
|
| 628 |
+
'insert into foo',
|
| 629 |
+
'values (1, 2)',
|
| 630 |
+
' , (3, 4)',
|
| 631 |
+
' , (5, 6)'])
|
| 632 |
+
|
| 633 |
+
s = 'insert into foo(a, b) values (1, 2), (3, 4), (5, 6)'
|
| 634 |
+
assert f(s) == '\n'.join([
|
| 635 |
+
'insert into foo(a, b)',
|
| 636 |
+
'values (1, 2)',
|
| 637 |
+
' , (3, 4)',
|
| 638 |
+
' , (5, 6)'])
|
| 639 |
+
|
| 640 |
+
|
| 641 |
+
class TestOutputFormat:
|
| 642 |
+
def test_python(self):
|
| 643 |
+
sql = 'select * from foo;'
|
| 644 |
+
f = lambda sql: sqlparse.format(sql, output_format='python')
|
| 645 |
+
assert f(sql) == "sql = 'select * from foo;'"
|
| 646 |
+
f = lambda sql: sqlparse.format(sql, output_format='python',
|
| 647 |
+
reindent=True)
|
| 648 |
+
assert f(sql) == '\n'.join([
|
| 649 |
+
"sql = ('select * '",
|
| 650 |
+
" 'from foo;')"])
|
| 651 |
+
|
| 652 |
+
def test_python_multiple_statements(self):
|
| 653 |
+
sql = 'select * from foo; select 1 from dual'
|
| 654 |
+
f = lambda sql: sqlparse.format(sql, output_format='python')
|
| 655 |
+
assert f(sql) == '\n'.join([
|
| 656 |
+
"sql = 'select * from foo; '",
|
| 657 |
+
"sql2 = 'select 1 from dual'"])
|
| 658 |
+
|
| 659 |
+
@pytest.mark.xfail(reason="Needs fixing")
|
| 660 |
+
def test_python_multiple_statements_with_formatting(self):
|
| 661 |
+
sql = 'select * from foo; select 1 from dual'
|
| 662 |
+
f = lambda sql: sqlparse.format(sql, output_format='python',
|
| 663 |
+
reindent=True)
|
| 664 |
+
assert f(sql) == '\n'.join([
|
| 665 |
+
"sql = ('select * '",
|
| 666 |
+
" 'from foo;')",
|
| 667 |
+
"sql2 = ('select 1 '",
|
| 668 |
+
" 'from dual')"])
|
| 669 |
+
|
| 670 |
+
def test_php(self):
|
| 671 |
+
sql = 'select * from foo;'
|
| 672 |
+
f = lambda sql: sqlparse.format(sql, output_format='php')
|
| 673 |
+
assert f(sql) == '$sql = "select * from foo;";'
|
| 674 |
+
f = lambda sql: sqlparse.format(sql, output_format='php',
|
| 675 |
+
reindent=True)
|
| 676 |
+
assert f(sql) == '\n'.join([
|
| 677 |
+
'$sql = "select * ";',
|
| 678 |
+
'$sql .= "from foo;";'])
|
| 679 |
+
|
| 680 |
+
def test_sql(self):
|
| 681 |
+
# "sql" is an allowed option but has no effect
|
| 682 |
+
sql = 'select * from foo;'
|
| 683 |
+
f = lambda sql: sqlparse.format(sql, output_format='sql')
|
| 684 |
+
assert f(sql) == 'select * from foo;'
|
| 685 |
+
|
| 686 |
+
def test_invalid_option(self):
|
| 687 |
+
sql = 'select * from foo;'
|
| 688 |
+
with pytest.raises(SQLParseError):
|
| 689 |
+
sqlparse.format(sql, output_format='foo')
|
| 690 |
+
|
| 691 |
+
|
| 692 |
+
def test_format_column_ordering():
|
| 693 |
+
# issue89
|
| 694 |
+
sql = 'select * from foo order by c1 desc, c2, c3;'
|
| 695 |
+
formatted = sqlparse.format(sql, reindent=True)
|
| 696 |
+
expected = '\n'.join([
|
| 697 |
+
'select *',
|
| 698 |
+
'from foo',
|
| 699 |
+
'order by c1 desc,',
|
| 700 |
+
' c2,',
|
| 701 |
+
' c3;'])
|
| 702 |
+
assert formatted == expected
|
| 703 |
+
|
| 704 |
+
|
| 705 |
+
def test_truncate_strings():
|
| 706 |
+
sql = "update foo set value = '{}';".format('x' * 1000)
|
| 707 |
+
formatted = sqlparse.format(sql, truncate_strings=10)
|
| 708 |
+
assert formatted == "update foo set value = 'xxxxxxxxxx[...]';"
|
| 709 |
+
formatted = sqlparse.format(sql, truncate_strings=3, truncate_char='YYY')
|
| 710 |
+
assert formatted == "update foo set value = 'xxxYYY';"
|
| 711 |
+
|
| 712 |
+
|
| 713 |
+
@pytest.mark.parametrize('option', ['bar', -1, 0])
|
| 714 |
+
def test_truncate_strings_invalid_option2(option):
|
| 715 |
+
with pytest.raises(SQLParseError):
|
| 716 |
+
sqlparse.format('foo', truncate_strings=option)
|
| 717 |
+
|
| 718 |
+
|
| 719 |
+
@pytest.mark.parametrize('sql', [
|
| 720 |
+
'select verrrylongcolumn from foo',
|
| 721 |
+
'select "verrrylongcolumn" from "foo"'])
|
| 722 |
+
def test_truncate_strings_doesnt_truncate_identifiers(sql):
|
| 723 |
+
formatted = sqlparse.format(sql, truncate_strings=2)
|
| 724 |
+
assert formatted == sql
|
| 725 |
+
|
| 726 |
+
|
| 727 |
+
def test_having_produces_newline():
|
| 728 |
+
sql = ('select * from foo, bar where bar.id = foo.bar_id '
|
| 729 |
+
'having sum(bar.value) > 100')
|
| 730 |
+
formatted = sqlparse.format(sql, reindent=True)
|
| 731 |
+
expected = [
|
| 732 |
+
'select *',
|
| 733 |
+
'from foo,',
|
| 734 |
+
' bar',
|
| 735 |
+
'where bar.id = foo.bar_id',
|
| 736 |
+
'having sum(bar.value) > 100']
|
| 737 |
+
assert formatted == '\n'.join(expected)
|
| 738 |
+
|
| 739 |
+
|
| 740 |
+
@pytest.mark.parametrize('right_margin', ['ten', 2])
|
| 741 |
+
def test_format_right_margin_invalid_option(right_margin):
|
| 742 |
+
with pytest.raises(SQLParseError):
|
| 743 |
+
sqlparse.format('foo', right_margin=right_margin)
|
| 744 |
+
|
| 745 |
+
|
| 746 |
+
@pytest.mark.xfail(reason="Needs fixing")
|
| 747 |
+
def test_format_right_margin():
|
| 748 |
+
# TODO: Needs better test, only raises exception right now
|
| 749 |
+
sqlparse.format('foo', right_margin="79")
|
| 750 |
+
|
| 751 |
+
|
| 752 |
+
def test_format_json_ops(): # issue542
|
| 753 |
+
formatted = sqlparse.format(
|
| 754 |
+
"select foo->'bar', foo->'bar';", reindent=True)
|
| 755 |
+
expected = "select foo->'bar',\n foo->'bar';"
|
| 756 |
+
assert formatted == expected
|
| 757 |
+
|
| 758 |
+
|
| 759 |
+
@pytest.mark.parametrize('sql, expected_normal, expected_compact', [
|
| 760 |
+
('case when foo then 1 else bar end',
|
| 761 |
+
'case\n when foo then 1\n else bar\nend',
|
| 762 |
+
'case when foo then 1 else bar end')])
|
| 763 |
+
def test_compact(sql, expected_normal, expected_compact): # issue783
|
| 764 |
+
formatted_normal = sqlparse.format(sql, reindent=True)
|
| 765 |
+
formatted_compact = sqlparse.format(sql, reindent=True, compact=True)
|
| 766 |
+
assert formatted_normal == expected_normal
|
| 767 |
+
assert formatted_compact == expected_compact
|
| 768 |
+
|
| 769 |
+
|
| 770 |
+
def test_strip_ws_removes_trailing_ws_in_groups(): # issue782
|
| 771 |
+
formatted = sqlparse.format('( where foo = bar ) from',
|
| 772 |
+
strip_whitespace=True)
|
| 773 |
+
expected = '(where foo = bar) from'
|
| 774 |
+
assert formatted == expected
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
import sqlparse
|
| 4 |
+
from sqlparse import sql, tokens as T
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def test_grouping_parenthesis():
|
| 8 |
+
s = 'select (select (x3) x2) and (y2) bar'
|
| 9 |
+
parsed = sqlparse.parse(s)[0]
|
| 10 |
+
assert str(parsed) == s
|
| 11 |
+
assert len(parsed.tokens) == 7
|
| 12 |
+
assert isinstance(parsed.tokens[2], sql.Parenthesis)
|
| 13 |
+
assert isinstance(parsed.tokens[-1], sql.Identifier)
|
| 14 |
+
assert len(parsed.tokens[2].tokens) == 5
|
| 15 |
+
assert isinstance(parsed.tokens[2].tokens[3], sql.Identifier)
|
| 16 |
+
assert isinstance(parsed.tokens[2].tokens[3].tokens[0], sql.Parenthesis)
|
| 17 |
+
assert len(parsed.tokens[2].tokens[3].tokens) == 3
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@pytest.mark.parametrize('s', ['foo := 1;', 'foo := 1'])
|
| 21 |
+
def test_grouping_assignment(s):
|
| 22 |
+
parsed = sqlparse.parse(s)[0]
|
| 23 |
+
assert len(parsed.tokens) == 1
|
| 24 |
+
assert isinstance(parsed.tokens[0], sql.Assignment)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@pytest.mark.parametrize('s', ["x > DATE '2020-01-01'", "x > TIMESTAMP '2020-01-01 00:00:00'"])
|
| 28 |
+
def test_grouping_typed_literal(s):
|
| 29 |
+
parsed = sqlparse.parse(s)[0]
|
| 30 |
+
assert isinstance(parsed[0][4], sql.TypedLiteral)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@pytest.mark.parametrize('s, a, b', [
|
| 34 |
+
('select a from b where c < d + e', sql.Identifier, sql.Identifier),
|
| 35 |
+
('select a from b where c < d + interval \'1 day\'', sql.Identifier, sql.TypedLiteral),
|
| 36 |
+
('select a from b where c < d + interval \'6\' month', sql.Identifier, sql.TypedLiteral),
|
| 37 |
+
('select a from b where c < current_timestamp - interval \'1 day\'', sql.Token, sql.TypedLiteral),
|
| 38 |
+
])
|
| 39 |
+
def test_compare_expr(s, a, b):
|
| 40 |
+
parsed = sqlparse.parse(s)[0]
|
| 41 |
+
assert str(parsed) == s
|
| 42 |
+
assert isinstance(parsed.tokens[2], sql.Identifier)
|
| 43 |
+
assert isinstance(parsed.tokens[6], sql.Identifier)
|
| 44 |
+
assert isinstance(parsed.tokens[8], sql.Where)
|
| 45 |
+
assert len(parsed.tokens) == 9
|
| 46 |
+
where = parsed.tokens[8]
|
| 47 |
+
assert isinstance(where.tokens[2], sql.Comparison)
|
| 48 |
+
assert len(where.tokens) == 3
|
| 49 |
+
comparison = where.tokens[2]
|
| 50 |
+
assert isinstance(comparison.tokens[0], sql.Identifier)
|
| 51 |
+
assert comparison.tokens[2].ttype is T.Operator.Comparison
|
| 52 |
+
assert isinstance(comparison.tokens[4], sql.Operation)
|
| 53 |
+
assert len(comparison.tokens) == 5
|
| 54 |
+
operation = comparison.tokens[4]
|
| 55 |
+
assert isinstance(operation.tokens[0], a)
|
| 56 |
+
assert operation.tokens[2].ttype is T.Operator
|
| 57 |
+
assert isinstance(operation.tokens[4], b)
|
| 58 |
+
assert len(operation.tokens) == 5
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def test_grouping_identifiers():
|
| 62 |
+
s = 'select foo.bar from "myscheme"."table" where fail. order'
|
| 63 |
+
parsed = sqlparse.parse(s)[0]
|
| 64 |
+
assert str(parsed) == s
|
| 65 |
+
assert isinstance(parsed.tokens[2], sql.Identifier)
|
| 66 |
+
assert isinstance(parsed.tokens[6], sql.Identifier)
|
| 67 |
+
assert isinstance(parsed.tokens[8], sql.Where)
|
| 68 |
+
s = 'select * from foo where foo.id = 1'
|
| 69 |
+
parsed = sqlparse.parse(s)[0]
|
| 70 |
+
assert str(parsed) == s
|
| 71 |
+
assert isinstance(parsed.tokens[-1].tokens[-1].tokens[0], sql.Identifier)
|
| 72 |
+
s = 'select * from (select "foo"."id" from foo)'
|
| 73 |
+
parsed = sqlparse.parse(s)[0]
|
| 74 |
+
assert str(parsed) == s
|
| 75 |
+
assert isinstance(parsed.tokens[-1].tokens[3], sql.Identifier)
|
| 76 |
+
|
| 77 |
+
for s in ["INSERT INTO `test` VALUES('foo', 'bar');",
|
| 78 |
+
"INSERT INTO `test` VALUES(1, 2), (3, 4), (5, 6);",
|
| 79 |
+
"INSERT INTO `test(a, b)` VALUES(1, 2), (3, 4), (5, 6);"]:
|
| 80 |
+
parsed = sqlparse.parse(s)[0]
|
| 81 |
+
types = [l.ttype for l in parsed.tokens if not l.is_whitespace]
|
| 82 |
+
assert types == [T.DML, T.Keyword, None, None, T.Punctuation]
|
| 83 |
+
assert isinstance(parsed.tokens[6], sql.Values)
|
| 84 |
+
|
| 85 |
+
s = "select 1.0*(a+b) as col, sum(c)/sum(d) from myschema.mytable"
|
| 86 |
+
parsed = sqlparse.parse(s)[0]
|
| 87 |
+
assert len(parsed.tokens) == 7
|
| 88 |
+
assert isinstance(parsed.tokens[2], sql.IdentifierList)
|
| 89 |
+
assert len(parsed.tokens[2].tokens) == 4
|
| 90 |
+
identifiers = list(parsed.tokens[2].get_identifiers())
|
| 91 |
+
assert len(identifiers) == 2
|
| 92 |
+
assert identifiers[0].get_alias() == "col"
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
@pytest.mark.parametrize('s', [
|
| 96 |
+
'1 as f',
|
| 97 |
+
'foo as f',
|
| 98 |
+
'foo f',
|
| 99 |
+
'1/2 as f',
|
| 100 |
+
'1/2 f',
|
| 101 |
+
'1<2 as f', # issue327
|
| 102 |
+
'1<2 f',
|
| 103 |
+
])
|
| 104 |
+
def test_simple_identifiers(s):
|
| 105 |
+
parsed = sqlparse.parse(s)[0]
|
| 106 |
+
assert isinstance(parsed.tokens[0], sql.Identifier)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
@pytest.mark.parametrize('s', [
|
| 110 |
+
'foo, bar',
|
| 111 |
+
'sum(a), sum(b)',
|
| 112 |
+
'sum(a) as x, b as y',
|
| 113 |
+
'sum(a)::integer, b',
|
| 114 |
+
'sum(a)/count(b) as x, y',
|
| 115 |
+
'sum(a)::integer as x, y',
|
| 116 |
+
'sum(a)::integer/count(b) as x, y', # issue297
|
| 117 |
+
])
|
| 118 |
+
def test_group_identifier_list(s):
|
| 119 |
+
parsed = sqlparse.parse(s)[0]
|
| 120 |
+
assert isinstance(parsed.tokens[0], sql.IdentifierList)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def test_grouping_identifier_wildcard():
|
| 124 |
+
p = sqlparse.parse('a.*, b.id')[0]
|
| 125 |
+
assert isinstance(p.tokens[0], sql.IdentifierList)
|
| 126 |
+
assert isinstance(p.tokens[0].tokens[0], sql.Identifier)
|
| 127 |
+
assert isinstance(p.tokens[0].tokens[-1], sql.Identifier)
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def test_grouping_identifier_name_wildcard():
|
| 131 |
+
p = sqlparse.parse('a.*')[0]
|
| 132 |
+
t = p.tokens[0]
|
| 133 |
+
assert t.get_name() == '*'
|
| 134 |
+
assert t.is_wildcard() is True
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def test_grouping_identifier_invalid():
|
| 138 |
+
p = sqlparse.parse('a.')[0]
|
| 139 |
+
assert isinstance(p.tokens[0], sql.Identifier)
|
| 140 |
+
assert p.tokens[0].has_alias() is False
|
| 141 |
+
assert p.tokens[0].get_name() is None
|
| 142 |
+
assert p.tokens[0].get_real_name() is None
|
| 143 |
+
assert p.tokens[0].get_parent_name() == 'a'
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def test_grouping_identifier_invalid_in_middle():
|
| 147 |
+
# issue261
|
| 148 |
+
s = 'SELECT foo. FROM foo'
|
| 149 |
+
p = sqlparse.parse(s)[0]
|
| 150 |
+
assert isinstance(p[2], sql.Identifier)
|
| 151 |
+
assert p[2][1].ttype == T.Punctuation
|
| 152 |
+
assert p[3].ttype == T.Whitespace
|
| 153 |
+
assert str(p[2]) == 'foo.'
|
| 154 |
+
|
| 155 |
+
@pytest.mark.parametrize('s', ['foo as (select *)', 'foo as(select *)'])
|
| 156 |
+
def test_grouping_identifer_as(s):
|
| 157 |
+
# issue507
|
| 158 |
+
p = sqlparse.parse(s)[0]
|
| 159 |
+
assert isinstance(p.tokens[0], sql.Identifier)
|
| 160 |
+
token = p.tokens[0].tokens[2]
|
| 161 |
+
assert token.ttype == T.Keyword
|
| 162 |
+
assert token.normalized == 'AS'
|
| 163 |
+
|
| 164 |
+
def test_grouping_identifier_as_invalid():
|
| 165 |
+
# issue8
|
| 166 |
+
p = sqlparse.parse('foo as select *')[0]
|
| 167 |
+
assert len(p.tokens), 5
|
| 168 |
+
assert isinstance(p.tokens[0], sql.Identifier)
|
| 169 |
+
assert len(p.tokens[0].tokens) == 1
|
| 170 |
+
assert p.tokens[2].ttype == T.Keyword
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
def test_grouping_identifier_function():
|
| 174 |
+
p = sqlparse.parse('foo() as bar')[0]
|
| 175 |
+
assert isinstance(p.tokens[0], sql.Identifier)
|
| 176 |
+
assert isinstance(p.tokens[0].tokens[0], sql.Function)
|
| 177 |
+
p = sqlparse.parse('foo()||col2 bar')[0]
|
| 178 |
+
assert isinstance(p.tokens[0], sql.Identifier)
|
| 179 |
+
assert isinstance(p.tokens[0].tokens[0], sql.Operation)
|
| 180 |
+
assert isinstance(p.tokens[0].tokens[0].tokens[0], sql.Function)
|
| 181 |
+
p = sqlparse.parse('foo(c1) over win1 as bar')[0]
|
| 182 |
+
assert isinstance(p.tokens[0], sql.Identifier)
|
| 183 |
+
assert isinstance(p.tokens[0].tokens[0], sql.Function)
|
| 184 |
+
assert len(p.tokens[0].tokens[0].tokens) == 4
|
| 185 |
+
assert isinstance(p.tokens[0].tokens[0].tokens[3], sql.Over)
|
| 186 |
+
assert isinstance(p.tokens[0].tokens[0].tokens[3].tokens[2],
|
| 187 |
+
sql.Identifier)
|
| 188 |
+
p = sqlparse.parse('foo(c1) over (partition by c2 order by c3) as bar')[0]
|
| 189 |
+
assert isinstance(p.tokens[0], sql.Identifier)
|
| 190 |
+
assert isinstance(p.tokens[0].tokens[0], sql.Function)
|
| 191 |
+
assert len(p.tokens[0].tokens[0].tokens) == 4
|
| 192 |
+
assert isinstance(p.tokens[0].tokens[0].tokens[3], sql.Over)
|
| 193 |
+
assert isinstance(p.tokens[0].tokens[0].tokens[3].tokens[2],
|
| 194 |
+
sql.Parenthesis)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
@pytest.mark.parametrize('s', ['foo+100', 'foo + 100', 'foo*100'])
|
| 198 |
+
def test_grouping_operation(s):
|
| 199 |
+
p = sqlparse.parse(s)[0]
|
| 200 |
+
assert isinstance(p.tokens[0], sql.Operation)
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def test_grouping_identifier_list():
|
| 204 |
+
p = sqlparse.parse('a, b, c')[0]
|
| 205 |
+
assert isinstance(p.tokens[0], sql.IdentifierList)
|
| 206 |
+
p = sqlparse.parse('(a, b, c)')[0]
|
| 207 |
+
assert isinstance(p.tokens[0].tokens[1], sql.IdentifierList)
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def test_grouping_identifier_list_subquery():
|
| 211 |
+
"""identifier lists should still work in subqueries with aliases"""
|
| 212 |
+
p = sqlparse.parse("select * from ("
|
| 213 |
+
"select a, b + c as d from table) sub")[0]
|
| 214 |
+
subquery = p.tokens[-1].tokens[0]
|
| 215 |
+
idx, iden_list = subquery.token_next_by(i=sql.IdentifierList)
|
| 216 |
+
assert iden_list is not None
|
| 217 |
+
# all the identifiers should be within the IdentifierList
|
| 218 |
+
_, ilist = subquery.token_next_by(i=sql.Identifier, idx=idx)
|
| 219 |
+
assert ilist is None
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def test_grouping_identifier_list_case():
|
| 223 |
+
p = sqlparse.parse('a, case when 1 then 2 else 3 end as b, c')[0]
|
| 224 |
+
assert isinstance(p.tokens[0], sql.IdentifierList)
|
| 225 |
+
p = sqlparse.parse('(a, case when 1 then 2 else 3 end as b, c)')[0]
|
| 226 |
+
assert isinstance(p.tokens[0].tokens[1], sql.IdentifierList)
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def test_grouping_identifier_list_other():
|
| 230 |
+
# issue2
|
| 231 |
+
p = sqlparse.parse("select *, null, 1, 'foo', bar from mytable, x")[0]
|
| 232 |
+
assert isinstance(p.tokens[2], sql.IdentifierList)
|
| 233 |
+
assert len(p.tokens[2].tokens) == 13
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def test_grouping_identifier_list_with_inline_comments():
|
| 237 |
+
# issue163
|
| 238 |
+
p = sqlparse.parse('foo /* a comment */, bar')[0]
|
| 239 |
+
assert isinstance(p.tokens[0], sql.IdentifierList)
|
| 240 |
+
assert isinstance(p.tokens[0].tokens[0], sql.Identifier)
|
| 241 |
+
assert isinstance(p.tokens[0].tokens[3], sql.Identifier)
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def test_grouping_identifiers_with_operators():
|
| 245 |
+
p = sqlparse.parse('a+b as c from table where (d-e)%2= 1')[0]
|
| 246 |
+
assert len([x for x in p.flatten() if x.ttype == T.Name]) == 5
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def test_grouping_identifier_list_with_order():
|
| 250 |
+
# issue101
|
| 251 |
+
p = sqlparse.parse('1, 2 desc, 3')[0]
|
| 252 |
+
assert isinstance(p.tokens[0], sql.IdentifierList)
|
| 253 |
+
assert isinstance(p.tokens[0].tokens[3], sql.Identifier)
|
| 254 |
+
assert str(p.tokens[0].tokens[3]) == '2 desc'
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def test_grouping_nested_identifier_with_order():
|
| 258 |
+
# issue745
|
| 259 |
+
p = sqlparse.parse('(a desc)')[0]
|
| 260 |
+
assert isinstance(p.tokens[0], sql.Parenthesis)
|
| 261 |
+
assert isinstance(p.tokens[0].tokens[1], sql.Identifier)
|
| 262 |
+
assert str(p.tokens[0].tokens[1]) == 'a desc'
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
def test_grouping_where():
|
| 266 |
+
s = 'select * from foo where bar = 1 order by id desc'
|
| 267 |
+
p = sqlparse.parse(s)[0]
|
| 268 |
+
assert str(p) == s
|
| 269 |
+
assert len(p.tokens) == 12
|
| 270 |
+
|
| 271 |
+
s = 'select x from (select y from foo where bar = 1) z'
|
| 272 |
+
p = sqlparse.parse(s)[0]
|
| 273 |
+
assert str(p) == s
|
| 274 |
+
assert isinstance(p.tokens[-1].tokens[0].tokens[-2], sql.Where)
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
@pytest.mark.parametrize('s', (
|
| 278 |
+
'select 1 where 1 = 2 union select 2',
|
| 279 |
+
'select 1 where 1 = 2 union all select 2',
|
| 280 |
+
))
|
| 281 |
+
def test_grouping_where_union(s):
|
| 282 |
+
p = sqlparse.parse(s)[0]
|
| 283 |
+
assert p.tokens[5].value.startswith('union')
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
def test_returning_kw_ends_where_clause():
|
| 287 |
+
s = 'delete from foo where x > y returning z'
|
| 288 |
+
p = sqlparse.parse(s)[0]
|
| 289 |
+
assert isinstance(p.tokens[6], sql.Where)
|
| 290 |
+
assert p.tokens[7].ttype == T.Keyword
|
| 291 |
+
assert p.tokens[7].value == 'returning'
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def test_into_kw_ends_where_clause(): # issue324
|
| 295 |
+
s = 'select * from foo where a = 1 into baz'
|
| 296 |
+
p = sqlparse.parse(s)[0]
|
| 297 |
+
assert isinstance(p.tokens[8], sql.Where)
|
| 298 |
+
assert p.tokens[9].ttype == T.Keyword
|
| 299 |
+
assert p.tokens[9].value == 'into'
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
@pytest.mark.parametrize('sql, expected', [
|
| 303 |
+
# note: typecast needs to be 2nd token for this test
|
| 304 |
+
('select foo::integer from bar', 'integer'),
|
| 305 |
+
('select (current_database())::information_schema.sql_identifier',
|
| 306 |
+
'information_schema.sql_identifier'),
|
| 307 |
+
])
|
| 308 |
+
def test_grouping_typecast(sql, expected):
|
| 309 |
+
p = sqlparse.parse(sql)[0]
|
| 310 |
+
assert p.tokens[2].get_typecast() == expected
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def test_grouping_alias():
|
| 314 |
+
s = 'select foo as bar from mytable'
|
| 315 |
+
p = sqlparse.parse(s)[0]
|
| 316 |
+
assert str(p) == s
|
| 317 |
+
assert p.tokens[2].get_real_name() == 'foo'
|
| 318 |
+
assert p.tokens[2].get_alias() == 'bar'
|
| 319 |
+
s = 'select foo from mytable t1'
|
| 320 |
+
p = sqlparse.parse(s)[0]
|
| 321 |
+
assert str(p) == s
|
| 322 |
+
assert p.tokens[6].get_real_name() == 'mytable'
|
| 323 |
+
assert p.tokens[6].get_alias() == 't1'
|
| 324 |
+
s = 'select foo::integer as bar from mytable'
|
| 325 |
+
p = sqlparse.parse(s)[0]
|
| 326 |
+
assert str(p) == s
|
| 327 |
+
assert p.tokens[2].get_alias() == 'bar'
|
| 328 |
+
s = ('SELECT DISTINCT '
|
| 329 |
+
'(current_database())::information_schema.sql_identifier AS view')
|
| 330 |
+
p = sqlparse.parse(s)[0]
|
| 331 |
+
assert str(p) == s
|
| 332 |
+
assert p.tokens[4].get_alias() == 'view'
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
def test_grouping_alias_case():
|
| 336 |
+
# see issue46
|
| 337 |
+
p = sqlparse.parse('CASE WHEN 1 THEN 2 ELSE 3 END foo')[0]
|
| 338 |
+
assert len(p.tokens) == 1
|
| 339 |
+
assert p.tokens[0].get_alias() == 'foo'
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
def test_grouping_alias_ctas():
|
| 343 |
+
p = sqlparse.parse('CREATE TABLE tbl1 AS SELECT coalesce(t1.col1, 0) AS col1 FROM t1')[0]
|
| 344 |
+
assert p.tokens[10].get_alias() == 'col1'
|
| 345 |
+
assert isinstance(p.tokens[10].tokens[0], sql.Function)
|
| 346 |
+
|
| 347 |
+
def test_grouping_subquery_no_parens():
|
| 348 |
+
# Not totally sure if this is the right approach...
|
| 349 |
+
# When a THEN clause contains a subquery w/o parenthesis around it *and*
|
| 350 |
+
# a WHERE condition, the WHERE grouper consumes END too.
|
| 351 |
+
# This takes makes sure that it doesn't fail.
|
| 352 |
+
p = sqlparse.parse('CASE WHEN 1 THEN select 2 where foo = 1 end')[0]
|
| 353 |
+
assert len(p.tokens) == 1
|
| 354 |
+
assert isinstance(p.tokens[0], sql.Case)
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
@pytest.mark.parametrize('s', ['foo.bar', 'x, y', 'x > y', 'x / y'])
|
| 358 |
+
def test_grouping_alias_returns_none(s):
|
| 359 |
+
# see issue185 and issue445
|
| 360 |
+
p = sqlparse.parse(s)[0]
|
| 361 |
+
assert len(p.tokens) == 1
|
| 362 |
+
assert p.tokens[0].get_alias() is None
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
def test_grouping_idlist_function():
|
| 366 |
+
# see issue10 too
|
| 367 |
+
p = sqlparse.parse('foo(1) x, bar')[0]
|
| 368 |
+
assert isinstance(p.tokens[0], sql.IdentifierList)
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
def test_grouping_comparison_exclude():
|
| 372 |
+
# make sure operators are not handled too lazy
|
| 373 |
+
p = sqlparse.parse('(=)')[0]
|
| 374 |
+
assert isinstance(p.tokens[0], sql.Parenthesis)
|
| 375 |
+
assert not isinstance(p.tokens[0].tokens[1], sql.Comparison)
|
| 376 |
+
p = sqlparse.parse('(a=1)')[0]
|
| 377 |
+
assert isinstance(p.tokens[0].tokens[1], sql.Comparison)
|
| 378 |
+
p = sqlparse.parse('(a>=1)')[0]
|
| 379 |
+
assert isinstance(p.tokens[0].tokens[1], sql.Comparison)
|
| 380 |
+
|
| 381 |
+
|
| 382 |
+
def test_grouping_function():
|
| 383 |
+
p = sqlparse.parse('foo()')[0]
|
| 384 |
+
assert isinstance(p.tokens[0], sql.Function)
|
| 385 |
+
p = sqlparse.parse('foo(null, bar)')[0]
|
| 386 |
+
assert isinstance(p.tokens[0], sql.Function)
|
| 387 |
+
assert len(list(p.tokens[0].get_parameters())) == 2
|
| 388 |
+
p = sqlparse.parse('foo(5) over win1')[0]
|
| 389 |
+
assert isinstance(p.tokens[0], sql.Function)
|
| 390 |
+
assert len(list(p.tokens[0].get_parameters())) == 1
|
| 391 |
+
assert isinstance(p.tokens[0].get_window(), sql.Identifier)
|
| 392 |
+
p = sqlparse.parse('foo(5) over (PARTITION BY c1)')[0]
|
| 393 |
+
assert isinstance(p.tokens[0], sql.Function)
|
| 394 |
+
assert len(list(p.tokens[0].get_parameters())) == 1
|
| 395 |
+
assert isinstance(p.tokens[0].get_window(), sql.Parenthesis)
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def test_grouping_function_not_in():
|
| 399 |
+
# issue183
|
| 400 |
+
p = sqlparse.parse('in(1, 2)')[0]
|
| 401 |
+
assert len(p.tokens) == 2
|
| 402 |
+
assert p.tokens[0].ttype == T.Keyword
|
| 403 |
+
assert isinstance(p.tokens[1], sql.Parenthesis)
|
| 404 |
+
|
| 405 |
+
|
| 406 |
+
def test_grouping_varchar():
|
| 407 |
+
p = sqlparse.parse('"text" Varchar(50) NOT NULL')[0]
|
| 408 |
+
assert isinstance(p.tokens[2], sql.Function)
|
| 409 |
+
|
| 410 |
+
|
| 411 |
+
def test_statement_get_type():
|
| 412 |
+
def f(sql):
|
| 413 |
+
return sqlparse.parse(sql)[0]
|
| 414 |
+
|
| 415 |
+
assert f('select * from foo').get_type() == 'SELECT'
|
| 416 |
+
assert f('update foo').get_type() == 'UPDATE'
|
| 417 |
+
assert f(' update foo').get_type() == 'UPDATE'
|
| 418 |
+
assert f('\nupdate foo').get_type() == 'UPDATE'
|
| 419 |
+
assert f('foo').get_type() == 'UNKNOWN'
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
def test_identifier_with_operators():
|
| 423 |
+
# issue 53
|
| 424 |
+
p = sqlparse.parse('foo||bar')[0]
|
| 425 |
+
assert len(p.tokens) == 1
|
| 426 |
+
assert isinstance(p.tokens[0], sql.Operation)
|
| 427 |
+
# again with whitespaces
|
| 428 |
+
p = sqlparse.parse('foo || bar')[0]
|
| 429 |
+
assert len(p.tokens) == 1
|
| 430 |
+
assert isinstance(p.tokens[0], sql.Operation)
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
def test_identifier_with_op_trailing_ws():
|
| 434 |
+
# make sure trailing whitespace isn't grouped with identifier
|
| 435 |
+
p = sqlparse.parse('foo || bar ')[0]
|
| 436 |
+
assert len(p.tokens) == 2
|
| 437 |
+
assert isinstance(p.tokens[0], sql.Operation)
|
| 438 |
+
assert p.tokens[1].ttype is T.Whitespace
|
| 439 |
+
|
| 440 |
+
|
| 441 |
+
def test_identifier_with_string_literals():
|
| 442 |
+
p = sqlparse.parse("foo + 'bar'")[0]
|
| 443 |
+
assert len(p.tokens) == 1
|
| 444 |
+
assert isinstance(p.tokens[0], sql.Operation)
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
# This test seems to be wrong. It was introduced when fixing #53, but #111
|
| 448 |
+
# showed that this shouldn't be an identifier at all. I'm leaving this
|
| 449 |
+
# commented in the source for a while.
|
| 450 |
+
# def test_identifier_string_concat():
|
| 451 |
+
# p = sqlparse.parse("'foo' || bar")[0]
|
| 452 |
+
# assert len(p.tokens) == 1
|
| 453 |
+
# assert isinstance(p.tokens[0], sql.Identifier)
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
def test_identifier_consumes_ordering():
|
| 457 |
+
# issue89
|
| 458 |
+
p = sqlparse.parse('select * from foo order by c1 desc, c2, c3')[0]
|
| 459 |
+
assert isinstance(p.tokens[-1], sql.IdentifierList)
|
| 460 |
+
ids = list(p.tokens[-1].get_identifiers())
|
| 461 |
+
assert len(ids) == 3
|
| 462 |
+
assert ids[0].get_name() == 'c1'
|
| 463 |
+
assert ids[0].get_ordering() == 'DESC'
|
| 464 |
+
assert ids[1].get_name() == 'c2'
|
| 465 |
+
assert ids[1].get_ordering() is None
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
def test_comparison_with_keywords():
|
| 469 |
+
# issue90
|
| 470 |
+
# in fact these are assignments, but for now we don't distinguish them
|
| 471 |
+
p = sqlparse.parse('foo = NULL')[0]
|
| 472 |
+
assert len(p.tokens) == 1
|
| 473 |
+
assert isinstance(p.tokens[0], sql.Comparison)
|
| 474 |
+
assert len(p.tokens[0].tokens) == 5
|
| 475 |
+
assert p.tokens[0].left.value == 'foo'
|
| 476 |
+
assert p.tokens[0].right.value == 'NULL'
|
| 477 |
+
# make sure it's case-insensitive
|
| 478 |
+
p = sqlparse.parse('foo = null')[0]
|
| 479 |
+
assert len(p.tokens) == 1
|
| 480 |
+
assert isinstance(p.tokens[0], sql.Comparison)
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
def test_comparison_with_floats():
|
| 484 |
+
# issue145
|
| 485 |
+
p = sqlparse.parse('foo = 25.5')[0]
|
| 486 |
+
assert len(p.tokens) == 1
|
| 487 |
+
assert isinstance(p.tokens[0], sql.Comparison)
|
| 488 |
+
assert len(p.tokens[0].tokens) == 5
|
| 489 |
+
assert p.tokens[0].left.value == 'foo'
|
| 490 |
+
assert p.tokens[0].right.value == '25.5'
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
def test_comparison_with_parenthesis():
|
| 494 |
+
# issue23
|
| 495 |
+
p = sqlparse.parse('(3 + 4) = 7')[0]
|
| 496 |
+
assert len(p.tokens) == 1
|
| 497 |
+
assert isinstance(p.tokens[0], sql.Comparison)
|
| 498 |
+
comp = p.tokens[0]
|
| 499 |
+
assert isinstance(comp.left, sql.Parenthesis)
|
| 500 |
+
assert comp.right.ttype is T.Number.Integer
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
@pytest.mark.parametrize('operator', (
|
| 504 |
+
'=', '!=', '>', '<', '<=', '>=', '~', '~~', '!~~',
|
| 505 |
+
'LIKE', 'NOT LIKE', 'ILIKE', 'NOT ILIKE',
|
| 506 |
+
))
|
| 507 |
+
def test_comparison_with_strings(operator):
|
| 508 |
+
# issue148
|
| 509 |
+
p = sqlparse.parse("foo {} 'bar'".format(operator))[0]
|
| 510 |
+
assert len(p.tokens) == 1
|
| 511 |
+
assert isinstance(p.tokens[0], sql.Comparison)
|
| 512 |
+
assert p.tokens[0].right.value == "'bar'"
|
| 513 |
+
assert p.tokens[0].right.ttype == T.String.Single
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
def test_like_and_ilike_comparison():
|
| 517 |
+
def validate_where_clause(where_clause, expected_tokens):
|
| 518 |
+
assert len(where_clause.tokens) == len(expected_tokens)
|
| 519 |
+
for where_token, expected_token in zip(where_clause, expected_tokens):
|
| 520 |
+
expected_ttype, expected_value = expected_token
|
| 521 |
+
if where_token.ttype is not None:
|
| 522 |
+
assert where_token.match(expected_ttype, expected_value, regex=True)
|
| 523 |
+
else:
|
| 524 |
+
# Certain tokens, such as comparison tokens, do not define a ttype that can be
|
| 525 |
+
# matched against. For these tokens, we ensure that the token instance is of
|
| 526 |
+
# the expected type and has a value conforming to specified regular expression
|
| 527 |
+
import re
|
| 528 |
+
assert (isinstance(where_token, expected_ttype)
|
| 529 |
+
and re.match(expected_value, where_token.value))
|
| 530 |
+
|
| 531 |
+
[p1] = sqlparse.parse("select * from mytable where mytable.mycolumn LIKE 'expr%' limit 5;")
|
| 532 |
+
[p1_where] = [token for token in p1 if isinstance(token, sql.Where)]
|
| 533 |
+
validate_where_clause(p1_where, [
|
| 534 |
+
(T.Keyword, "where"),
|
| 535 |
+
(T.Whitespace, None),
|
| 536 |
+
(sql.Comparison, r"mytable.mycolumn LIKE.*"),
|
| 537 |
+
(T.Whitespace, None),
|
| 538 |
+
])
|
| 539 |
+
|
| 540 |
+
[p2] = sqlparse.parse(
|
| 541 |
+
"select * from mytable where mycolumn NOT ILIKE '-expr' group by othercolumn;")
|
| 542 |
+
[p2_where] = [token for token in p2 if isinstance(token, sql.Where)]
|
| 543 |
+
validate_where_clause(p2_where, [
|
| 544 |
+
(T.Keyword, "where"),
|
| 545 |
+
(T.Whitespace, None),
|
| 546 |
+
(sql.Comparison, r"mycolumn NOT ILIKE.*"),
|
| 547 |
+
(T.Whitespace, None),
|
| 548 |
+
])
|
| 549 |
+
|
| 550 |
+
|
| 551 |
+
def test_comparison_with_functions():
|
| 552 |
+
# issue230
|
| 553 |
+
p = sqlparse.parse('foo = DATE(bar.baz)')[0]
|
| 554 |
+
assert len(p.tokens) == 1
|
| 555 |
+
assert isinstance(p.tokens[0], sql.Comparison)
|
| 556 |
+
assert len(p.tokens[0].tokens) == 5
|
| 557 |
+
assert p.tokens[0].left.value == 'foo'
|
| 558 |
+
assert p.tokens[0].right.value == 'DATE(bar.baz)'
|
| 559 |
+
|
| 560 |
+
p = sqlparse.parse('DATE(foo.bar) = DATE(bar.baz)')[0]
|
| 561 |
+
assert len(p.tokens) == 1
|
| 562 |
+
assert isinstance(p.tokens[0], sql.Comparison)
|
| 563 |
+
assert len(p.tokens[0].tokens) == 5
|
| 564 |
+
assert p.tokens[0].left.value == 'DATE(foo.bar)'
|
| 565 |
+
assert p.tokens[0].right.value == 'DATE(bar.baz)'
|
| 566 |
+
|
| 567 |
+
p = sqlparse.parse('DATE(foo.bar) = bar.baz')[0]
|
| 568 |
+
assert len(p.tokens) == 1
|
| 569 |
+
assert isinstance(p.tokens[0], sql.Comparison)
|
| 570 |
+
assert len(p.tokens[0].tokens) == 5
|
| 571 |
+
assert p.tokens[0].left.value == 'DATE(foo.bar)'
|
| 572 |
+
assert p.tokens[0].right.value == 'bar.baz'
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
def test_comparison_with_typed_literal():
|
| 576 |
+
p = sqlparse.parse("foo = DATE 'bar.baz'")[0]
|
| 577 |
+
assert len(p.tokens) == 1
|
| 578 |
+
comp = p.tokens[0]
|
| 579 |
+
assert isinstance(comp, sql.Comparison)
|
| 580 |
+
assert len(comp.tokens) == 5
|
| 581 |
+
assert comp.left.value == 'foo'
|
| 582 |
+
assert isinstance(comp.right, sql.TypedLiteral)
|
| 583 |
+
assert comp.right.value == "DATE 'bar.baz'"
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
@pytest.mark.parametrize('start', ['FOR', 'FOREACH'])
|
| 587 |
+
def test_forloops(start):
|
| 588 |
+
p = sqlparse.parse('{} foo in bar LOOP foobar END LOOP'.format(start))[0]
|
| 589 |
+
assert (len(p.tokens)) == 1
|
| 590 |
+
assert isinstance(p.tokens[0], sql.For)
|
| 591 |
+
|
| 592 |
+
|
| 593 |
+
def test_nested_for():
|
| 594 |
+
p = sqlparse.parse('FOR foo LOOP FOR bar LOOP END LOOP END LOOP')[0]
|
| 595 |
+
assert len(p.tokens) == 1
|
| 596 |
+
for1 = p.tokens[0]
|
| 597 |
+
assert for1.tokens[0].value == 'FOR'
|
| 598 |
+
assert for1.tokens[-1].value == 'END LOOP'
|
| 599 |
+
for2 = for1.tokens[6]
|
| 600 |
+
assert isinstance(for2, sql.For)
|
| 601 |
+
assert for2.tokens[0].value == 'FOR'
|
| 602 |
+
assert for2.tokens[-1].value == 'END LOOP'
|
| 603 |
+
|
| 604 |
+
|
| 605 |
+
def test_begin():
|
| 606 |
+
p = sqlparse.parse('BEGIN foo END')[0]
|
| 607 |
+
assert len(p.tokens) == 1
|
| 608 |
+
assert isinstance(p.tokens[0], sql.Begin)
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
def test_keyword_followed_by_parenthesis():
|
| 612 |
+
p = sqlparse.parse('USING(somecol')[0]
|
| 613 |
+
assert len(p.tokens) == 3
|
| 614 |
+
assert p.tokens[0].ttype == T.Keyword
|
| 615 |
+
assert p.tokens[1].ttype == T.Punctuation
|
| 616 |
+
|
| 617 |
+
|
| 618 |
+
def test_nested_begin():
|
| 619 |
+
p = sqlparse.parse('BEGIN foo BEGIN bar END END')[0]
|
| 620 |
+
assert len(p.tokens) == 1
|
| 621 |
+
outer = p.tokens[0]
|
| 622 |
+
assert outer.tokens[0].value == 'BEGIN'
|
| 623 |
+
assert outer.tokens[-1].value == 'END'
|
| 624 |
+
inner = outer.tokens[4]
|
| 625 |
+
assert inner.tokens[0].value == 'BEGIN'
|
| 626 |
+
assert inner.tokens[-1].value == 'END'
|
| 627 |
+
assert isinstance(inner, sql.Begin)
|
| 628 |
+
|
| 629 |
+
|
| 630 |
+
def test_aliased_column_without_as():
|
| 631 |
+
p = sqlparse.parse('foo bar')[0].tokens
|
| 632 |
+
assert len(p) == 1
|
| 633 |
+
assert p[0].get_real_name() == 'foo'
|
| 634 |
+
assert p[0].get_alias() == 'bar'
|
| 635 |
+
|
| 636 |
+
p = sqlparse.parse('foo.bar baz')[0].tokens[0]
|
| 637 |
+
assert p.get_parent_name() == 'foo'
|
| 638 |
+
assert p.get_real_name() == 'bar'
|
| 639 |
+
assert p.get_alias() == 'baz'
|
| 640 |
+
|
| 641 |
+
|
| 642 |
+
def test_qualified_function():
|
| 643 |
+
p = sqlparse.parse('foo()')[0].tokens[0]
|
| 644 |
+
assert p.get_parent_name() is None
|
| 645 |
+
assert p.get_real_name() == 'foo'
|
| 646 |
+
|
| 647 |
+
p = sqlparse.parse('foo.bar()')[0].tokens[0]
|
| 648 |
+
assert p.get_parent_name() == 'foo'
|
| 649 |
+
assert p.get_real_name() == 'bar'
|
| 650 |
+
|
| 651 |
+
|
| 652 |
+
def test_aliased_function_without_as():
|
| 653 |
+
p = sqlparse.parse('foo() bar')[0].tokens[0]
|
| 654 |
+
assert p.get_parent_name() is None
|
| 655 |
+
assert p.get_real_name() == 'foo'
|
| 656 |
+
assert p.get_alias() == 'bar'
|
| 657 |
+
|
| 658 |
+
p = sqlparse.parse('foo.bar() baz')[0].tokens[0]
|
| 659 |
+
assert p.get_parent_name() == 'foo'
|
| 660 |
+
assert p.get_real_name() == 'bar'
|
| 661 |
+
assert p.get_alias() == 'baz'
|
| 662 |
+
|
| 663 |
+
|
| 664 |
+
def test_aliased_literal_without_as():
|
| 665 |
+
p = sqlparse.parse('1 foo')[0].tokens
|
| 666 |
+
assert len(p) == 1
|
| 667 |
+
assert p[0].get_alias() == 'foo'
|
| 668 |
+
|
| 669 |
+
|
| 670 |
+
def test_grouping_as_cte():
|
| 671 |
+
p = sqlparse.parse('foo AS WITH apple AS 1, banana AS 2')[0].tokens
|
| 672 |
+
assert len(p) > 4
|
| 673 |
+
assert p[0].get_alias() is None
|
| 674 |
+
assert p[2].value == 'AS'
|
| 675 |
+
assert p[4].value == 'WITH'
|
| 676 |
+
|
| 677 |
+
def test_grouping_create_table():
|
| 678 |
+
p = sqlparse.parse("create table db.tbl (a string)")[0].tokens
|
| 679 |
+
assert p[4].value == "db.tbl"
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_keywords.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pytest
|
| 2 |
+
|
| 3 |
+
from sqlparse import tokens
|
| 4 |
+
from sqlparse.lexer import Lexer
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class TestSQLREGEX:
|
| 8 |
+
@pytest.mark.parametrize('number', ['1.0', '-1.0',
|
| 9 |
+
'1.', '-1.',
|
| 10 |
+
'.1', '-.1'])
|
| 11 |
+
def test_float_numbers(self, number):
|
| 12 |
+
ttype = next(tt for action, tt in Lexer.get_default_instance()._SQL_REGEX if action(number))
|
| 13 |
+
assert tokens.Number.Float == ttype
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_parse.py
ADDED
|
@@ -0,0 +1,595 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests sqlparse.parse()."""
|
| 2 |
+
from io import StringIO
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
import sqlparse
|
| 7 |
+
from sqlparse import sql, tokens as T, keywords
|
| 8 |
+
from sqlparse.lexer import Lexer
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_parse_tokenize():
|
| 12 |
+
s = 'select * from foo;'
|
| 13 |
+
stmts = sqlparse.parse(s)
|
| 14 |
+
assert len(stmts) == 1
|
| 15 |
+
assert str(stmts[0]) == s
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def test_parse_multistatement():
|
| 19 |
+
sql1 = 'select * from foo;'
|
| 20 |
+
sql2 = 'select * from bar;'
|
| 21 |
+
stmts = sqlparse.parse(sql1 + sql2)
|
| 22 |
+
assert len(stmts) == 2
|
| 23 |
+
assert str(stmts[0]) == sql1
|
| 24 |
+
assert str(stmts[1]) == sql2
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@pytest.mark.parametrize('s', ['select\n*from foo;',
|
| 28 |
+
'select\r\n*from foo',
|
| 29 |
+
'select\r*from foo',
|
| 30 |
+
'select\r\n*from foo\n'])
|
| 31 |
+
def test_parse_newlines(s):
|
| 32 |
+
p = sqlparse.parse(s)[0]
|
| 33 |
+
assert str(p) == s
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def test_parse_within():
|
| 37 |
+
s = 'foo(col1, col2)'
|
| 38 |
+
p = sqlparse.parse(s)[0]
|
| 39 |
+
col1 = p.tokens[0].tokens[1].tokens[1].tokens[0]
|
| 40 |
+
assert col1.within(sql.Function)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def test_parse_child_of():
|
| 44 |
+
s = '(col1, col2)'
|
| 45 |
+
p = sqlparse.parse(s)[0]
|
| 46 |
+
assert p.tokens[0].tokens[1].is_child_of(p.tokens[0])
|
| 47 |
+
s = 'select foo'
|
| 48 |
+
p = sqlparse.parse(s)[0]
|
| 49 |
+
assert not p.tokens[2].is_child_of(p.tokens[0])
|
| 50 |
+
assert p.tokens[2].is_child_of(p)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def test_parse_has_ancestor():
|
| 54 |
+
s = 'foo or (bar, baz)'
|
| 55 |
+
p = sqlparse.parse(s)[0]
|
| 56 |
+
baz = p.tokens[-1].tokens[1].tokens[-1]
|
| 57 |
+
assert baz.has_ancestor(p.tokens[-1].tokens[1])
|
| 58 |
+
assert baz.has_ancestor(p.tokens[-1])
|
| 59 |
+
assert baz.has_ancestor(p)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
@pytest.mark.parametrize('s', ['.5', '.51', '1.5', '12.5'])
|
| 63 |
+
def test_parse_float(s):
|
| 64 |
+
t = sqlparse.parse(s)[0].tokens
|
| 65 |
+
assert len(t) == 1
|
| 66 |
+
assert t[0].ttype is sqlparse.tokens.Number.Float
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
@pytest.mark.parametrize('s, holder', [
|
| 70 |
+
('select * from foo where user = ?', '?'),
|
| 71 |
+
('select * from foo where user = :1', ':1'),
|
| 72 |
+
('select * from foo where user = :name', ':name'),
|
| 73 |
+
('select * from foo where user = %s', '%s'),
|
| 74 |
+
('select * from foo where user = $a', '$a')])
|
| 75 |
+
def test_parse_placeholder(s, holder):
|
| 76 |
+
t = sqlparse.parse(s)[0].tokens[-1].tokens
|
| 77 |
+
assert t[-1].ttype is sqlparse.tokens.Name.Placeholder
|
| 78 |
+
assert t[-1].value == holder
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def test_parse_modulo_not_placeholder():
|
| 82 |
+
tokens = list(sqlparse.lexer.tokenize('x %3'))
|
| 83 |
+
assert tokens[2][0] == sqlparse.tokens.Operator
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def test_parse_access_symbol():
|
| 87 |
+
# see issue27
|
| 88 |
+
t = sqlparse.parse('select a.[foo bar] as foo')[0].tokens
|
| 89 |
+
assert isinstance(t[-1], sql.Identifier)
|
| 90 |
+
assert t[-1].get_name() == 'foo'
|
| 91 |
+
assert t[-1].get_real_name() == '[foo bar]'
|
| 92 |
+
assert t[-1].get_parent_name() == 'a'
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def test_parse_square_brackets_notation_isnt_too_greedy():
|
| 96 |
+
# see issue153
|
| 97 |
+
t = sqlparse.parse('[foo], [bar]')[0].tokens
|
| 98 |
+
assert isinstance(t[0], sql.IdentifierList)
|
| 99 |
+
assert len(t[0].tokens) == 4
|
| 100 |
+
assert t[0].tokens[0].get_real_name() == '[foo]'
|
| 101 |
+
assert t[0].tokens[-1].get_real_name() == '[bar]'
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def test_parse_square_brackets_notation_isnt_too_greedy2():
|
| 105 |
+
# see issue583
|
| 106 |
+
t = sqlparse.parse('[(foo[i])]')[0].tokens
|
| 107 |
+
assert isinstance(t[0], sql.SquareBrackets) # not Identifier!
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def test_parse_keyword_like_identifier():
|
| 111 |
+
# see issue47
|
| 112 |
+
t = sqlparse.parse('foo.key')[0].tokens
|
| 113 |
+
assert len(t) == 1
|
| 114 |
+
assert isinstance(t[0], sql.Identifier)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def test_parse_function_parameter():
|
| 118 |
+
# see issue94
|
| 119 |
+
t = sqlparse.parse('abs(some_col)')[0].tokens[0].get_parameters()
|
| 120 |
+
assert len(t) == 1
|
| 121 |
+
assert isinstance(t[0], sql.Identifier)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def test_parse_function_param_single_literal():
|
| 125 |
+
t = sqlparse.parse('foo(5)')[0].tokens[0].get_parameters()
|
| 126 |
+
assert len(t) == 1
|
| 127 |
+
assert t[0].ttype is T.Number.Integer
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def test_parse_nested_function():
|
| 131 |
+
t = sqlparse.parse('foo(bar(5))')[0].tokens[0].get_parameters()
|
| 132 |
+
assert len(t) == 1
|
| 133 |
+
assert type(t[0]) is sql.Function
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def test_parse_casted_params():
|
| 137 |
+
t = sqlparse.parse("foo(DATE '2023-11-14', TIMESTAMP '2023-11-15')")[0].tokens[0].get_parameters()
|
| 138 |
+
assert len(t) == 2
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def test_parse_div_operator():
|
| 142 |
+
p = sqlparse.parse('col1 DIV 5 AS div_col1')[0].tokens
|
| 143 |
+
assert p[0].tokens[0].tokens[2].ttype is T.Operator
|
| 144 |
+
assert p[0].get_alias() == 'div_col1'
|
| 145 |
+
|
| 146 |
+
|
| 147 |
+
def test_quoted_identifier():
|
| 148 |
+
t = sqlparse.parse('select x.y as "z" from foo')[0].tokens
|
| 149 |
+
assert isinstance(t[2], sql.Identifier)
|
| 150 |
+
assert t[2].get_name() == 'z'
|
| 151 |
+
assert t[2].get_real_name() == 'y'
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
@pytest.mark.parametrize('name', [
|
| 155 |
+
'foo', '_foo', # issue175
|
| 156 |
+
'1_data', # valid MySQL table name, see issue337
|
| 157 |
+
'業者名稱', # valid at least for SQLite3, see issue641
|
| 158 |
+
])
|
| 159 |
+
def test_valid_identifier_names(name):
|
| 160 |
+
t = sqlparse.parse(name)[0].tokens
|
| 161 |
+
assert isinstance(t[0], sql.Identifier)
|
| 162 |
+
assert t[0].get_name() == name
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def test_psql_quotation_marks():
|
| 166 |
+
# issue83
|
| 167 |
+
|
| 168 |
+
# regression: make sure plain $$ work
|
| 169 |
+
t = sqlparse.split("""
|
| 170 |
+
CREATE OR REPLACE FUNCTION testfunc1(integer) RETURNS integer AS $$
|
| 171 |
+
....
|
| 172 |
+
$$ LANGUAGE plpgsql;
|
| 173 |
+
CREATE OR REPLACE FUNCTION testfunc2(integer) RETURNS integer AS $$
|
| 174 |
+
....
|
| 175 |
+
$$ LANGUAGE plpgsql;""")
|
| 176 |
+
assert len(t) == 2
|
| 177 |
+
|
| 178 |
+
# make sure $SOMETHING$ works too
|
| 179 |
+
t = sqlparse.split("""
|
| 180 |
+
CREATE OR REPLACE FUNCTION testfunc1(integer) RETURNS integer AS $PROC_1$
|
| 181 |
+
....
|
| 182 |
+
$PROC_1$ LANGUAGE plpgsql;
|
| 183 |
+
CREATE OR REPLACE FUNCTION testfunc2(integer) RETURNS integer AS $PROC_2$
|
| 184 |
+
....
|
| 185 |
+
$PROC_2$ LANGUAGE plpgsql;""")
|
| 186 |
+
assert len(t) == 2
|
| 187 |
+
|
| 188 |
+
# operators are valid infront of dollar quoted strings
|
| 189 |
+
t = sqlparse.split("""UPDATE SET foo =$$bar;SELECT bar$$""")
|
| 190 |
+
assert len(t) == 1
|
| 191 |
+
|
| 192 |
+
# identifiers must be separated by whitespace
|
| 193 |
+
t = sqlparse.split("""UPDATE SET foo TO$$bar;SELECT bar$$""")
|
| 194 |
+
assert len(t) == 2
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def test_double_precision_is_builtin():
|
| 198 |
+
s = 'DOUBLE PRECISION'
|
| 199 |
+
t = sqlparse.parse(s)[0].tokens
|
| 200 |
+
assert len(t) == 1
|
| 201 |
+
assert t[0].ttype == sqlparse.tokens.Name.Builtin
|
| 202 |
+
assert t[0].value == 'DOUBLE PRECISION'
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
@pytest.mark.parametrize('ph', ['?', ':1', ':foo', '%s', '%(foo)s'])
|
| 206 |
+
def test_placeholder(ph):
|
| 207 |
+
p = sqlparse.parse(ph)[0].tokens
|
| 208 |
+
assert len(p) == 1
|
| 209 |
+
assert p[0].ttype is T.Name.Placeholder
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
@pytest.mark.parametrize('num, expected', [
|
| 213 |
+
('6.67428E-8', T.Number.Float),
|
| 214 |
+
('1.988e33', T.Number.Float),
|
| 215 |
+
('1e-12', T.Number.Float),
|
| 216 |
+
('e1', None),
|
| 217 |
+
])
|
| 218 |
+
def test_scientific_numbers(num, expected):
|
| 219 |
+
p = sqlparse.parse(num)[0].tokens
|
| 220 |
+
assert len(p) == 1
|
| 221 |
+
assert p[0].ttype is expected
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
def test_single_quotes_are_strings():
|
| 225 |
+
p = sqlparse.parse("'foo'")[0].tokens
|
| 226 |
+
assert len(p) == 1
|
| 227 |
+
assert p[0].ttype is T.String.Single
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
def test_double_quotes_are_identifiers():
|
| 231 |
+
p = sqlparse.parse('"foo"')[0].tokens
|
| 232 |
+
assert len(p) == 1
|
| 233 |
+
assert isinstance(p[0], sql.Identifier)
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def test_single_quotes_with_linebreaks():
|
| 237 |
+
# issue118
|
| 238 |
+
p = sqlparse.parse("'f\nf'")[0].tokens
|
| 239 |
+
assert len(p) == 1
|
| 240 |
+
assert p[0].ttype is T.String.Single
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
def test_sqlite_identifiers():
|
| 244 |
+
# Make sure we still parse sqlite style escapes
|
| 245 |
+
p = sqlparse.parse('[col1],[col2]')[0].tokens
|
| 246 |
+
id_names = [id_.get_name() for id_ in p[0].get_identifiers()]
|
| 247 |
+
assert len(p) == 1
|
| 248 |
+
assert isinstance(p[0], sql.IdentifierList)
|
| 249 |
+
assert id_names == ['[col1]', '[col2]']
|
| 250 |
+
|
| 251 |
+
p = sqlparse.parse('[col1]+[col2]')[0]
|
| 252 |
+
types = [tok.ttype for tok in p.flatten()]
|
| 253 |
+
assert types == [T.Name, T.Operator, T.Name]
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def test_simple_1d_array_index():
|
| 257 |
+
p = sqlparse.parse('col[1]')[0].tokens
|
| 258 |
+
assert len(p) == 1
|
| 259 |
+
assert p[0].get_name() == 'col'
|
| 260 |
+
indices = list(p[0].get_array_indices())
|
| 261 |
+
assert len(indices) == 1 # 1-dimensional index
|
| 262 |
+
assert len(indices[0]) == 1 # index is single token
|
| 263 |
+
assert indices[0][0].value == '1'
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def test_2d_array_index():
|
| 267 |
+
p = sqlparse.parse('col[x][(y+1)*2]')[0].tokens
|
| 268 |
+
assert len(p) == 1
|
| 269 |
+
assert p[0].get_name() == 'col'
|
| 270 |
+
assert len(list(p[0].get_array_indices())) == 2 # 2-dimensional index
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def test_array_index_function_result():
|
| 274 |
+
p = sqlparse.parse('somefunc()[1]')[0].tokens
|
| 275 |
+
assert len(p) == 1
|
| 276 |
+
assert len(list(p[0].get_array_indices())) == 1
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
def test_schema_qualified_array_index():
|
| 280 |
+
p = sqlparse.parse('schem.col[1]')[0].tokens
|
| 281 |
+
assert len(p) == 1
|
| 282 |
+
assert p[0].get_parent_name() == 'schem'
|
| 283 |
+
assert p[0].get_name() == 'col'
|
| 284 |
+
assert list(p[0].get_array_indices())[0][0].value == '1'
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
def test_aliased_array_index():
|
| 288 |
+
p = sqlparse.parse('col[1] x')[0].tokens
|
| 289 |
+
assert len(p) == 1
|
| 290 |
+
assert p[0].get_alias() == 'x'
|
| 291 |
+
assert p[0].get_real_name() == 'col'
|
| 292 |
+
assert list(p[0].get_array_indices())[0][0].value == '1'
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def test_array_literal():
|
| 296 |
+
# See issue #176
|
| 297 |
+
p = sqlparse.parse('ARRAY[%s, %s]')[0]
|
| 298 |
+
assert len(p.tokens) == 2
|
| 299 |
+
assert len(list(p.flatten())) == 7
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def test_typed_array_definition():
|
| 303 |
+
# array indices aren't grouped with built-ins, but make sure we can extract
|
| 304 |
+
# identifier names
|
| 305 |
+
p = sqlparse.parse('x int, y int[], z int')[0]
|
| 306 |
+
names = [x.get_name() for x in p.get_sublists()
|
| 307 |
+
if isinstance(x, sql.Identifier)]
|
| 308 |
+
assert names == ['x', 'y', 'z']
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
@pytest.mark.parametrize('s', ['select 1 -- foo', 'select 1 # foo'])
|
| 312 |
+
def test_single_line_comments(s):
|
| 313 |
+
# see issue178
|
| 314 |
+
p = sqlparse.parse(s)[0]
|
| 315 |
+
assert len(p.tokens) == 5
|
| 316 |
+
assert p.tokens[-1].ttype == T.Comment.Single
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
@pytest.mark.parametrize('s', ['foo', '@foo', '#foo', '##foo'])
|
| 320 |
+
def test_names_and_special_names(s):
|
| 321 |
+
# see issue192
|
| 322 |
+
p = sqlparse.parse(s)[0]
|
| 323 |
+
assert len(p.tokens) == 1
|
| 324 |
+
assert isinstance(p.tokens[0], sql.Identifier)
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
def test_get_token_at_offset():
|
| 328 |
+
p = sqlparse.parse('select * from dual')[0]
|
| 329 |
+
# 0123456789
|
| 330 |
+
assert p.get_token_at_offset(0) == p.tokens[0]
|
| 331 |
+
assert p.get_token_at_offset(1) == p.tokens[0]
|
| 332 |
+
assert p.get_token_at_offset(6) == p.tokens[1]
|
| 333 |
+
assert p.get_token_at_offset(7) == p.tokens[2]
|
| 334 |
+
assert p.get_token_at_offset(8) == p.tokens[3]
|
| 335 |
+
assert p.get_token_at_offset(9) == p.tokens[4]
|
| 336 |
+
assert p.get_token_at_offset(10) == p.tokens[4]
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def test_pprint():
|
| 340 |
+
p = sqlparse.parse('select a0, b0, c0, d0, e0 from '
|
| 341 |
+
'(select * from dual) q0 where 1=1 and 2=2')[0]
|
| 342 |
+
output = StringIO()
|
| 343 |
+
|
| 344 |
+
p._pprint_tree(f=output)
|
| 345 |
+
pprint = '\n'.join([
|
| 346 |
+
"|- 0 DML 'select'",
|
| 347 |
+
"|- 1 Whitespace ' '",
|
| 348 |
+
"|- 2 IdentifierList 'a0, b0...'",
|
| 349 |
+
"| |- 0 Identifier 'a0'",
|
| 350 |
+
"| | `- 0 Name 'a0'",
|
| 351 |
+
"| |- 1 Punctuation ','",
|
| 352 |
+
"| |- 2 Whitespace ' '",
|
| 353 |
+
"| |- 3 Identifier 'b0'",
|
| 354 |
+
"| | `- 0 Name 'b0'",
|
| 355 |
+
"| |- 4 Punctuation ','",
|
| 356 |
+
"| |- 5 Whitespace ' '",
|
| 357 |
+
"| |- 6 Identifier 'c0'",
|
| 358 |
+
"| | `- 0 Name 'c0'",
|
| 359 |
+
"| |- 7 Punctuation ','",
|
| 360 |
+
"| |- 8 Whitespace ' '",
|
| 361 |
+
"| |- 9 Identifier 'd0'",
|
| 362 |
+
"| | `- 0 Name 'd0'",
|
| 363 |
+
"| |- 10 Punctuation ','",
|
| 364 |
+
"| |- 11 Whitespace ' '",
|
| 365 |
+
"| `- 12 Identifier 'e0'",
|
| 366 |
+
"| `- 0 Name 'e0'",
|
| 367 |
+
"|- 3 Whitespace ' '",
|
| 368 |
+
"|- 4 Keyword 'from'",
|
| 369 |
+
"|- 5 Whitespace ' '",
|
| 370 |
+
"|- 6 Identifier '(selec...'",
|
| 371 |
+
"| |- 0 Parenthesis '(selec...'",
|
| 372 |
+
"| | |- 0 Punctuation '('",
|
| 373 |
+
"| | |- 1 DML 'select'",
|
| 374 |
+
"| | |- 2 Whitespace ' '",
|
| 375 |
+
"| | |- 3 Wildcard '*'",
|
| 376 |
+
"| | |- 4 Whitespace ' '",
|
| 377 |
+
"| | |- 5 Keyword 'from'",
|
| 378 |
+
"| | |- 6 Whitespace ' '",
|
| 379 |
+
"| | |- 7 Identifier 'dual'",
|
| 380 |
+
"| | | `- 0 Name 'dual'",
|
| 381 |
+
"| | `- 8 Punctuation ')'",
|
| 382 |
+
"| |- 1 Whitespace ' '",
|
| 383 |
+
"| `- 2 Identifier 'q0'",
|
| 384 |
+
"| `- 0 Name 'q0'",
|
| 385 |
+
"|- 7 Whitespace ' '",
|
| 386 |
+
"`- 8 Where 'where ...'",
|
| 387 |
+
" |- 0 Keyword 'where'",
|
| 388 |
+
" |- 1 Whitespace ' '",
|
| 389 |
+
" |- 2 Comparison '1=1'",
|
| 390 |
+
" | |- 0 Integer '1'",
|
| 391 |
+
" | |- 1 Comparison '='",
|
| 392 |
+
" | `- 2 Integer '1'",
|
| 393 |
+
" |- 3 Whitespace ' '",
|
| 394 |
+
" |- 4 Keyword 'and'",
|
| 395 |
+
" |- 5 Whitespace ' '",
|
| 396 |
+
" `- 6 Comparison '2=2'",
|
| 397 |
+
" |- 0 Integer '2'",
|
| 398 |
+
" |- 1 Comparison '='",
|
| 399 |
+
" `- 2 Integer '2'",
|
| 400 |
+
""])
|
| 401 |
+
assert output.getvalue() == pprint
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
def test_wildcard_multiplication():
|
| 405 |
+
p = sqlparse.parse('select * from dual')[0]
|
| 406 |
+
assert p.tokens[2].ttype == T.Wildcard
|
| 407 |
+
|
| 408 |
+
p = sqlparse.parse('select a0.* from dual a0')[0]
|
| 409 |
+
assert p.tokens[2][2].ttype == T.Wildcard
|
| 410 |
+
|
| 411 |
+
p = sqlparse.parse('select 1 * 2 from dual')[0]
|
| 412 |
+
assert p.tokens[2][2].ttype == T.Operator
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
def test_stmt_tokens_parents():
|
| 416 |
+
# see issue 226
|
| 417 |
+
s = "CREATE TABLE test();"
|
| 418 |
+
stmt = sqlparse.parse(s)[0]
|
| 419 |
+
for token in stmt.tokens:
|
| 420 |
+
assert token.has_ancestor(stmt)
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
@pytest.mark.parametrize('sql, is_literal', [
|
| 424 |
+
('$$foo$$', True),
|
| 425 |
+
('$_$foo$_$', True),
|
| 426 |
+
('$token$ foo $token$', True),
|
| 427 |
+
# don't parse inner tokens
|
| 428 |
+
('$_$ foo $token$bar$token$ baz$_$', True),
|
| 429 |
+
('$A$ foo $B$', False) # tokens don't match
|
| 430 |
+
])
|
| 431 |
+
def test_dbldollar_as_literal(sql, is_literal):
|
| 432 |
+
# see issue 277
|
| 433 |
+
p = sqlparse.parse(sql)[0]
|
| 434 |
+
if is_literal:
|
| 435 |
+
assert len(p.tokens) == 1
|
| 436 |
+
assert p.tokens[0].ttype == T.Literal
|
| 437 |
+
else:
|
| 438 |
+
for token in p.tokens:
|
| 439 |
+
assert token.ttype != T.Literal
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
def test_non_ascii():
|
| 443 |
+
_test_non_ascii = "insert into test (id, name) values (1, 'тест');"
|
| 444 |
+
|
| 445 |
+
s = _test_non_ascii
|
| 446 |
+
stmts = sqlparse.parse(s)
|
| 447 |
+
assert len(stmts) == 1
|
| 448 |
+
statement = stmts[0]
|
| 449 |
+
assert str(statement) == s
|
| 450 |
+
assert statement._pprint_tree() is None
|
| 451 |
+
|
| 452 |
+
s = _test_non_ascii.encode('utf-8')
|
| 453 |
+
stmts = sqlparse.parse(s, 'utf-8')
|
| 454 |
+
assert len(stmts) == 1
|
| 455 |
+
statement = stmts[0]
|
| 456 |
+
assert str(statement) == _test_non_ascii
|
| 457 |
+
assert statement._pprint_tree() is None
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
def test_get_real_name():
|
| 461 |
+
# issue 369
|
| 462 |
+
s = "update a t set t.b=1"
|
| 463 |
+
stmts = sqlparse.parse(s)
|
| 464 |
+
assert len(stmts) == 1
|
| 465 |
+
assert 'a' == stmts[0].tokens[2].get_real_name()
|
| 466 |
+
assert 't' == stmts[0].tokens[2].get_alias()
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
def test_from_subquery():
|
| 470 |
+
# issue 446
|
| 471 |
+
s = 'from(select 1)'
|
| 472 |
+
stmts = sqlparse.parse(s)
|
| 473 |
+
assert len(stmts) == 1
|
| 474 |
+
assert len(stmts[0].tokens) == 2
|
| 475 |
+
assert stmts[0].tokens[0].value == 'from'
|
| 476 |
+
assert stmts[0].tokens[0].ttype == T.Keyword
|
| 477 |
+
|
| 478 |
+
s = 'from (select 1)'
|
| 479 |
+
stmts = sqlparse.parse(s)
|
| 480 |
+
assert len(stmts) == 1
|
| 481 |
+
assert len(stmts[0].tokens) == 3
|
| 482 |
+
assert stmts[0].tokens[0].value == 'from'
|
| 483 |
+
assert stmts[0].tokens[0].ttype == T.Keyword
|
| 484 |
+
assert stmts[0].tokens[1].ttype == T.Whitespace
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def test_parenthesis():
|
| 488 |
+
tokens = sqlparse.parse("(\n\n1\n\n)")[0].tokens[0].tokens
|
| 489 |
+
assert list(map(lambda t: t.ttype, tokens)) == [T.Punctuation,
|
| 490 |
+
T.Newline,
|
| 491 |
+
T.Newline,
|
| 492 |
+
T.Number.Integer,
|
| 493 |
+
T.Newline,
|
| 494 |
+
T.Newline,
|
| 495 |
+
T.Punctuation]
|
| 496 |
+
tokens = sqlparse.parse("(\n\n 1 \n\n)")[0].tokens[0].tokens
|
| 497 |
+
assert list(map(lambda t: t.ttype, tokens)) == [T.Punctuation,
|
| 498 |
+
T.Newline,
|
| 499 |
+
T.Newline,
|
| 500 |
+
T.Whitespace,
|
| 501 |
+
T.Number.Integer,
|
| 502 |
+
T.Whitespace,
|
| 503 |
+
T.Newline,
|
| 504 |
+
T.Newline,
|
| 505 |
+
T.Punctuation]
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
def test_configurable_keywords():
|
| 509 |
+
sql = """select * from foo BACON SPAM EGGS;"""
|
| 510 |
+
tokens = sqlparse.parse(sql)[0]
|
| 511 |
+
|
| 512 |
+
assert list(
|
| 513 |
+
(t.ttype, t.value)
|
| 514 |
+
for t in tokens
|
| 515 |
+
if t.ttype not in sqlparse.tokens.Whitespace
|
| 516 |
+
) == [
|
| 517 |
+
(sqlparse.tokens.Keyword.DML, "select"),
|
| 518 |
+
(sqlparse.tokens.Wildcard, "*"),
|
| 519 |
+
(sqlparse.tokens.Keyword, "from"),
|
| 520 |
+
(None, "foo BACON"),
|
| 521 |
+
(None, "SPAM EGGS"),
|
| 522 |
+
(sqlparse.tokens.Punctuation, ";"),
|
| 523 |
+
]
|
| 524 |
+
|
| 525 |
+
Lexer.get_default_instance().add_keywords(
|
| 526 |
+
{
|
| 527 |
+
"BACON": sqlparse.tokens.Name.Builtin,
|
| 528 |
+
"SPAM": sqlparse.tokens.Keyword,
|
| 529 |
+
"EGGS": sqlparse.tokens.Keyword,
|
| 530 |
+
}
|
| 531 |
+
)
|
| 532 |
+
|
| 533 |
+
tokens = sqlparse.parse(sql)[0]
|
| 534 |
+
|
| 535 |
+
# reset the syntax for later tests.
|
| 536 |
+
Lexer.get_default_instance().default_initialization()
|
| 537 |
+
|
| 538 |
+
assert list(
|
| 539 |
+
(t.ttype, t.value)
|
| 540 |
+
for t in tokens
|
| 541 |
+
if t.ttype not in sqlparse.tokens.Whitespace
|
| 542 |
+
) == [
|
| 543 |
+
(sqlparse.tokens.Keyword.DML, "select"),
|
| 544 |
+
(sqlparse.tokens.Wildcard, "*"),
|
| 545 |
+
(sqlparse.tokens.Keyword, "from"),
|
| 546 |
+
(None, "foo"),
|
| 547 |
+
(sqlparse.tokens.Name.Builtin, "BACON"),
|
| 548 |
+
(sqlparse.tokens.Keyword, "SPAM"),
|
| 549 |
+
(sqlparse.tokens.Keyword, "EGGS"),
|
| 550 |
+
(sqlparse.tokens.Punctuation, ";"),
|
| 551 |
+
]
|
| 552 |
+
|
| 553 |
+
|
| 554 |
+
def test_configurable_regex():
|
| 555 |
+
lex = Lexer.get_default_instance()
|
| 556 |
+
lex.clear()
|
| 557 |
+
|
| 558 |
+
my_regex = (r"ZORDER\s+BY\b", sqlparse.tokens.Keyword)
|
| 559 |
+
|
| 560 |
+
lex.set_SQL_REGEX(
|
| 561 |
+
keywords.SQL_REGEX[:38]
|
| 562 |
+
+ [my_regex]
|
| 563 |
+
+ keywords.SQL_REGEX[38:]
|
| 564 |
+
)
|
| 565 |
+
lex.add_keywords(keywords.KEYWORDS_COMMON)
|
| 566 |
+
lex.add_keywords(keywords.KEYWORDS_ORACLE)
|
| 567 |
+
lex.add_keywords(keywords.KEYWORDS_PLPGSQL)
|
| 568 |
+
lex.add_keywords(keywords.KEYWORDS_HQL)
|
| 569 |
+
lex.add_keywords(keywords.KEYWORDS_MSACCESS)
|
| 570 |
+
lex.add_keywords(keywords.KEYWORDS)
|
| 571 |
+
|
| 572 |
+
tokens = sqlparse.parse("select * from foo zorder by bar;")[0]
|
| 573 |
+
|
| 574 |
+
# reset the syntax for later tests.
|
| 575 |
+
Lexer.get_default_instance().default_initialization()
|
| 576 |
+
|
| 577 |
+
assert list(
|
| 578 |
+
(t.ttype, t.value)
|
| 579 |
+
for t in tokens
|
| 580 |
+
if t.ttype not in sqlparse.tokens.Whitespace
|
| 581 |
+
)[4] == (sqlparse.tokens.Keyword, "zorder by")
|
| 582 |
+
|
| 583 |
+
|
| 584 |
+
@pytest.mark.parametrize('sql', [
|
| 585 |
+
'->', '->>', '#>', '#>>',
|
| 586 |
+
'@>', '<@',
|
| 587 |
+
# leaving ? out for now, they're somehow ambiguous as placeholders
|
| 588 |
+
# '?', '?|', '?&',
|
| 589 |
+
'||', '-', '#-'
|
| 590 |
+
])
|
| 591 |
+
def test_json_operators(sql):
|
| 592 |
+
p = sqlparse.parse(sql)
|
| 593 |
+
assert len(p) == 1
|
| 594 |
+
assert len(p[0].tokens) == 1
|
| 595 |
+
assert p[0].tokens[0].ttype == sqlparse.tokens.Operator
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_regressions.py
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
import sqlparse
|
| 7 |
+
from sqlparse import sql, tokens as T
|
| 8 |
+
from sqlparse.exceptions import SQLParseError
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_issue9():
|
| 12 |
+
# make sure where doesn't consume parenthesis
|
| 13 |
+
p = sqlparse.parse('(where 1)')[0]
|
| 14 |
+
assert isinstance(p, sql.Statement)
|
| 15 |
+
assert len(p.tokens) == 1
|
| 16 |
+
assert isinstance(p.tokens[0], sql.Parenthesis)
|
| 17 |
+
prt = p.tokens[0]
|
| 18 |
+
assert len(prt.tokens) == 3
|
| 19 |
+
assert prt.tokens[0].ttype == T.Punctuation
|
| 20 |
+
assert prt.tokens[-1].ttype == T.Punctuation
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def test_issue13():
|
| 24 |
+
parsed = sqlparse.parse("select 'one';\n"
|
| 25 |
+
"select 'two\\'';\n"
|
| 26 |
+
"select 'three';")
|
| 27 |
+
assert len(parsed) == 3
|
| 28 |
+
assert str(parsed[1]).strip() == "select 'two\\'';"
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
@pytest.mark.parametrize('s', ['--hello', '-- hello', '--hello\n',
|
| 32 |
+
'--', '--\n'])
|
| 33 |
+
def test_issue26(s):
|
| 34 |
+
# parse stand-alone comments
|
| 35 |
+
p = sqlparse.parse(s)[0]
|
| 36 |
+
assert len(p.tokens) == 1
|
| 37 |
+
assert p.tokens[0].ttype is T.Comment.Single
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
@pytest.mark.parametrize('value', ['create', 'CREATE'])
|
| 41 |
+
def test_issue34(value):
|
| 42 |
+
t = sqlparse.parse("create")[0].token_first()
|
| 43 |
+
assert t.match(T.Keyword.DDL, value) is True
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_issue35():
|
| 47 |
+
# missing space before LIMIT. Updated for #321
|
| 48 |
+
sql = sqlparse.format("select * from foo where bar = 1 limit 1",
|
| 49 |
+
reindent=True)
|
| 50 |
+
assert sql == "\n".join([
|
| 51 |
+
"select *",
|
| 52 |
+
"from foo",
|
| 53 |
+
"where bar = 1",
|
| 54 |
+
"limit 1"])
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def test_issue38():
|
| 58 |
+
sql = sqlparse.format("SELECT foo; -- comment", strip_comments=True)
|
| 59 |
+
assert sql == "SELECT foo;"
|
| 60 |
+
sql = sqlparse.format("/* foo */", strip_comments=True)
|
| 61 |
+
assert sql == ""
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def test_issue39():
|
| 65 |
+
p = sqlparse.parse('select user.id from user')[0]
|
| 66 |
+
assert len(p.tokens) == 7
|
| 67 |
+
idt = p.tokens[2]
|
| 68 |
+
assert idt.__class__ == sql.Identifier
|
| 69 |
+
assert len(idt.tokens) == 3
|
| 70 |
+
assert idt.tokens[0].match(T.Name, 'user') is True
|
| 71 |
+
assert idt.tokens[1].match(T.Punctuation, '.') is True
|
| 72 |
+
assert idt.tokens[2].match(T.Name, 'id') is True
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def test_issue40():
|
| 76 |
+
# make sure identifier lists in subselects are grouped
|
| 77 |
+
p = sqlparse.parse('SELECT id, name FROM '
|
| 78 |
+
'(SELECT id, name FROM bar) as foo')[0]
|
| 79 |
+
assert len(p.tokens) == 7
|
| 80 |
+
assert p.tokens[2].__class__ == sql.IdentifierList
|
| 81 |
+
assert p.tokens[-1].__class__ == sql.Identifier
|
| 82 |
+
assert p.tokens[-1].get_name() == 'foo'
|
| 83 |
+
sp = p.tokens[-1].tokens[0]
|
| 84 |
+
assert sp.tokens[3].__class__ == sql.IdentifierList
|
| 85 |
+
# make sure that formatting works as expected
|
| 86 |
+
s = sqlparse.format('SELECT id == name FROM '
|
| 87 |
+
'(SELECT id, name FROM bar)', reindent=True)
|
| 88 |
+
assert s == '\n'.join([
|
| 89 |
+
'SELECT id == name',
|
| 90 |
+
'FROM',
|
| 91 |
+
' (SELECT id,',
|
| 92 |
+
' name',
|
| 93 |
+
' FROM bar)'])
|
| 94 |
+
|
| 95 |
+
s = sqlparse.format('SELECT id == name FROM '
|
| 96 |
+
'(SELECT id, name FROM bar) as foo', reindent=True)
|
| 97 |
+
assert s == '\n'.join([
|
| 98 |
+
'SELECT id == name',
|
| 99 |
+
'FROM',
|
| 100 |
+
' (SELECT id,',
|
| 101 |
+
' name',
|
| 102 |
+
' FROM bar) as foo'])
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
@pytest.mark.parametrize('s', ['select x.y::text as z from foo',
|
| 106 |
+
'select x.y::text as "z" from foo',
|
| 107 |
+
'select x."y"::text as z from foo',
|
| 108 |
+
'select x."y"::text as "z" from foo',
|
| 109 |
+
'select "x".y::text as z from foo',
|
| 110 |
+
'select "x".y::text as "z" from foo',
|
| 111 |
+
'select "x"."y"::text as z from foo',
|
| 112 |
+
'select "x"."y"::text as "z" from foo'])
|
| 113 |
+
@pytest.mark.parametrize('func_name, result', [('get_name', 'z'),
|
| 114 |
+
('get_real_name', 'y'),
|
| 115 |
+
('get_parent_name', 'x'),
|
| 116 |
+
('get_alias', 'z'),
|
| 117 |
+
('get_typecast', 'text')])
|
| 118 |
+
def test_issue78(s, func_name, result):
|
| 119 |
+
# the bug author provided this nice examples, let's use them!
|
| 120 |
+
p = sqlparse.parse(s)[0]
|
| 121 |
+
i = p.tokens[2]
|
| 122 |
+
assert isinstance(i, sql.Identifier)
|
| 123 |
+
|
| 124 |
+
func = getattr(i, func_name)
|
| 125 |
+
assert func() == result
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def test_issue83():
|
| 129 |
+
sql = """ CREATE OR REPLACE FUNCTION func_a(text)
|
| 130 |
+
RETURNS boolean LANGUAGE plpgsql STRICT IMMUTABLE AS
|
| 131 |
+
$_$
|
| 132 |
+
BEGIN
|
| 133 |
+
...
|
| 134 |
+
END;
|
| 135 |
+
$_$;
|
| 136 |
+
|
| 137 |
+
CREATE OR REPLACE FUNCTION func_b(text)
|
| 138 |
+
RETURNS boolean LANGUAGE plpgsql STRICT IMMUTABLE AS
|
| 139 |
+
$_$
|
| 140 |
+
BEGIN
|
| 141 |
+
...
|
| 142 |
+
END;
|
| 143 |
+
$_$;
|
| 144 |
+
|
| 145 |
+
ALTER TABLE..... ;"""
|
| 146 |
+
t = sqlparse.split(sql)
|
| 147 |
+
assert len(t) == 3
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def test_comment_encoding_when_reindent():
|
| 151 |
+
# There was an UnicodeEncodeError in the reindent filter that
|
| 152 |
+
# casted every comment followed by a keyword to str.
|
| 153 |
+
sql = 'select foo -- Comment containing Ümläuts\nfrom bar'
|
| 154 |
+
formatted = sqlparse.format(sql, reindent=True)
|
| 155 |
+
assert formatted == sql
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def test_parse_sql_with_binary():
|
| 159 |
+
# See https://github.com/andialbrecht/sqlparse/pull/88
|
| 160 |
+
# digest = '|ËêplL4¡høN{'
|
| 161 |
+
digest = '\x82|\xcb\x0e\xea\x8aplL4\xa1h\x91\xf8N{'
|
| 162 |
+
sql = "select * from foo where bar = '{}'".format(digest)
|
| 163 |
+
formatted = sqlparse.format(sql, reindent=True)
|
| 164 |
+
tformatted = "select *\nfrom foo\nwhere bar = '{}'".format(digest)
|
| 165 |
+
assert formatted == tformatted
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def test_dont_alias_keywords():
|
| 169 |
+
# The _group_left_right function had a bug where the check for the
|
| 170 |
+
# left side wasn't handled correctly. In one case this resulted in
|
| 171 |
+
# a keyword turning into an identifier.
|
| 172 |
+
p = sqlparse.parse('FROM AS foo')[0]
|
| 173 |
+
assert len(p.tokens) == 5
|
| 174 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 175 |
+
assert p.tokens[2].ttype is T.Keyword
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def test_format_accepts_encoding(load_file):
|
| 179 |
+
# issue20
|
| 180 |
+
sql = load_file('test_cp1251.sql', 'cp1251')
|
| 181 |
+
formatted = sqlparse.format(sql, reindent=True, encoding='cp1251')
|
| 182 |
+
tformatted = 'insert into foo\nvalues (1); -- Песня про надежду'
|
| 183 |
+
|
| 184 |
+
assert formatted == tformatted
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def test_stream(get_stream):
|
| 188 |
+
with get_stream("stream.sql") as stream:
|
| 189 |
+
p = sqlparse.parse(stream)[0]
|
| 190 |
+
assert p.get_type() == 'INSERT'
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def test_issue90():
|
| 194 |
+
sql = ('UPDATE "gallery_photo" SET "owner_id" = 4018, "deleted_at" = NULL,'
|
| 195 |
+
' "width" = NULL, "height" = NULL, "rating_votes" = 0,'
|
| 196 |
+
' "rating_score" = 0, "thumbnail_width" = NULL,'
|
| 197 |
+
' "thumbnail_height" = NULL, "price" = 1, "description" = NULL')
|
| 198 |
+
formatted = sqlparse.format(sql, reindent=True)
|
| 199 |
+
tformatted = '\n'.join([
|
| 200 |
+
'UPDATE "gallery_photo"',
|
| 201 |
+
'SET "owner_id" = 4018,',
|
| 202 |
+
' "deleted_at" = NULL,',
|
| 203 |
+
' "width" = NULL,',
|
| 204 |
+
' "height" = NULL,',
|
| 205 |
+
' "rating_votes" = 0,',
|
| 206 |
+
' "rating_score" = 0,',
|
| 207 |
+
' "thumbnail_width" = NULL,',
|
| 208 |
+
' "thumbnail_height" = NULL,',
|
| 209 |
+
' "price" = 1,',
|
| 210 |
+
' "description" = NULL'])
|
| 211 |
+
assert formatted == tformatted
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def test_except_formatting():
|
| 215 |
+
sql = 'SELECT 1 FROM foo WHERE 2 = 3 EXCEPT SELECT 2 FROM bar WHERE 1 = 2'
|
| 216 |
+
formatted = sqlparse.format(sql, reindent=True)
|
| 217 |
+
tformatted = '\n'.join([
|
| 218 |
+
'SELECT 1',
|
| 219 |
+
'FROM foo',
|
| 220 |
+
'WHERE 2 = 3',
|
| 221 |
+
'EXCEPT',
|
| 222 |
+
'SELECT 2',
|
| 223 |
+
'FROM bar',
|
| 224 |
+
'WHERE 1 = 2'])
|
| 225 |
+
assert formatted == tformatted
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def test_null_with_as():
|
| 229 |
+
sql = 'SELECT NULL AS c1, NULL AS c2 FROM t1'
|
| 230 |
+
formatted = sqlparse.format(sql, reindent=True)
|
| 231 |
+
tformatted = '\n'.join([
|
| 232 |
+
'SELECT NULL AS c1,',
|
| 233 |
+
' NULL AS c2',
|
| 234 |
+
'FROM t1'])
|
| 235 |
+
assert formatted == tformatted
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def test_issue190_open_file(filepath):
|
| 239 |
+
path = filepath('stream.sql')
|
| 240 |
+
with open(path) as stream:
|
| 241 |
+
p = sqlparse.parse(stream)[0]
|
| 242 |
+
assert p.get_type() == 'INSERT'
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def test_issue193_splitting_function():
|
| 246 |
+
sql = """ CREATE FUNCTION a(x VARCHAR(20)) RETURNS VARCHAR(20)
|
| 247 |
+
BEGIN
|
| 248 |
+
DECLARE y VARCHAR(20);
|
| 249 |
+
RETURN x;
|
| 250 |
+
END;
|
| 251 |
+
SELECT * FROM a.b;"""
|
| 252 |
+
statements = sqlparse.split(sql)
|
| 253 |
+
assert len(statements) == 2
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def test_issue194_splitting_function():
|
| 257 |
+
sql = """ CREATE FUNCTION a(x VARCHAR(20)) RETURNS VARCHAR(20)
|
| 258 |
+
BEGIN
|
| 259 |
+
DECLARE y VARCHAR(20);
|
| 260 |
+
IF (1 = 1) THEN
|
| 261 |
+
SET x = y;
|
| 262 |
+
END IF;
|
| 263 |
+
RETURN x;
|
| 264 |
+
END;
|
| 265 |
+
SELECT * FROM a.b;"""
|
| 266 |
+
statements = sqlparse.split(sql)
|
| 267 |
+
assert len(statements) == 2
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def test_issue186_get_type():
|
| 271 |
+
sql = "-- comment\ninsert into foo"
|
| 272 |
+
p = sqlparse.parse(sql)[0]
|
| 273 |
+
assert p.get_type() == 'INSERT'
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
def test_issue212_py2unicode():
|
| 277 |
+
t1 = sql.Token(T.String, 'schöner ')
|
| 278 |
+
t2 = sql.Token(T.String, 'bug')
|
| 279 |
+
token_list = sql.TokenList([t1, t2])
|
| 280 |
+
assert str(token_list) == 'schöner bug'
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
def test_issue213_leadingws():
|
| 284 |
+
sql = " select * from foo"
|
| 285 |
+
assert sqlparse.format(sql, strip_whitespace=True) == "select * from foo"
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
def test_issue227_gettype_cte():
|
| 289 |
+
select_stmt = sqlparse.parse('SELECT 1, 2, 3 FROM foo;')
|
| 290 |
+
assert select_stmt[0].get_type() == 'SELECT'
|
| 291 |
+
with_stmt = sqlparse.parse('WITH foo AS (SELECT 1, 2, 3)'
|
| 292 |
+
'SELECT * FROM foo;')
|
| 293 |
+
assert with_stmt[0].get_type() == 'SELECT'
|
| 294 |
+
with2_stmt = sqlparse.parse("""
|
| 295 |
+
WITH foo AS (SELECT 1 AS abc, 2 AS def),
|
| 296 |
+
bar AS (SELECT * FROM something WHERE x > 1)
|
| 297 |
+
INSERT INTO elsewhere SELECT * FROM foo JOIN bar;""")
|
| 298 |
+
assert with2_stmt[0].get_type() == 'INSERT'
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
def test_issue207_runaway_format():
|
| 302 |
+
sql = 'select 1 from (select 1 as one, 2 as two, 3 from dual) t0'
|
| 303 |
+
p = sqlparse.format(sql, reindent=True)
|
| 304 |
+
assert p == '\n'.join([
|
| 305 |
+
"select 1",
|
| 306 |
+
"from",
|
| 307 |
+
" (select 1 as one,",
|
| 308 |
+
" 2 as two,",
|
| 309 |
+
" 3",
|
| 310 |
+
" from dual) t0"])
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def test_token_next_doesnt_ignore_skip_cm():
|
| 314 |
+
sql = '--comment\nselect 1'
|
| 315 |
+
tok = sqlparse.parse(sql)[0].token_next(-1, skip_cm=True)[1]
|
| 316 |
+
assert tok.value == 'select'
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
@pytest.mark.parametrize('s', [
|
| 320 |
+
'SELECT x AS',
|
| 321 |
+
'AS'
|
| 322 |
+
])
|
| 323 |
+
def test_issue284_as_grouping(s):
|
| 324 |
+
p = sqlparse.parse(s)[0]
|
| 325 |
+
assert s == str(p)
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
def test_issue315_utf8_by_default():
|
| 329 |
+
# Make sure the lexer can handle utf-8 string by default correctly
|
| 330 |
+
# digest = '齐天大圣.カラフルな雲.사랑해요'
|
| 331 |
+
# The digest contains Chinese, Japanese and Korean characters
|
| 332 |
+
# All in 'utf-8' encoding.
|
| 333 |
+
digest = (
|
| 334 |
+
'\xe9\xbd\x90\xe5\xa4\xa9\xe5\xa4\xa7\xe5\x9c\xa3.'
|
| 335 |
+
'\xe3\x82\xab\xe3\x83\xa9\xe3\x83\x95\xe3\x83\xab\xe3\x81\xaa\xe9'
|
| 336 |
+
'\x9b\xb2.'
|
| 337 |
+
'\xec\x82\xac\xeb\x9e\x91\xed\x95\xb4\xec\x9a\x94'
|
| 338 |
+
)
|
| 339 |
+
sql = "select * from foo where bar = '{}'".format(digest)
|
| 340 |
+
formatted = sqlparse.format(sql, reindent=True)
|
| 341 |
+
tformatted = "select *\nfrom foo\nwhere bar = '{}'".format(digest)
|
| 342 |
+
assert formatted == tformatted
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
def test_issue322_concurrently_is_keyword():
|
| 346 |
+
s = 'CREATE INDEX CONCURRENTLY myindex ON mytable(col1);'
|
| 347 |
+
p = sqlparse.parse(s)[0]
|
| 348 |
+
|
| 349 |
+
assert len(p.tokens) == 12
|
| 350 |
+
assert p.tokens[0].ttype is T.Keyword.DDL # CREATE
|
| 351 |
+
assert p.tokens[2].ttype is T.Keyword # INDEX
|
| 352 |
+
assert p.tokens[4].ttype is T.Keyword # CONCURRENTLY
|
| 353 |
+
assert p.tokens[4].value == 'CONCURRENTLY'
|
| 354 |
+
assert isinstance(p.tokens[6], sql.Identifier)
|
| 355 |
+
assert p.tokens[6].value == 'myindex'
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
@pytest.mark.parametrize('s', [
|
| 359 |
+
'SELECT @min_price:=MIN(price), @max_price:=MAX(price) FROM shop;',
|
| 360 |
+
'SELECT @min_price:=MIN(price), @max_price:=MAX(price) FROM shop',
|
| 361 |
+
|
| 362 |
+
])
|
| 363 |
+
def test_issue359_index_error_assignments(s):
|
| 364 |
+
sqlparse.parse(s)
|
| 365 |
+
sqlparse.format(s, strip_comments=True)
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
def test_issue469_copy_as_psql_command():
|
| 369 |
+
formatted = sqlparse.format(
|
| 370 |
+
'\\copy select * from foo',
|
| 371 |
+
keyword_case='upper', identifier_case='capitalize')
|
| 372 |
+
assert formatted == '\\copy SELECT * FROM Foo'
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
@pytest.mark.xfail(reason='Needs to be fixed')
|
| 376 |
+
def test_issue484_comments_and_newlines():
|
| 377 |
+
formatted = sqlparse.format('\n'.join([
|
| 378 |
+
'Create table myTable',
|
| 379 |
+
'(',
|
| 380 |
+
' myId TINYINT NOT NULL, --my special comment',
|
| 381 |
+
' myName VARCHAR2(100) NOT NULL',
|
| 382 |
+
')']),
|
| 383 |
+
strip_comments=True)
|
| 384 |
+
assert formatted == ('\n'.join([
|
| 385 |
+
'Create table myTable',
|
| 386 |
+
'(',
|
| 387 |
+
' myId TINYINT NOT NULL,',
|
| 388 |
+
' myName VARCHAR2(100) NOT NULL',
|
| 389 |
+
')']))
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
def test_issue485_split_multi():
|
| 393 |
+
p_sql = '''CREATE OR REPLACE RULE ruled_tab_2rules AS ON INSERT
|
| 394 |
+
TO public.ruled_tab
|
| 395 |
+
DO instead (
|
| 396 |
+
select 1;
|
| 397 |
+
select 2;
|
| 398 |
+
);'''
|
| 399 |
+
assert len(sqlparse.split(p_sql)) == 1
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
def test_issue489_tzcasts():
|
| 403 |
+
p = sqlparse.parse('select bar at time zone \'UTC\' as foo')[0]
|
| 404 |
+
assert p.tokens[-1].has_alias() is True
|
| 405 |
+
assert p.tokens[-1].get_alias() == 'foo'
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
def test_issue562_tzcasts():
|
| 409 |
+
# Test that whitespace between 'from' and 'bar' is retained
|
| 410 |
+
formatted = sqlparse.format(
|
| 411 |
+
'SELECT f(HOUR from bar AT TIME ZONE \'UTC\') from foo', reindent=True
|
| 412 |
+
)
|
| 413 |
+
assert formatted == \
|
| 414 |
+
'SELECT f(HOUR\n from bar AT TIME ZONE \'UTC\')\nfrom foo'
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
def test_as_in_parentheses_indents():
|
| 418 |
+
# did raise NoneType has no attribute is_group in _process_parentheses
|
| 419 |
+
formatted = sqlparse.format('(as foo)', reindent=True)
|
| 420 |
+
assert formatted == '(as foo)'
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
def test_format_invalid_where_clause():
|
| 424 |
+
# did raise ValueError
|
| 425 |
+
formatted = sqlparse.format('where, foo', reindent=True)
|
| 426 |
+
assert formatted == 'where, foo'
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
def test_splitting_at_and_backticks_issue588():
|
| 430 |
+
splitted = sqlparse.split(
|
| 431 |
+
'grant foo to user1@`myhost`; grant bar to user1@`myhost`;')
|
| 432 |
+
assert len(splitted) == 2
|
| 433 |
+
assert splitted[-1] == 'grant bar to user1@`myhost`;'
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
def test_comment_between_cte_clauses_issue632():
|
| 437 |
+
p, = sqlparse.parse("""
|
| 438 |
+
WITH foo AS (),
|
| 439 |
+
-- A comment before baz subquery
|
| 440 |
+
baz AS ()
|
| 441 |
+
SELECT * FROM baz;""")
|
| 442 |
+
assert p.get_type() == "SELECT"
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
def test_copy_issue672():
|
| 446 |
+
p = sqlparse.parse('select * from foo')[0]
|
| 447 |
+
copied = copy.deepcopy(p)
|
| 448 |
+
assert str(p) == str(copied)
|
| 449 |
+
|
| 450 |
+
|
| 451 |
+
def test_primary_key_issue740():
|
| 452 |
+
p = sqlparse.parse('PRIMARY KEY')[0]
|
| 453 |
+
assert len(p.tokens) == 1
|
| 454 |
+
assert p.tokens[0].ttype == T.Keyword
|
| 455 |
+
|
| 456 |
+
|
| 457 |
+
@pytest.fixture
|
| 458 |
+
def limit_recursion():
|
| 459 |
+
curr_limit = sys.getrecursionlimit()
|
| 460 |
+
sys.setrecursionlimit(100)
|
| 461 |
+
yield
|
| 462 |
+
sys.setrecursionlimit(curr_limit)
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
def test_max_recursion(limit_recursion):
|
| 466 |
+
with pytest.raises(SQLParseError):
|
| 467 |
+
sqlparse.parse('[' * 1000 + ']' * 1000)
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_split.py
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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5 |
+
|
| 6 |
+
import pytest
|
| 7 |
+
|
| 8 |
+
import sqlparse
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_split_semicolon():
|
| 12 |
+
sql1 = 'select * from foo;'
|
| 13 |
+
sql2 = "select * from foo where bar = 'foo;bar';"
|
| 14 |
+
stmts = sqlparse.parse(''.join([sql1, sql2]))
|
| 15 |
+
assert len(stmts) == 2
|
| 16 |
+
assert str(stmts[0]) == sql1
|
| 17 |
+
assert str(stmts[1]) == sql2
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def test_split_backslash():
|
| 21 |
+
stmts = sqlparse.parse("select '\'; select '\'';")
|
| 22 |
+
assert len(stmts) == 2
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@pytest.mark.parametrize('fn', ['function.sql',
|
| 26 |
+
'function_psql.sql',
|
| 27 |
+
'function_psql2.sql',
|
| 28 |
+
'function_psql3.sql',
|
| 29 |
+
'function_psql4.sql'])
|
| 30 |
+
def test_split_create_function(load_file, fn):
|
| 31 |
+
sql = load_file(fn)
|
| 32 |
+
stmts = sqlparse.parse(sql)
|
| 33 |
+
assert len(stmts) == 1
|
| 34 |
+
assert str(stmts[0]) == sql
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_split_dashcomments(load_file):
|
| 38 |
+
sql = load_file('dashcomment.sql')
|
| 39 |
+
stmts = sqlparse.parse(sql)
|
| 40 |
+
assert len(stmts) == 3
|
| 41 |
+
assert ''.join(str(q) for q in stmts) == sql
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
@pytest.mark.parametrize('s', ['select foo; -- comment\n',
|
| 45 |
+
'select foo; -- comment\r',
|
| 46 |
+
'select foo; -- comment\r\n',
|
| 47 |
+
'select foo; -- comment'])
|
| 48 |
+
def test_split_dashcomments_eol(s):
|
| 49 |
+
stmts = sqlparse.parse(s)
|
| 50 |
+
assert len(stmts) == 1
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def test_split_begintag(load_file):
|
| 54 |
+
sql = load_file('begintag.sql')
|
| 55 |
+
stmts = sqlparse.parse(sql)
|
| 56 |
+
assert len(stmts) == 3
|
| 57 |
+
assert ''.join(str(q) for q in stmts) == sql
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def test_split_begintag_2(load_file):
|
| 61 |
+
sql = load_file('begintag_2.sql')
|
| 62 |
+
stmts = sqlparse.parse(sql)
|
| 63 |
+
assert len(stmts) == 1
|
| 64 |
+
assert ''.join(str(q) for q in stmts) == sql
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def test_split_dropif():
|
| 68 |
+
sql = 'DROP TABLE IF EXISTS FOO;\n\nSELECT * FROM BAR;'
|
| 69 |
+
stmts = sqlparse.parse(sql)
|
| 70 |
+
assert len(stmts) == 2
|
| 71 |
+
assert ''.join(str(q) for q in stmts) == sql
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def test_split_comment_with_umlaut():
|
| 75 |
+
sql = ('select * from foo;\n'
|
| 76 |
+
'-- Testing an umlaut: ä\n'
|
| 77 |
+
'select * from bar;')
|
| 78 |
+
stmts = sqlparse.parse(sql)
|
| 79 |
+
assert len(stmts) == 2
|
| 80 |
+
assert ''.join(str(q) for q in stmts) == sql
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def test_split_comment_end_of_line():
|
| 84 |
+
sql = ('select * from foo; -- foo\n'
|
| 85 |
+
'select * from bar;')
|
| 86 |
+
stmts = sqlparse.parse(sql)
|
| 87 |
+
assert len(stmts) == 2
|
| 88 |
+
assert ''.join(str(q) for q in stmts) == sql
|
| 89 |
+
# make sure the comment belongs to first query
|
| 90 |
+
assert str(stmts[0]) == 'select * from foo; -- foo\n'
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def test_split_casewhen():
|
| 94 |
+
sql = ("SELECT case when val = 1 then 2 else null end as foo;\n"
|
| 95 |
+
"comment on table actor is 'The actor table.';")
|
| 96 |
+
stmts = sqlparse.split(sql)
|
| 97 |
+
assert len(stmts) == 2
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def test_split_casewhen_procedure(load_file):
|
| 101 |
+
# see issue580
|
| 102 |
+
stmts = sqlparse.split(load_file('casewhen_procedure.sql'))
|
| 103 |
+
assert len(stmts) == 2
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def test_split_cursor_declare():
|
| 107 |
+
sql = ('DECLARE CURSOR "foo" AS SELECT 1;\n'
|
| 108 |
+
'SELECT 2;')
|
| 109 |
+
stmts = sqlparse.split(sql)
|
| 110 |
+
assert len(stmts) == 2
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def test_split_if_function(): # see issue 33
|
| 114 |
+
# don't let IF as a function confuse the splitter
|
| 115 |
+
sql = ('CREATE TEMPORARY TABLE tmp '
|
| 116 |
+
'SELECT IF(a=1, a, b) AS o FROM one; '
|
| 117 |
+
'SELECT t FROM two')
|
| 118 |
+
stmts = sqlparse.split(sql)
|
| 119 |
+
assert len(stmts) == 2
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def test_split_stream():
|
| 123 |
+
stream = StringIO("SELECT 1; SELECT 2;")
|
| 124 |
+
stmts = sqlparse.parsestream(stream)
|
| 125 |
+
assert isinstance(stmts, types.GeneratorType)
|
| 126 |
+
assert len(list(stmts)) == 2
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def test_split_encoding_parsestream():
|
| 130 |
+
stream = StringIO("SELECT 1; SELECT 2;")
|
| 131 |
+
stmts = list(sqlparse.parsestream(stream))
|
| 132 |
+
assert isinstance(stmts[0].tokens[0].value, str)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def test_split_unicode_parsestream():
|
| 136 |
+
stream = StringIO('SELECT ö')
|
| 137 |
+
stmts = list(sqlparse.parsestream(stream))
|
| 138 |
+
assert str(stmts[0]) == 'SELECT ö'
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def test_split_simple():
|
| 142 |
+
stmts = sqlparse.split('select * from foo; select * from bar;')
|
| 143 |
+
assert len(stmts) == 2
|
| 144 |
+
assert stmts[0] == 'select * from foo;'
|
| 145 |
+
assert stmts[1] == 'select * from bar;'
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def test_split_ignores_empty_newlines():
|
| 149 |
+
stmts = sqlparse.split('select foo;\nselect bar;\n')
|
| 150 |
+
assert len(stmts) == 2
|
| 151 |
+
assert stmts[0] == 'select foo;'
|
| 152 |
+
assert stmts[1] == 'select bar;'
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def test_split_quotes_with_new_line():
|
| 156 |
+
stmts = sqlparse.split('select "foo\nbar"')
|
| 157 |
+
assert len(stmts) == 1
|
| 158 |
+
assert stmts[0] == 'select "foo\nbar"'
|
| 159 |
+
|
| 160 |
+
stmts = sqlparse.split("select 'foo\n\bar'")
|
| 161 |
+
assert len(stmts) == 1
|
| 162 |
+
assert stmts[0] == "select 'foo\n\bar'"
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def test_split_mysql_handler_for(load_file):
|
| 166 |
+
# see issue581
|
| 167 |
+
stmts = sqlparse.split(load_file('mysql_handler.sql'))
|
| 168 |
+
assert len(stmts) == 2
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
@pytest.mark.parametrize('sql, expected', [
|
| 172 |
+
('select * from foo;', ['select * from foo']),
|
| 173 |
+
('select * from foo', ['select * from foo']),
|
| 174 |
+
('select * from foo; select * from bar;', [
|
| 175 |
+
'select * from foo',
|
| 176 |
+
'select * from bar',
|
| 177 |
+
]),
|
| 178 |
+
(' select * from foo;\n\nselect * from bar;\n\n\n\n', [
|
| 179 |
+
'select * from foo',
|
| 180 |
+
'select * from bar',
|
| 181 |
+
]),
|
| 182 |
+
('select * from foo\n\n; bar', ['select * from foo', 'bar']),
|
| 183 |
+
])
|
| 184 |
+
def test_split_strip_semicolon(sql, expected):
|
| 185 |
+
stmts = sqlparse.split(sql, strip_semicolon=True)
|
| 186 |
+
assert len(stmts) == len(expected)
|
| 187 |
+
for idx, expectation in enumerate(expected):
|
| 188 |
+
assert stmts[idx] == expectation
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def test_split_strip_semicolon_procedure(load_file):
|
| 192 |
+
stmts = sqlparse.split(load_file('mysql_handler.sql'),
|
| 193 |
+
strip_semicolon=True)
|
| 194 |
+
assert len(stmts) == 2
|
| 195 |
+
assert stmts[0].endswith('end')
|
| 196 |
+
assert stmts[1].endswith('end')
|
| 197 |
+
|
| 198 |
+
@pytest.mark.parametrize('sql, num', [
|
| 199 |
+
('USE foo;\nGO\nSELECT 1;\nGO', 4),
|
| 200 |
+
('SELECT * FROM foo;\nGO', 2),
|
| 201 |
+
('USE foo;\nGO 2\nSELECT 1;', 3)
|
| 202 |
+
])
|
| 203 |
+
def test_split_go(sql, num): # issue762
|
| 204 |
+
stmts = sqlparse.split(sql)
|
| 205 |
+
assert len(stmts) == num
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def test_split_multiple_case_in_begin(load_file): # issue784
|
| 209 |
+
stmts = sqlparse.split(load_file('multiple_case_in_begin.sql'))
|
| 210 |
+
assert len(stmts) == 1
|
tasks/andialbrecht__sqlparse.e57923b3.func_basic__0zb7o5ky/tests/trusted/tests/test_tokenize.py
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import types
|
| 2 |
+
from io import StringIO
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
import sqlparse
|
| 7 |
+
from sqlparse import lexer
|
| 8 |
+
from sqlparse import sql, tokens as T
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_tokenize_simple():
|
| 12 |
+
s = 'select * from foo;'
|
| 13 |
+
stream = lexer.tokenize(s)
|
| 14 |
+
assert isinstance(stream, types.GeneratorType)
|
| 15 |
+
tokens = list(stream)
|
| 16 |
+
assert len(tokens) == 8
|
| 17 |
+
assert len(tokens[0]) == 2
|
| 18 |
+
assert tokens[0] == (T.Keyword.DML, 'select')
|
| 19 |
+
assert tokens[-1] == (T.Punctuation, ';')
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def test_tokenize_backticks():
|
| 23 |
+
s = '`foo`.`bar`'
|
| 24 |
+
tokens = list(lexer.tokenize(s))
|
| 25 |
+
assert len(tokens) == 3
|
| 26 |
+
assert tokens[0] == (T.Name, '`foo`')
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@pytest.mark.parametrize('s', ['foo\nbar\n', 'foo\rbar\r',
|
| 30 |
+
'foo\r\nbar\r\n', 'foo\r\nbar\n'])
|
| 31 |
+
def test_tokenize_linebreaks(s):
|
| 32 |
+
# issue1
|
| 33 |
+
tokens = lexer.tokenize(s)
|
| 34 |
+
assert ''.join(str(x[1]) for x in tokens) == s
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_tokenize_inline_keywords():
|
| 38 |
+
# issue 7
|
| 39 |
+
s = "create created_foo"
|
| 40 |
+
tokens = list(lexer.tokenize(s))
|
| 41 |
+
assert len(tokens) == 3
|
| 42 |
+
assert tokens[0][0] == T.Keyword.DDL
|
| 43 |
+
assert tokens[2][0] == T.Name
|
| 44 |
+
assert tokens[2][1] == 'created_foo'
|
| 45 |
+
s = "enddate"
|
| 46 |
+
tokens = list(lexer.tokenize(s))
|
| 47 |
+
assert len(tokens) == 1
|
| 48 |
+
assert tokens[0][0] == T.Name
|
| 49 |
+
s = "join_col"
|
| 50 |
+
tokens = list(lexer.tokenize(s))
|
| 51 |
+
assert len(tokens) == 1
|
| 52 |
+
assert tokens[0][0] == T.Name
|
| 53 |
+
s = "left join_col"
|
| 54 |
+
tokens = list(lexer.tokenize(s))
|
| 55 |
+
assert len(tokens) == 3
|
| 56 |
+
assert tokens[2][0] == T.Name
|
| 57 |
+
assert tokens[2][1] == 'join_col'
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def test_tokenize_negative_numbers():
|
| 61 |
+
s = "values(-1)"
|
| 62 |
+
tokens = list(lexer.tokenize(s))
|
| 63 |
+
assert len(tokens) == 4
|
| 64 |
+
assert tokens[2][0] == T.Number.Integer
|
| 65 |
+
assert tokens[2][1] == '-1'
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def test_token_str():
|
| 69 |
+
token = sql.Token(None, 'FoO')
|
| 70 |
+
assert str(token) == 'FoO'
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def test_token_repr():
|
| 74 |
+
token = sql.Token(T.Keyword, 'foo')
|
| 75 |
+
tst = "<Keyword 'foo' at 0x"
|
| 76 |
+
assert repr(token)[:len(tst)] == tst
|
| 77 |
+
token = sql.Token(T.Keyword, '1234567890')
|
| 78 |
+
tst = "<Keyword '123456...' at 0x"
|
| 79 |
+
assert repr(token)[:len(tst)] == tst
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def test_token_flatten():
|
| 83 |
+
token = sql.Token(T.Keyword, 'foo')
|
| 84 |
+
gen = token.flatten()
|
| 85 |
+
assert isinstance(gen, types.GeneratorType)
|
| 86 |
+
lgen = list(gen)
|
| 87 |
+
assert lgen == [token]
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def test_tokenlist_repr():
|
| 91 |
+
p = sqlparse.parse('foo, bar, baz')[0]
|
| 92 |
+
tst = "<IdentifierList 'foo, b...' at 0x"
|
| 93 |
+
assert repr(p.tokens[0])[:len(tst)] == tst
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def test_single_quotes():
|
| 97 |
+
p = sqlparse.parse("'test'")[0]
|
| 98 |
+
tst = "<Single \"'test'\" at 0x"
|
| 99 |
+
assert repr(p.tokens[0])[:len(tst)] == tst
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def test_tokenlist_first():
|
| 103 |
+
p = sqlparse.parse(' select foo')[0]
|
| 104 |
+
first = p.token_first()
|
| 105 |
+
assert first.value == 'select'
|
| 106 |
+
assert p.token_first(skip_ws=False).value == ' '
|
| 107 |
+
assert sql.TokenList([]).token_first() is None
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def test_tokenlist_token_matching():
|
| 111 |
+
t1 = sql.Token(T.Keyword, 'foo')
|
| 112 |
+
t2 = sql.Token(T.Punctuation, ',')
|
| 113 |
+
x = sql.TokenList([t1, t2])
|
| 114 |
+
assert x.token_matching([lambda t: t.ttype is T.Keyword], 0) == t1
|
| 115 |
+
assert x.token_matching([lambda t: t.ttype is T.Punctuation], 0) == t2
|
| 116 |
+
assert x.token_matching([lambda t: t.ttype is T.Keyword], 1) is None
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def test_stream_simple():
|
| 120 |
+
stream = StringIO("SELECT 1; SELECT 2;")
|
| 121 |
+
|
| 122 |
+
tokens = lexer.tokenize(stream)
|
| 123 |
+
assert len(list(tokens)) == 9
|
| 124 |
+
|
| 125 |
+
stream.seek(0)
|
| 126 |
+
tokens = list(lexer.tokenize(stream))
|
| 127 |
+
assert len(tokens) == 9
|
| 128 |
+
|
| 129 |
+
stream.seek(0)
|
| 130 |
+
tokens = list(lexer.tokenize(stream))
|
| 131 |
+
assert len(tokens) == 9
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def test_stream_error():
|
| 135 |
+
stream = StringIO("FOOBAR{")
|
| 136 |
+
|
| 137 |
+
tokens = list(lexer.tokenize(stream))
|
| 138 |
+
assert len(tokens) == 2
|
| 139 |
+
assert tokens[1][0] == T.Error
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
@pytest.mark.parametrize('expr', [
|
| 143 |
+
'JOIN',
|
| 144 |
+
'LEFT JOIN',
|
| 145 |
+
'LEFT OUTER JOIN',
|
| 146 |
+
'FULL OUTER JOIN',
|
| 147 |
+
'NATURAL JOIN',
|
| 148 |
+
'CROSS JOIN',
|
| 149 |
+
'STRAIGHT JOIN',
|
| 150 |
+
'INNER JOIN',
|
| 151 |
+
'LEFT INNER JOIN'])
|
| 152 |
+
def test_parse_join(expr):
|
| 153 |
+
p = sqlparse.parse('{} foo'.format(expr))[0]
|
| 154 |
+
assert len(p.tokens) == 3
|
| 155 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
def test_parse_union(): # issue294
|
| 159 |
+
p = sqlparse.parse('UNION ALL')[0]
|
| 160 |
+
assert len(p.tokens) == 1
|
| 161 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
@pytest.mark.parametrize('s', ['END IF', 'END IF', 'END\t\nIF',
|
| 165 |
+
'END LOOP', 'END LOOP', 'END\t\nLOOP'])
|
| 166 |
+
def test_parse_endifloop(s):
|
| 167 |
+
p = sqlparse.parse(s)[0]
|
| 168 |
+
assert len(p.tokens) == 1
|
| 169 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
@pytest.mark.parametrize('s', [
|
| 173 |
+
'ASC', 'DESC',
|
| 174 |
+
'NULLS FIRST', 'NULLS LAST',
|
| 175 |
+
'ASC NULLS FIRST', 'ASC NULLS LAST',
|
| 176 |
+
'DESC NULLS FIRST', 'DESC NULLS LAST',
|
| 177 |
+
])
|
| 178 |
+
def test_parse_order(s): # issue487
|
| 179 |
+
p = sqlparse.parse(s)[0]
|
| 180 |
+
assert len(p.tokens) == 1
|
| 181 |
+
assert p.tokens[0].ttype is T.Keyword.Order
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
@pytest.mark.parametrize('s', [
|
| 185 |
+
'foo',
|
| 186 |
+
'Foo',
|
| 187 |
+
'FOO',
|
| 188 |
+
'v$name', # issue291
|
| 189 |
+
])
|
| 190 |
+
def test_parse_identifiers(s):
|
| 191 |
+
p = sqlparse.parse(s)[0]
|
| 192 |
+
assert len(p.tokens) == 1
|
| 193 |
+
token = p.tokens[0]
|
| 194 |
+
assert str(token) == s
|
| 195 |
+
assert isinstance(token, sql.Identifier)
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def test_parse_group_by():
|
| 199 |
+
p = sqlparse.parse('GROUP BY')[0]
|
| 200 |
+
assert len(p.tokens) == 1
|
| 201 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def test_parse_order_by():
|
| 205 |
+
p = sqlparse.parse('ORDER BY')[0]
|
| 206 |
+
assert len(p.tokens) == 1
|
| 207 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
def test_parse_window_as():
|
| 211 |
+
p = sqlparse.parse('WINDOW w AS')[0]
|
| 212 |
+
assert len(p.tokens) == 5
|
| 213 |
+
assert p.tokens[0].ttype is T.Keyword
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
@pytest.mark.parametrize('s', (
|
| 217 |
+
"LIKE", "ILIKE", "NOT LIKE", "NOT ILIKE",
|
| 218 |
+
"NOT LIKE", "NOT ILIKE",
|
| 219 |
+
))
|
| 220 |
+
def test_like_and_ilike_parsed_as_comparisons(s):
|
| 221 |
+
p = sqlparse.parse(s)[0]
|
| 222 |
+
assert len(p.tokens) == 1
|
| 223 |
+
assert p.tokens[0].ttype == T.Operator.Comparison
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
@pytest.mark.parametrize('s', (
|
| 227 |
+
"LIKEaaa", "bILIKE", "aaILIKEbb", "NOTLIKE", "NOTILIKE",
|
| 228 |
+
))
|
| 229 |
+
def test_near_like_and_ilike_parsed_appropriately(s):
|
| 230 |
+
p = sqlparse.parse(s)[0]
|
| 231 |
+
assert len(p.tokens) == 1
|
| 232 |
+
assert isinstance(p.tokens[0], sql.Identifier)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
@pytest.mark.parametrize('s', (
|
| 236 |
+
'AT TIME ZONE \'UTC\'',
|
| 237 |
+
))
|
| 238 |
+
def test_parse_tzcast(s):
|
| 239 |
+
p = sqlparse.parse(s)[0]
|
| 240 |
+
assert len(p.tokens) == 1
|
| 241 |
+
assert p.tokens[0].ttype == T.Keyword.TZCast
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
def test_cli_commands():
|
| 245 |
+
p = sqlparse.parse('\\copy')[0]
|
| 246 |
+
assert len(p.tokens) == 1
|
| 247 |
+
assert p.tokens[0].ttype == T.Command
|