Skip to content

Commit

Permalink
Merge pull request #9 from edaniszewski/async-visiter
Browse files Browse the repository at this point in the history
Async function visiter
  • Loading branch information
edaniszewski committed Mar 2, 2018
2 parents da1fbdc + c961a8f commit 187210a
Show file tree
Hide file tree
Showing 9 changed files with 374 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ matrix:
# env: TOXENV=py27
# - python: 2.7.6
# env: TOXENV=py27
- python: 3.3
env: TOXENV=py33
# - python: 3.3
# env: TOXENV=py33
- python: 3.4
env: TOXENV=py34
- python: 3.5
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def main(output="default"):
'''Entrypoint to the example script which prints out the
value in the 'output' variable.
'''
print output
print(output)


if __name__ == "__main__":
Expand Down Expand Up @@ -51,7 +51,7 @@ def main(output='default'):
"""Entrypoint to the example script which prints out the
value in the 'output' variable.
"""
print output
print(output)


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion pylint_quotes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from __future__ import absolute_import
from pylint_quotes import plugin, checker

__version__ = '0.1.7'
__version__ = '0.1.8'

register = plugin.register
8 changes: 8 additions & 0 deletions pylint_quotes/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ def visit_functiondef(self, node):
"""
self._process_for_docstring(node, 'function')

def visit_asyncfunctiondef(self, node):
"""Visit an asynchronous function and check for docstring quote consistency.
Args:
node: the async function node being visited.
"""
self._process_for_docstring(node, 'function')

def _process_for_docstring(self, node, node_type):
"""Check for docstring quote consistency.
Expand Down
333 changes: 333 additions & 0 deletions tests/test_async_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,333 @@
"""Tests for the string quote checker for function-level docstrings.
"""
import sys

import pytest

from pylint_quotes.checker import StringQuoteChecker
from pylint.testutils import Message, set_config

from utils import TRI_Q_DOUB, TRI_Q_SING, StringQuiteCheckerTestCase


@pytest.mark.skipif(sys.version_info < (3, 5), reason='requires python3.5 or python3.6')
class TestAsyncFunctionStringQuoteChecker(StringQuiteCheckerTestCase):
""" Test case for asynchronous function-level docstrings.
"""
CHECKER_CLASS = StringQuoteChecker

@set_config(docstring_quote='double')
def test_single_line_double_quote_docstring_with_cfg_double(self):

test_str = '''
async def fn(x): #@
"""Function level docstring on a single line."""
pass
'''

self.check_async_function(test_str)

@set_config(docstring_quote='single')
def test_single_line_double_quote_docstring_with_cfg_single(self):

test_str = '''
async def fn(x): #@
"""Function level docstring on a single line."""
pass
'''
msg = Message(msg_id='invalid-docstring-quote', line=3, args=(TRI_Q_DOUB, TRI_Q_SING))
self.check_async_function(test_str, msg)

@set_config(docstring_quote='double')
def test_single_line_single_quote_docstring_with_cfg_double(self):

test_str = """
async def fn(x): #@
'''Function level docstring on a single line.'''
pass
"""
msg = Message(msg_id='invalid-docstring-quote', line=3, args=(TRI_Q_SING, TRI_Q_DOUB))

self.check_async_function(test_str, msg)

@set_config(docstring_quote='single')
def test_single_line_single_quote_docstring_with_cfg_single(self):

test_str = """
async def fn(x): #@
'''Function level docstring on a single line.'''
pass
"""
self.check_async_function(test_str)

@set_config(docstring_quote='double')
def test_single_line_double_quote_docstring_with_cfg_double_multi_row_def(self):

test_str = '''
async def fn( #@
x
):
"""Function level docstring on a single line."""
pass
'''

self.check_async_function(test_str)

@set_config(docstring_quote='single')
def test_single_line_double_quote_docstring_with_cfg_single_multi_row_def(self):

test_str = '''
async def fn( #@
x
):
"""Function level docstring on a single line."""
'''
msg = Message(msg_id='invalid-docstring-quote', line=5, args=(TRI_Q_DOUB, TRI_Q_SING))

self.check_async_function(test_str, msg)

@set_config(docstring_quote='double')
def test_single_line_double_quote_docstring_with_cfg_double_multiple_def(self):

test_str = '''
async def fn1(x):
"""Function docstring"""
async def fn2(x): #@
"""Function level docstring on a single line."""
async def fn3(x):
"""Another function level docstring on single line."""
'''

self.check_async_function(test_str)

@set_config(docstring_quote='single')
def test_single_line_double_quote_docstring_with_cfg_single_multiple_def(self):

test_str = '''
async def fn1(x):
"""Function docstring"""
async def fn2(x): #@
"""Function level docstring on a single line."""
async def fn3(x):
"""Another function level docstring on single line."""
'''
msg = Message(msg_id='invalid-docstring-quote', line=6, args=(TRI_Q_DOUB, TRI_Q_SING))

self.check_async_function(test_str, msg)

@set_config(docstring_quote='double')
def test_multi_line_double_quote_docstring_with_cfg_double(self):

test_str = '''
async def fn(x): #@
"""Function level docstring
on multiple lines.
"""
'''

self.check_async_function(test_str)

@set_config(docstring_quote='single')
def test_multi_line_double_quote_docstring_with_cfg_single(self):

