File: test_concurrency.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 (19 lines) | stat: -rw-r--r-- 649 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from threading import Timer


def test_interrupt_from_another_thread(vim):
    timer = Timer(0.5, lambda: vim.async_call(lambda: vim.stop_loop()))
    timer.start()
    assert vim.next_message() is None


def test_exception_in_threadsafe_call(vim):
    # an exception in a threadsafe_call shouldn't crash the entire host
    msgs = []
    vim.async_call(lambda: [vim.eval("3"), undefined_variable])  # noqa: F821
    timer = Timer(0.5, lambda: vim.async_call(lambda: vim.stop_loop()))
    timer.start()
    vim.run_loop(None, None, err_cb=msgs.append)
    assert len(msgs) == 1
    msgs[0].index('NameError')
    msgs[0].index('undefined_variable')