Skip to content

Commit 55359e7

Browse files
Add tests for parse_sql
1 parent 0df2cdb commit 55359e7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

tests/test_utils_parse_sql.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import pytest
2+
3+
from datajoint.utils import parse_sql
4+
5+
6+
def test_parse_sql_with_trailing_delimiter(tmp_path):
7+
sql_file = tmp_path / "script.sql"
8+
sql_file.write_text(
9+
"""
10+
-- comment should be ignored
11+
CREATE TABLE t (id INT);
12+
INSERT INTO t VALUES (1);
13+
"""
14+
)
15+
statements = list(parse_sql(sql_file))
16+
assert statements == [
17+
"CREATE TABLE t (id INT);",
18+
"INSERT INTO t VALUES (1);",
19+
]
20+
21+
22+
def test_parse_sql_without_trailing_delimiter(tmp_path):
23+
sql_file = tmp_path / "script.sql"
24+
sql_file.write_text(
25+
"""
26+
CREATE TABLE t (id INT);
27+
INSERT INTO t VALUES (1)
28+
"""
29+
)
30+
statements = list(parse_sql(sql_file))
31+
assert statements == [
32+
"CREATE TABLE t (id INT);",
33+
"INSERT INTO t VALUES (1)",
34+
]

0 commit comments

Comments
 (0)