test_str = '''
async def fn(x): #@
"""Function level docstring
on multiple lines.
"""
'''
msg = Message(msg_id='invalid-docstring-quote', line=3, args=(TRI_Q_DOUB, TRI_Q_SING))

self.check_async_function(test_str, msg)

@set_config(docstring_quote='double')
def test_multi_line_single_quote_docstring_with_cfg_double(self):

test_str = """
async def fn(x): #@
'''Function level docstring
on multiple lines.
'''
"""
msg = Message(msg_id='invalid-docstring-quote', line=3, args=(TRI_Q_SING, TRI_Q_DOUB))

self.check_async_function(test_str, msg)

@set_config(docstring_quote='single')
def test_multi_line_single_quote_docstring_with_cfg_single(self):

test_str = """
async def fn(x): #@
'''Function level docstring
on multiple lines.
'''
"""

self.check_async_function(test_str)

@set_config(docstring_quote='double')
def test_multi_line_double_quote_docstring_with_cfg_double_multi_row_def(self):

test_str = '''
async def fn( #@
x
):
"""Function level docstring
on multiple lines.
"""
'''

self.check_async_function(test_str)

@set_config(docstring_quote='single')
def test_multi_line_double_quote_docstring_with_cfg_single_multi_row_def(self):

test_str = '''
async def fn( #@
x
):
"""Function level docstring
on multiple lines.
"""
'''
msg = Message(msg_id='invalid-docstring-quote', line=5, args=(TRI_Q_DOUB, TRI_Q_SING))

self.check_async_function(test_str, msg)

@set_config(docstring_quote='double')
def test_multi_line_double_quote_docstring_with_cfg_double_multiple_def(self):

test_str = '''
async def fn1(x):
"""Function docstring
on multiple lines.
"""
async def fn2(x): #@
"""Function level docstring
on multiple lines.
"""
async def fn3(x):
"""Another function level docstring
on multiple lines.
"""
'''

self.check_async_function(test_str)

@set_config(docstring_quote='single')
def test_multi_line_double_quote_docstring_with_cfg_single_multiple_def(self):

test_str = '''
async def fn1(x):
"""Function docstring
on multiple lines.
"""
async def fn2(x): #@
"""Function level docstring
on multiple lines.
"""
async def fn3(x):
"""Another function level docstring
on multiple lines.
"""
'''
msg = Message(msg_id='invalid-docstring-quote', line=8, args=(TRI_Q_DOUB, TRI_Q_SING))

self.check_async_function(test_str, msg)

@set_config(docstring_quote='double')
def test_single_line_double_quote_docstring_with_cfg_double_def_contents_01(self):

test_str = '''
async def fn(x): #@
"""Function level docstring on a single line."""
return 33
'''

self.check_async_function(test_str)

@set_config(docstring_quote='single')
def test_single_line_double_quote_docstring_with_cfg_single_def_contents_01(self):

test_str = '''
async def fn(x): #@
"""Function level docstring on a single line."""
return 33
'''
msg = Message(msg_id='invalid-docstring-quote', line=3, args=(TRI_Q_DOUB, TRI_Q_SING))

self.check_async_function(test_str, msg)

@set_config(docstring_quote='double')
def test_single_line_double_quote_docstring_with_cfg_double_def_contents_02(self):

test_str = '''
async def fn(x): #@
"""Function level docstring on a single line."""
# this is a dictionary
values = {1:2, 3:4}
return values.get(x)
'''

self.check_async_function(test_str)

@set_config(docstring_quote='single')
def test_single_line_double_quote_docstring_with_cfg_single_def_contents_02(self):

test_str = '''
async def fn(x): #@
"""Function level docstring on a single line."""
# this is a dictionary
values = {1:2, 3:4}
return values.get(x)
'''
msg = Message(msg_id='invalid-docstring-quote', line=3, args=(TRI_Q_DOUB, TRI_Q_SING))

self.check_async_function(test_str, msg)

@set_config(docstring_quote='double')
def test_single_line_double_quote_docstring_with_cfg_double_def_contents_03(self):

test_str = '''
async def fn(x): #@
"""Function level docstring on a single line."""
# define a function in a function
def local_fn(z):
"""Function within a function - inception"""
return z * z
return local_fn(x)
'''

self.check_async_function(test_str)

@set_config(docstring_quote='single')
def test_single_line_double_quote_docstring_with_cfg_single_def_contents_03(self):

test_str = '''
async def fn(x): #@
"""Function level docstring on a single line."""
# define a function in a function
def local_fn(z):
"""Function within a function - inception"""
return z * z
return local_fn(x)
'''
msg = Message(msg_id='invalid-docstring-quote', line=3, args=(TRI_Q_DOUB, TRI_Q_SING))

self.check_async_function(test_str, msg)
7 changes: 6 additions & 1 deletion tests/test_smart_quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
"""

from pylint_quotes.checker import StringQuoteChecker
from pylint.testutils import Message, set_config, tokenize_str
from pylint.testutils import Message, set_config

try:
from pylint.testutils import tokenize_str
except ImportError:
from pylint.testutils import _tokenize_str as tokenize_str

from utils import Q_DOUB, Q_SING, TRI_Q_SING, TRI_Q_DOUB, StringQuiteCheckerTestCase

Expand Down

0 comments on commit 187210a

Please sign in to comment.