File: test_events.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 (55 lines) | stat: -rw-r--r-- 1,793 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-


def test_receiving_events(vim):
    vim.command('call rpcnotify(%d, "test-event", 1, 2, 3)' % vim.channel_id)
    event = vim.next_message()
    assert event[1] == 'test-event'
    assert event[2] == [1, 2, 3]
    vim.command('au FileType python call rpcnotify(%d, "py!", bufnr("$"))' %
                vim.channel_id)
    vim.command('set filetype=python')
    event = vim.next_message()
    assert event[1] == 'py!'
    assert event[2] == [vim.current.buffer.number]


def test_sending_notify(vim):
    # notify after notify
    vim.command("let g:test = 3", async_=True)
    cmd = 'call rpcnotify(%d, "test-event", g:test)' % vim.channel_id
    vim.command(cmd, async_=True)
    event = vim.next_message()
    assert event[1] == 'test-event'
    assert event[2] == [3]

    # request after notify
    vim.command("let g:data = 'xyz'", async_=True)
    assert vim.eval('g:data') == 'xyz'


def test_async_error(vim):
    # Invoke a bogus Ex command via notify (async).
    vim.command("lolwut", async_=True)
    event = vim.next_message()
    assert event[1] == 'nvim_error_event'


def test_broadcast(vim):
    vim.subscribe('event2')
    vim.command('call rpcnotify(0, "event1", 1, 2, 3)')
    vim.command('call rpcnotify(0, "event2", 4, 5, 6)')
    vim.command('call rpcnotify(0, "event2", 7, 8, 9)')
    event = vim.next_message()
    assert event[1] == 'event2'
    assert event[2] == [4, 5, 6]
    event = vim.next_message()
    assert event[1] == 'event2'
    assert event[2] == [7, 8, 9]
    vim.unsubscribe('event2')
    vim.subscribe('event1')
    vim.command('call rpcnotify(0, "event2", 10, 11, 12)')
    vim.command('call rpcnotify(0, "event1", 13, 14, 15)')
    msg = vim.next_message()
    assert msg[1] == 'event1'
    assert msg[2] == [13, 14, 15]