MCPcopy Create free account
hub / github.com/dbcli/mycli / assert_result_equal

Function assert_result_equal

test/pytests/test_sqlexecute.py:19–50  ·  view source on GitHub ↗

Assert that an sqlexecute.run() result matches the expected values.

(
    result,
    preamble=None,
    header=None,
    rows=None,
    status=None,
    status_plain=None,
    postamble=None,
    auto_status=True,
    assert_contains=False,
)

Source from the content-addressed store, hash-verified

17
18
19def assert_result_equal(
20 result,
21 preamble=None,
22 header=None,
23 rows=None,
24 status=None,
25 status_plain=None,
26 postamble=None,
27 auto_status=True,
28 assert_contains=False,
29):
30 """Assert that an sqlexecute.run() result matches the expected values."""
31 if status_plain is None and auto_status and rows:
32 status_plain = f"{len(rows)} row{'s' if len(rows) > 1 else ''} in set"
33 status = FormattedText([('', status_plain)])
34 fields = {
35 "preamble": preamble,
36 "header": header,
37 "rows": rows,
38 "postamble": postamble,
39 "status": status,
40 "status_plain": status_plain,
41 }
42
43 if assert_contains:
44 # Do a loose match on the results using the *in* operator.
45 for key, field in fields.items():
46 if field:
47 assert field in result[0][key]
48 else:
49 # Do an exact match on the fields.
50 assert result == [fields]
51
52
53@dbtest

Calls

no outgoing calls

Tested by

no test coverage detected