~neovim-ppa/neovim-ppa/python-neovim

« back to all changes in this revision

Viewing changes to test/test_logging.py

  • Committer: Justin M. Keyes
  • Author(s): Daniel Hahler
  • Date: 2019-10-17 07:15:12 UTC
  • Revision ID: git-v1:f3babfb1b0baf9294bf03ec7d089c893fef9e187
setup_logging: warn about invalid log level from env (#413)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import sys
 
3
 
 
4
 
 
5
def test_setup_logging(monkeypatch, tmpdir, caplog):
 
6
    from pynvim import setup_logging
 
7
 
 
8
    major_version = sys.version_info[0]
 
9
 
 
10
    setup_logging('name1')
 
11
    assert caplog.messages == []
 
12
 
 
13
    def get_expected_logfile(prefix, name):
 
14
        return '{}_py{}_{}'.format(prefix, major_version, name)
 
15
 
 
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() == ''
 
23
 
 
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."),
 
28
    ]
 
29
    logfile = get_expected_logfile(prefix, 'name2')
 
30
    assert os.path.exists(logfile)
 
31
    with open(logfile, 'r') as f:
 
32
        lines = f.readlines()
 
33
        assert len(lines) == 1
 
34
        assert lines[0].endswith(
 
35
            "- Invalid NVIM_PYTHON_LOG_LEVEL: 'invalid', using INFO.\n"
 
36
        )