Skip to content

Commit

Permalink
Added vimmock.patch_vim
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszb committed Nov 12, 2012
1 parent 9f6a281 commit 42acd15
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
19 changes: 17 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ Usage
=====

At the test environment initialization one should prepare ``vim`` object that
would normaly be used within vim's plugin. Example::
would normaly be used within vim's plugin. We have added convenient function for
that::

import vimmock
vimmock.patch_vim()

This is equivalent to::

import sys
from vimmock import VimMock

sys.modules['vim'] = VimMock()

Once this is done one can start importing *vim* module which would be instance
of *VimMock* class. From now on we can write our tests::
of *VimMock* class. From now on we can write our tests (and import ``vim``
module)::

import vim
import unittest
Expand All @@ -46,3 +52,12 @@ Development
Please use github's issue tracker for filing new issues. Preferred way of
attaching patches is via *pull requests*.


Work in progress
----------------

Please note that ``vimmock`` is a work-in-progress module. Only basic mocks are
actually completed. If you want to use this module for now it is best if you
fork it, link to your ``PYTHONPATH`` environment variable and modify on the fly.
Pull requests are welcome!

8 changes: 8 additions & 0 deletions vimmock/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
vim mock object for easier testing of vim plugins written in Python.
"""
import sys
from vimmock.mocked import VimMock

VERSION = (0, 1, 0)
Expand All @@ -15,3 +16,10 @@ def get_version():
"""
return '.'.join((str(each) for each in VERSION[:4]))


def patch_vim():
"""
Sets new ``VimMock`` instance under ``vim`` key within ``sys.modules``.
"""
sys.modules['vim'] = VimMock()

11 changes: 11 additions & 0 deletions vimmock/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from vimmock.mocked import RangeMock
from vimmock.mocked import VimMock
from vimmock.mocked import WindowMock
import sys
import vimmock


class TestVimMock(unittest.TestCase):
Expand Down Expand Up @@ -71,6 +73,15 @@ def test_init(self):
self.assertTrue(isinstance(self.current.range, RangeMock))


class TestPatch(unittest.TestCase):

def test_patch_vim(self):
sys.modules['vim'] = object()

vimmock.patch_vim()
self.assertIsInstance(sys.modules['vim'], VimMock)


if __name__ == '__main__':
unittest.main()

0 comments on commit 42acd15

Please sign in to comment.