Skip to content

Commit 31e7325

Browse files
committed
add tests for SQLResult
1 parent a405fc2 commit 31e7325

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

test/pytests/test_sqlresult.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from prompt_toolkit.formatted_text import FormattedText
2+
3+
from mycli.packages.sqlresult import SQLResult
4+
5+
6+
def test_sqlresult_str_includes_all_fields() -> None:
7+
result = SQLResult(
8+
preamble='before',
9+
header=['id'],
10+
rows=[(1,)],
11+
postamble='after',
12+
status='ok',
13+
command={'name': 'watch', 'seconds': 1.0},
14+
)
15+
16+
assert 'before' in str(result)
17+
assert "['id']" in str(result)
18+
assert '[(1,)]' in str(result)
19+
assert 'after' in str(result)
20+
assert 'ok' in str(result)
21+
assert "{'name': 'watch', 'seconds': 1.0}" in str(result)
22+
23+
24+
def test_sqlresult_status_plain_handles_none_and_formatted_text() -> None:
25+
empty = SQLResult()
26+
formatted = SQLResult(status=FormattedText([('', '1 row in set'), ('', ', '), ('class:warn', '1 warning')]))
27+
28+
assert empty.status_plain is None
29+
assert formatted.status_plain == '1 row in set, 1 warning'

0 commit comments

Comments
 (0)