Skip to content

Commit

Permalink
Made tests more robust to version change
Browse files Browse the repository at this point in the history
  • Loading branch information
galaunay committed Mar 23, 2020
1 parent 8649505 commit b69ae76
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 38 deletions.
7 changes: 4 additions & 3 deletions elpy/tests/support.py
Expand Up @@ -17,6 +17,7 @@
import sys
import tempfile
import unittest
import re

from elpy.tests import compat

Expand Down Expand Up @@ -808,9 +809,9 @@ def check_docstring(self, docstring):

def first_line(s):
return s[:s.index("\n")]

self.assertEqual(first_line(docstring),
self.JSON_LOADS_DOCSTRING)
match = re.match(self.JSON_LOADS_REGEX,
first_line(docstring))
self.assertIsNotNone(match)

def test_should_get_docstring(self):
source, offset = source_and_offset(
Expand Down
3 changes: 2 additions & 1 deletion elpy/tests/test_black.py
Expand Up @@ -49,7 +49,8 @@ def test_should_read_options_from_pyproject_toml(self):
testdata = [('x= 123\n', 'x = 123\n'),
('x=1; \ny=2 \n', 'x = 1\ny = 2\n'),
('x, y, z, a, b, c = 123, 124, 125, 126, 127, 128',
'x, y, z, a, b, c = (\n 123,\n 124,\n 125,'
'(\n x,\n y,\n z,\n a,\n b,\n c,\n)'
' = (\n 123,\n 124,\n 125,'
'\n 126,\n 127,\n 128,\n)\n')]
for src, expected in testdata:
self._assert_format(src, expected)
42 changes: 8 additions & 34 deletions elpy/tests/test_jedibackend.py
Expand Up @@ -5,6 +5,7 @@

import jedi
import mock
import re

from elpy import jedibackend
from elpy import rpc
Expand Down Expand Up @@ -54,43 +55,16 @@ class TestRPCGetDocstring(RPCGetDocstringTests,

def __init__(self, *args, **kwargs):
super(TestRPCGetDocstring, self).__init__(*args, **kwargs)
if sys.version_info >= (3, 6):
self.JSON_LOADS_DOCSTRING = (
'loads(s, *, encoding=None, cls=None, object_hook=None, '
'parse_float=None, parse_int=None, parse_constant=None, '
'object_pairs_hook=None, object_hook: '
'Optional[Callable[[Dict[str, Any]], Any]]=..., '
'parse_float: Optional[Callable[[str], Any]]=..., '
'parse_int: Optional[Callable[[str], Any]]=..., '
'parse_constant: Optional[Callable[[str], Any]]=..., '
'strict: bool=..., '
'object_pairs_hook: Optional[Callable[[List[Tuple[str, Any]]], '
'Any]]=...)'
)
elif sys.version_info >= (3, 5):
self.JSON_LOADS_DOCSTRING = (
'loads(s, encoding=None, cls=None, object_hook=None, '
'parse_float=None, parse_int=None, parse_constant=None, '
'object_pairs_hook=None, *, object_hook: '
'Optional[Callable[[Dict[str, Any]], Any]]=..., '
'parse_float: Optional[Callable[[str], Any]]=..., '
'parse_int: Optional[Callable[[str], Any]]=..., '
'parse_constant: Optional[Callable[[str], Any]]=..., '
'strict: bool=..., '
'object_pairs_hook: Optional[Callable[[List[Tuple[str, Any]]], '
'Any]]=...)'
)
else:
self.JSON_LOADS_DOCSTRING = (
'loads(s, encoding=None, cls=None, object_hook=None, '
'parse_float=None, parse_int=None, parse_constant=None, '
'object_pairs_hook=None, **kw)'
self.JSON_LOADS_REGEX = (
r'loads\(s.*, encoding.*, cls.*, object_hook.*, parse_float.*, '
r'parse_int.*, .*\)'
)

def check_docstring(self, docstring):
lines = docstring.splitlines()
self.assertEqual(lines[0], 'Documentation for json.loads:')
self.assertEqual(lines[2], self.JSON_LOADS_DOCSTRING)
match = re.match(self.JSON_LOADS_REGEX, lines[2])
self.assertIsNotNone(match)

@mock.patch("elpy.jedibackend.run_with_debug")
def test_should_not_return_empty_docstring(self, run_with_debug):
Expand Down Expand Up @@ -206,7 +180,7 @@ class TestRPCGetCalltip(RPCGetCalltipTests,
'params': ['group: None=...',
'target: Optional[Callable[..., Any]]=...',
'name: Optional[str]=...',
'args: Iterable=...',
'args: Iterable[Any]=...',
'kwargs: Mapping[str, Any]=...',
'daemon: Optional[bool]=...']}

Expand All @@ -216,7 +190,7 @@ class TestRPCGetCalltip(RPCGetCalltipTests,
'params': [u'group: None=...',
u'target: Optional[Callable[..., Any]]=...',
u'name: Optional[str]=...',
u'args: Iterable=...',
u'args: Iterable[Any]=...',
u'kwargs: Mapping[str, Any]=...']}

def test_should_not_fail_with_get_subscope_by_name(self):
Expand Down

0 comments on commit b69ae76

Please sign in to comment.