MCPcopy Index your code
hub / github.com/python-websockets/websockets / run_main

Method run_main

tests/test_cli.py:28–49  ·  view source on GitHub ↗
(self, argv, inputs="", close_input=False, expected_exit_code=None)

Source from the content-addressed store, hash-verified

26
27class CLITests(unittest.TestCase):
28 def run_main(self, argv, inputs="", close_input=False, expected_exit_code=None):
29 # Replace sys.stdin with a file-like object backed by a file descriptor
30 # for compatibility with loop.connect_read_pipe().
31 stdin_read_fd, stdin_write_fd = os.pipe()
32 stdin = io.FileIO(stdin_read_fd)
33 self.addCleanup(stdin.close)
34 os.write(stdin_write_fd, inputs.encode())
35 if close_input:
36 os.close(stdin_write_fd)
37 else:
38 self.addCleanup(os.close, stdin_write_fd)
39 # Replace sys.stdout with a file-like object to record outputs.
40 stdout = io.StringIO()
41 with patch("sys.stdin", new=stdin), patch("sys.stdout", new=stdout):
42 # Catch sys.exit() calls when expected.
43 if expected_exit_code is not None:
44 with self.assertRaises(SystemExit) as raised:
45 main(argv)
46 self.assertEqual(raised.exception.code, expected_exit_code)
47 else:
48 main(argv)
49 return stdout.getvalue()
50
51 def test_version(self):
52 output = self.run_main(["--version"])

Callers 7

test_versionMethod · 0.95
test_send_messageMethod · 0.95
test_close_connectionMethod · 0.95
test_no_argsMethod · 0.95

Calls 4

mainFunction · 0.50
writeMethod · 0.45
encodeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected