MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / test_log_and_exit

Function test_log_and_exit

tests/error_handler_test.py:110–153  ·  view source on GitHub ↗
(cap_out, mock_store_dir)

Source from the content-addressed store, hash-verified

108
109
110def test_log_and_exit(cap_out, mock_store_dir):
111 tb = (
112 'Traceback (most recent call last):\n'
113 ' File "<stdin>", line 2, in <module>\n'
114 'pre_commit.errors.FatalError: hai\n'
115 )
116
117 with pytest.raises(SystemExit) as excinfo:
118 error_handler._log_and_exit('msg', 1, FatalError('hai'), tb)
119 assert excinfo.value.code == 1
120
121 printed = cap_out.get()
122 log_file = os.path.join(mock_store_dir, 'pre-commit.log')
123 assert printed == f'msg: FatalError: hai\nCheck the log at {log_file}\n'
124
125 assert os.path.exists(log_file)
126 with open(log_file) as f:
127 logged = f.read()
128 pattern = re_assert.Matches(
129 r'^### version information\n'
130 r'\n'
131 r'```\n'
132 r'pre-commit version: \d+\.\d+\.\d+\n'
133 r'git --version: git version .+\n'
134 r'sys.version:\n'
135 r'( .*\n)*'
136 r'sys.executable: .*\n'
137 r'os.name: .*\n'
138 r'sys.platform: .*\n'
139 r'```\n'
140 r'\n'
141 r'### error information\n'
142 r'\n'
143 r'```\n'
144 r'msg: FatalError: hai\n'
145 r'```\n'
146 r'\n'
147 r'```\n'
148 r'Traceback \(most recent call last\):\n'
149 r' File "<stdin>", line 2, in <module>\n'
150 r'pre_commit\.errors\.FatalError: hai\n'
151 r'```\n',
152 )
153 pattern.assert_matches(logged)
154
155
156def test_error_handler_non_ascii_exception(mock_store_dir):

Callers

nothing calls this directly

Calls 3

FatalErrorClass · 0.90
existsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected