summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2019-05-21 13:53:09 +0100
committerw0rp <devw0rp@gmail.com>2019-05-21 13:53:09 +0100
commit3e3801e81ef70d3b35b7c527fbd1b4f62d50bae5 (patch)
tree79ce1ca62632864002e002bef38e957fe46025bb /test
parent89db85121c001fc60787647f012978a2328816a5 (diff)
downloadale-3e3801e81ef70d3b35b7c527fbd1b4f62d50bae5.zip
Revert "Fix #2492 - Remove all Deoplete support for now"
This reverts commit 975cc7af8fbabe234a220c84e56b7ff719d8d959.
Diffstat (limited to 'test')
-rw-r--r--test/python/test_deoplete_source.py147
-rwxr-xr-xtest/script/custom-checks10
2 files changed, 157 insertions, 0 deletions
diff --git a/test/python/test_deoplete_source.py b/test/python/test_deoplete_source.py
new file mode 100644
index 00000000..28eec5cd
--- /dev/null
+++ b/test/python/test_deoplete_source.py
@@ -0,0 +1,147 @@
+import unittest
+import imp
+
+ale_module = imp.load_source(
+ 'deoplete.sources.ale',
+ '/testplugin/rplugin/python3/deoplete/sources/ale.py',
+)
+
+
+class VimMock(object):
+ def __init__(self, call_list, call_results):
+ self.__call_list = call_list
+ self.__call_results = call_results
+
+ def call(self, function, *args):
+ self.__call_list.append((function, args))
+
+ return self.__call_results.get(function, 0)
+
+
+class DeopleteSourceTest(unittest.TestCase):
+ def setUp(self):
+ super(DeopleteSourceTest, self).setUp()
+
+ self.call_list = []
+ self.call_results = {'ale#completion#CanProvideCompletions': 1}
+ self.source = ale_module.Source('vim')
+ self.source.vim = VimMock(self.call_list, self.call_results)
+
+ def test_attributes(self):
+ """
+ Check all of the attributes we set.
+ """
+ attributes = dict(
+ (key, getattr(self.source, key))
+ for key in
+ dir(self.source)
+ if not key.startswith('__')
+ and key != 'vim'
+ and not hasattr(getattr(self.source, key), '__self__')
+ )
+
+ self.assertEqual(attributes, {
+ 'is_bytepos': True,
+ 'mark': '[L]',
+ 'min_pattern_length': 1,
+ 'name': 'ale',
+ 'rank': 100,
+ })
+
+ def test_completion_position(self):
+ self.call_results['ale#completion#GetCompletionPosition'] = 2
+
+ self.assertEqual(self.source.get_completion_position(), 2)
+ self.assertEqual(self.call_list, [
+ ('ale#completion#GetCompletionPosition', ()),
+ ])
+
+ def test_request_completion_results(self):
+ context = {'is_async': False}
+
+ self.assertEqual(self.source.gather_candidates(context), [])
+ self.assertEqual(context, {'is_async': True})
+ self.assertEqual(self.call_list, [
+ ('ale#completion#CanProvideCompletions', ()),
+ ('ale#completion#GetCompletions', ('deoplete',)),
+ ])
+
+ def test_request_completion_results_from_buffer_without_providers(self):
+ self.call_results['ale#completion#CanProvideCompletions'] = 0
+ context = {'is_async': False}
+
+ self.assertIsNone(self.source.gather_candidates(context), [])
+ self.assertEqual(context, {'is_async': False})
+ self.assertEqual(self.call_list, [
+ ('ale#completion#CanProvideCompletions', ()),
+ ])
+
+ def test_refresh_completion_results(self):
+ context = {'is_async': False}
+
+ self.assertEqual(self.source.gather_candidates(context), [])
+ self.assertEqual(context, {'is_async': True})
+ self.assertEqual(self.call_list, [
+ ('ale#completion#CanProvideCompletions', ()),
+ ('ale#completion#GetCompletions', ('deoplete',)),
+ ])
+
+ context = {'is_async': True, 'is_refresh': True}
+
+ self.assertEqual(self.source.gather_candidates(context), [])
+ self.assertEqual(context, {'is_async': True, 'is_refresh': True})
+ self.assertEqual(self.call_list, [
+ ('ale#completion#CanProvideCompletions', ()),
+ ('ale#completion#GetCompletions', ('deoplete',)),
+ ('ale#completion#CanProvideCompletions', ()),
+ ('ale#completion#GetCompletions', ('deoplete',)),
+ ])
+
+ def test_poll_no_result(self):
+ context = {'is_async': True}
+ self.call_results['ale#completion#GetCompletionResult'] = None
+
+ self.assertEqual(self.source.gather_candidates(context), [])
+ self.assertEqual(context, {'is_async': True})
+ self.assertEqual(self.call_list, [
+ ('ale#completion#CanProvideCompletions', ()),
+ ('ale#completion#GetCompletionResult', ()),
+ ])
+
+ def test_poll_empty_result_ready(self):
+ context = {'is_async': True}
+ self.call_results['ale#completion#GetCompletionResult'] = []
+
+ self.assertEqual(self.source.gather_candidates(context), [])
+ self.assertEqual(context, {'is_async': False})
+ self.assertEqual(self.call_list, [
+ ('ale#completion#CanProvideCompletions', ()),
+ ('ale#completion#GetCompletionResult', ()),
+ ])
+
+ def test_poll_non_empty_result_ready(self):
+ context = {'is_async': True}
+ self.call_results['ale#completion#GetCompletionResult'] = [
+ {
+ 'word': 'foobar',
+ 'kind': 'v',
+ 'icase': 1,
+ 'menu': '',
+ 'info': '',
+ },
+ ]
+
+ self.assertEqual(self.source.gather_candidates(context), [
+ {
+ 'word': 'foobar',
+ 'kind': 'v',
+ 'icase': 1,
+ 'menu': '',
+ 'info': '',
+ },
+ ])
+ self.assertEqual(context, {'is_async': False})
+ self.assertEqual(self.call_list, [
+ ('ale#completion#CanProvideCompletions', ()),
+ ('ale#completion#GetCompletionResult', ()),
+ ])
diff --git a/test/script/custom-checks b/test/script/custom-checks
index d4027fec..20dbfb80 100755
--- a/test/script/custom-checks
+++ b/test/script/custom-checks
@@ -67,4 +67,14 @@ echo
test/script/check-toc || exit_code=$?
+echo '========================================'
+echo 'Check Python code'
+echo '========================================'
+echo
+
+docker run --rm -v "$PWD:/testplugin" "$DOCKER_RUN_IMAGE" \
+ python -W ignore -m unittest discover /testplugin/test/python \
+ || exit_code=$?
+echo
+
exit $exit_code