5
def test_setup_logging(monkeypatch, tmpdir, caplog):
6
from pynvim import setup_logging
8
major_version = sys.version_info[0]
10
setup_logging('name1')
11
assert caplog.messages == []
13
def get_expected_logfile(prefix, name):
14
return '{}_py{}_{}'.format(prefix, major_version, name)
16
prefix = tmpdir.join('testlog1')
17
monkeypatch.setenv('NVIM_PYTHON_LOG_FILE', str(prefix))
18
setup_logging('name2')
19
assert caplog.messages == []
20
logfile = get_expected_logfile(prefix, 'name2')
21
assert os.path.exists(logfile)
22
assert open(logfile, 'r').read() == ''
24
monkeypatch.setenv('NVIM_PYTHON_LOG_LEVEL', 'invalid')
25
setup_logging('name3')
26
assert caplog.record_tuples == [
27
('pynvim', 30, "Invalid NVIM_PYTHON_LOG_LEVEL: 'invalid', using INFO."),
29
logfile = get_expected_logfile(prefix, 'name2')
30
assert os.path.exists(logfile)
31
with open(logfile, 'r') as f:
33
assert len(lines) == 1
34
assert lines[0].endswith(
35
"- Invalid NVIM_PYTHON_LOG_LEVEL: 'invalid', using INFO.\n"