def test_incorrect_log_level(tmpdir, caplog, logfile): # excuse my confusion over this but how the hell does anything pass setup_logging(name=tmpdir.strpath, level="30") 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")
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" )
import json import os import pytest import pynvim pynvim.setup_logging("test") @pytest.fixture def vim(): child_argv = os.environ.get('NVIM_CHILD_ARGV') listen_address = os.environ.get('NVIM_LISTEN_ADDRESS') if child_argv is None and listen_address is None: child_argv = '["nvim", "-u", "NONE", "--embed", "--headless"]' if child_argv is not None: editor = pynvim.attach('child', argv=json.loads(child_argv)) else: assert listen_address is None or listen_address != '' editor = pynvim.attach('socket', path=listen_address) return editor
import json import os from pynvim import attach, setup_logging from pytest import fixture import logging setup_logging("test") logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) @fixture def vim() -> None: child_argv = os.environ.get("NVIM_CHILD_ARGV") listen_address = os.environ.get("NVIM_LISTEN_ADDRESS") if child_argv is None and listen_address is None: child_argv = '["nvim", "-u", "NONE", "-i", "NONE", "--embed", "--headless"]' if child_argv is not None: vim = attach("child", argv=json.loads(child_argv)) else: assert listen_address is None or listen_address != "" vim = attach("socket", path=listen_address) vim.command("autocmd BufEnter :set bufhidden=wipe<CR>") yield vim logger.info("teardown")
from os import environ assert __name__ == "__main__" if "" in sys.path: sys.path.remove("") serveraddr = sys.argv[1] yarpid = int(sys.argv[2]) module = sys.argv[3] module_obj = None nvim = None environ['NVIM_YARP_MODULE'] = module setup_logging(module) def on_request(method, args): if hasattr(module_obj, method): return getattr(module_obj, method)(*args) else: raise Exception('method %s not found' % method) def on_notification(method, args): if hasattr(module_obj, method): getattr(module_obj, method)(*args) else: raise Exception('method %s not found' % method) pass
def test_create_logfile_envvar(tmpdir, monkeypatch): prefix = tmpdir.join("testlog1") monkeypatch.setenv("NVIM_PYTHON_LOG_FILE", prefix.strpath) setup_logging(name=os.environ.get("NVIM_PYTHON_LOG_FILE"), level=30) assert os.path.exists(logfile) assert caplog.messages == []
def test_create_logfile_envvar(logfile, monkeypatch): monkeypatch.setenv("NVIM_PYTHON_LOG_LEVEL", logging.WARNING) setup_logging(name="foo", level=os.environ.get("NVIM_PYTHON_LOG_LEVEL")) assert os.path.exists(logfile) with open(logfile, "r") as f: assert f.read() == ""
def test_log_file_exists_readable(logfile): setup_logging("name2") assert os.path.exists(logfile) with open(logfile, "r") as f: assert f.read() == ""
def convert_to_logfile(path): return setup_logging(path)
import json import os import textwrap import pynvim import pytest pynvim.setup_logging("test") @pytest.fixture(autouse=True) def cleanup_func(vim): fun = textwrap.dedent('''function! BeforeEachTest() set all& redir => groups silent augroup redir END for group in split(groups) exe 'augroup '.group autocmd! augroup END endfor autocmd! tabnew let curbufnum = eval(bufnr('%')) redir => buflist silent ls! redir END let bufnums = [] for buf in split(buflist, '\\n') let bufnum = eval(split(buf, '[ u]')[0])