File: test_logging.py

package info (click to toggle)
python-pynvim 0.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 344 kB
  • sloc: python: 2,538; sh: 6; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 1,121 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import sys


def test_setup_logging(monkeypatch, tmpdir, caplog):
    from pynvim import setup_logging

    major_version = sys.version_info[0]

    setup_logging('name1')
    assert caplog.messages == []

    def get_expected_logfile(prefix, name):
        return '{}_py{}_{}'.format(prefix, major_version, name)

    prefix = tmpdir.join('testlog1')
    monkeypatch.setenv('NVIM_PYTHON_LOG_FILE', str(prefix))
    setup_logging('name2')
    assert caplog.messages == []
    logfile = get_expected_logfile(prefix, 'name2')
    assert os.path.exists(logfile)
    assert open(logfile, 'r').read() == ''

    monkeypatch.setenv('NVIM_PYTHON_LOG_LEVEL', 'invalid')
    setup_logging('name3')
    assert caplog.record_tuples == [
        ('pynvim', 30, "Invalid NVIM_PYTHON_LOG_LEVEL: 'invalid', using INFO."),
    ]
    logfile = get_expected_logfile(prefix, 'name2')
    assert os.path.exists(logfile)
    with open(logfile, 'r') as f:
        lines = f.readlines()
        assert len(lines) == 1
        assert lines[0].endswith(
            "- Invalid NVIM_PYTHON_LOG_LEVEL: 'invalid', using INFO.\n"
        )