vimtk._demo.vimmock package

Submodules

Module contents

vim mock object for easier testing of vim plugins written in Python.

Originally from https://github.com/Erotemic/vimmock/tree/buffer_filename

class vimtk._demo.vimmock.VimMock[source]

Bases: object

The real vim module is defined in the c source code (if_python.c, if_python3.c, if_py_both.h, etc…) in the vim package. Therefore it is difficult to replicate its behavior exactly.

vim = <module ‘vim’ (built-in)> type(vim) = <type ‘module’>

The Attributes of the REAL vim module are: {

# Vim Types

‘Buffer’: vim.buffer, ‘Dictionary’: vim.dictionary, ‘Function’: vim.function, ‘List’: vim.list, ‘Options’: vim.options, ‘Range’: vim.range, ‘TabPage’: vim.tabpage, ‘Window’: vim.window, ‘_Loader’: vim.Loader,

# Members of numeric_constant ‘VAR_DEF_SCOPE’: 2, ‘VAR_FIXED’: 2, ‘VAR_LOCKED’: 1, ‘VAR_SCOPE’: 1, ‘VIM_SPECIAL_PATH’: ‘_vim_path_’,

# Members of object_constant ‘buffers’: <vim.bufferlist object at 0x8718d0>, ‘windows’: <vim.windowlist object at 0x8718b0>, ‘current’: <vim.currentdata object at 0x8718a0>, ‘tabpages’: <vim.tabpagelist object at 0x871890>,

# The vim module definitions

‘command’: <built-in function command>, ‘eval’: <built-in function eval>, ‘bindeval’: <built-in function bindeval>, ‘strwidth’: <built-in function strwidth>, ‘chdir’: <built-in function chdir>, ‘fchdir’: <built-in function fchdir>, ‘foreach_rtp’: <built-in function foreach_rtp>, ‘find_module’: <built-in function find_module>, ‘path_hook’: <built-in function path_hook>, ‘_get_paths’: <built-in function _get_paths>,

# Python versions of redefined functions ‘_chdir’: <built-in function chdir>, ‘_fchdir’: <built-in function fchdir>, ‘_find_module’: <built-in function find_module>, ‘_getcwd’: <built-in function getcwd>, ‘_load_module’: <built-in function load_module>,

# Checked objects ‘options’: <vim.options object at 0x7fae81970c30>, ‘vars’: <vim.dictionary object at 0x7fae8196dc90>, ‘vvars’: <vim.dictionary object at 0x7fae8196dcc0>,

# Error definition ‘error’: vim.error,

‘__doc__’: None, ‘__name__’: ‘vim’, ‘__package__’: None,

# The module also defines these attributes, but they are just imprted from # other places ‘os’: <module ‘os’ from ‘/usr/lib/python2.7/os.pyc’>, }

VAR_DEF_SCOPE = 2
VAR_FIXED = 2
VAR_LOCKED = 1
VAR_SCOPE = 1
VIM_SPECIAL_PATH = '_vim_path_'
Buffer

alias of BufferMock

Range

alias of RangeMock

TabPage

alias of TabPageMock

Window

alias of WindowMock

error

alias of VimErrorMock

vim_mode_codes = {'!': 'Shell', 'R': 'Replace', 'Rv': 'VReplace', 'S': 'SLine', 'V': 'VLine', 'c': 'Command', 'ce': 'Ex', 'cv': 'VimEx', 'i': 'Insert', 'n': 'Normal', 'no': 'NOperatorPending', 'r': 'Prompt', 'r?': 'Confirm', 'rm': 'More', 's': 'Select', 'v': 'Visual'}
_push_function_stack(name, named={}, positional=[])[source]

Simulate being inside a vim function

setup_text(text, name='')[source]

special mock-only function to put text into the buffer

move_cursor(row, col=0)[source]

Move the cursor to a particular row / column

Note

rows are 1 indexed but columns are 0 indexed

open_file(filepath, cursor=None)[source]

special mock-only function to put text into the buffer

command(command)[source]

Hack that pretends to “execute” a vim command

eval(command)[source]

A very hack, and very specific implementation of vim eval for tests.

This only handles very specific commands.

_eval_assignment(command)[source]

References

vimtk._demo.vimmock.patch_vim()[source]

Sets new VimMock instance under vim key within sys.modules.