MCPcopy Index your code
hub / github.com/dbcli/pgcli / run_with_watch

Function run_with_watch

tests/test_main.py:400–416  ·  view source on GitHub ↗

:param query: Input to the CLI :param target_call_count: Number of times the user lets the command run before Ctrl-C :param expected_output: Substring expected to be found for each executed query :param expected_timing: value `time.sleep` expected to be called with o

(query, target_call_count=1, expected_output="", expected_timing=None)

Source from the content-addressed store, hash-verified

398 cli = PGCli(pgexecute=executor)
399
400 def run_with_watch(query, target_call_count=1, expected_output="", expected_timing=None):
401 """
402 :param query: Input to the CLI
403 :param target_call_count: Number of times the user lets the command run before Ctrl-C
404 :param expected_output: Substring expected to be found for each executed query
405 :param expected_timing: value `time.sleep` expected to be called with on every invocation
406 """
407 with mock.patch.object(cli, "echo_via_pager") as mock_echo, mock.patch("pgcli.main.sleep") as mock_sleep:
408 mock_sleep.side_effect = [None] * (target_call_count - 1) + [KeyboardInterrupt]
409 cli.handle_watch_command(query)
410 # Validate that sleep was called with the right timing
411 for i in range(target_call_count - 1):
412 assert mock_sleep.call_args_list[i][0][0] == expected_timing
413 # Validate that the output of the query was expected
414 assert mock_echo.call_count == target_call_count
415 for i in range(target_call_count):
416 assert expected_output in mock_echo.call_args_list[i][0][0]
417
418 # With no history, it errors.
419 with mock.patch("pgcli.main.click.secho") as mock_secho:

Callers 1

test_watch_worksFunction · 0.85

Calls 1

handle_watch_commandMethod · 0.80

Tested by

no test coverage detected