vimtk._demo.vimmock.mocked module

Place this script in your the vimrc to inspect attributes of the real vim python module. This can be used to make this module more accurately reflect the real vim object.

python << endpython

def attrinfo(basename, base, attrname):

attr = getattr(base, attrname) print(’n——‘) print(‘%s.%s: %r’ % (basename, attrname, attr)) print(‘type(%s.%s): %r’ % (basename, attrname, type(attr))) print(‘dir(%s.%s): %r’ % (basename, attrname, dir(attr)))

print(’nn VIM BASE’) print(‘vim = %r’ % (vim,)) print(‘type(vim) = %r’ % (type(vim),)) print(‘dir(vim) = %r’ % (dir(vim),))

print(’nn VIM CURRENT’) attrinfo(‘vim’, vim, ‘current’) attrinfo(‘vim.current’, vim.current, ‘tabpage’) attrinfo(‘vim.current’, vim.current, ‘line’) attrinfo(‘vim.current’, vim.current, ‘window’) attrinfo(‘vim.current’, vim.current, ‘range’)

attrinfo(‘vim.current’, vim.current, ‘buffer’)

attrinfo(‘vim.current.buffer’, vim.current.buffer, ‘number’) attrinfo(‘vim.current.buffer’, vim.current.buffer, ‘name’) attrinfo(‘vim.current.buffer’, vim.current.buffer, ‘options’) attrinfo(‘vim.current.buffer’, vim.current.buffer, ‘range’) attrinfo(‘vim.current.buffer’, vim.current.buffer, ‘valid’) attrinfo(‘vim.current.buffer’, vim.current.buffer, ‘vars’) attrinfo(‘vim.current.buffer’, vim.current.buffer, ‘mark’)

endpython

exception vimtk._demo.vimmock.mocked.VimErrorMock[source]

Bases: Exception

class vimtk._demo.vimmock.mocked.LineMock[source]

Bases: object

vimtk._demo.vimmock.mocked.classname(obj)[source]
class vimtk._demo.vimmock.mocked.BufferMock(text=None)[source]

Bases: NiceRepr

Attributes of the REAL vim.buffer object

[‘__dir__’, ‘__members__’, ‘append’, ‘mark’, ‘name’, ‘number’, ‘options’, ‘range’, ‘valid’, ‘vars’]

_setmark(key, pos)[source]
_visual_select(row1, row2, col1=0, col2=None)[source]

first and last line to select inclusive

mark(key)[source]

Return the 1-based line number of a mark

property _text
setup_text(text=None, name='')[source]
open_file(filepath)[source]
append(other)[source]

the vim buffer append is actually an extend call

class vimtk._demo.vimmock.mocked.WindowMock(cursor=None)[source]

Bases: object

” RealObjectInfo:

vim.current.window: <window 0> type(vim.current.window): <type ‘vim.window’> dir(vim.current.window): [‘__dir__’, ‘__members__’, ‘buffer’, ‘col’,

‘cursor’, ‘height’, ‘number’, ‘options’, ‘row’, ‘tabpage’, ‘valid’, ‘vars’]

class vimtk._demo.vimmock.mocked.RangeMock[source]

Bases: object

RealObjectInfo:

vim.current.range: <range (1:1)> type(vim.current.range): <type ‘vim.range’> dir(vim.current.range): [‘__dir__’, ‘__members__’, ‘append’, ‘end’, ‘start’]

class vimtk._demo.vimmock.mocked.TabPageMock[source]

Bases: object

RealObjectInfo:

vim.current.tabpage: <tabpage 0> type(vim.current.tabpage): <type ‘vim.tabpage’> dir(vim.current.tabpage): [‘__dir__’, ‘__members__’, ‘number’, ‘valid’,

‘vars’, ‘window’, ‘windows’]

class vimtk._demo.vimmock.mocked.CurrentMock(text=None)[source]

Bases: object

RealObjectInfo:

vim.current: <vim.currentdata object at 0x8718a0> type(vim.current): <type ‘vim.currentdata’> dir(vim.current): [‘__dir__’, ‘__members__’, ‘buffer’, ‘line’, ‘range’, ‘tabpage’, ‘window’]

class vimtk._demo.vimmock.mocked.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