Skip to content

Commit

Permalink
Refactor Pylint test suite (#8939)
Browse files Browse the repository at this point in the history
* add placeholders

* add new placeholder comments

* Refactor class TestClientMethodsHaveTracingDecorators

Refactored class to use test file by the same name

* Refactor class TestClientsDoNotUseStaticMethods

Added test file by same name

* Refactor class TestClientHasApprovedMethodNamePrefix

Refactor to use file by same name

* Refactor class TestClientConstructorTakesCorrectParameters

Add file by same name

* Refactor class TestClientMethodsUseKwargsWithMultipleParameters

Added test file by same name

* Refactor class TestClientMethodsHaveTypeAnnotations

Added test file by same name

* Refactor class TestClientHasKwargsInPoliciesForCreateConfigurationMethod

Added test file by same name

* Refactor class TestClientUsesCorrectNamingConventions

Added test file by same name

* Refactor class TestClientMethodsHaveKwargsParameter

Added test file by same name

* Refactor class TestAsyncClientCorrectNaming

Added test file by same name

* Refactor class TestSpecifyParameterNamesInCall

Added test file by same name

* Refactor class class TestClientListMethodsUseCorePaging

Added test file by same name

* Refactor class TestClientLROMethodsUseCorePolling

Added test file by same name

* Refactor class TestClientLROMethodsUseCorrectNaming

Added test file by same name

* Refactor class TestClientConstructorDoesNotHaveConnectionStringParam

Added test file of same name

* Refactor class TestClientMethodNamesDoNotUseDoubleUnderscorePrefix

Added test file of same name

* Refactor class TestCheckDocstringAdmonitionNewline

Added test class by same name

* Refactor class TestCheckEnum

Added test file of same name

* Refactor class TestCheckAPIVersion

Added test file of same name

* Refactor class TestCheckNonCoreNetworkImport

Added test file by same name

* Refactor class TestCheckNonAbstractTransportImport

Added test file by same name

* Refactor class TestRaiseWithTraceback

Added test file by same name

* Refactor class TestTypePropertyNameLength

Added test file of same name

* Refactor class TestDeleteOperationReturnType

Added test file by same name

* Refactor class TestDocstringParameters

Added test file

* Refactor class TestDoNotImportLegacySix

Added file by same name

* Refactor class TestCheckNoLegacyAzureCoreHttpResponseImport

Added test file by same name

* Refactor class TestCheckNoTypingUnderTypeChecking

Added test file of same name

* Refactor class TestPackageNameDoesNotUseUnderscoreOrPeriod

Added test file by same name

* Refactor class TestServiceClientUsesNameWithClientSuffix

Added test file by same name

* Refactor class TestCheckNamingMismatchGeneratedCode

Added test file by same name

* Refactor class TestCheckDoNotUseLegacyTyping

Added test file by same name

* Update test_pylint_custom_plugins.py

* Refactor class TestDoNotLogErrorsEndUpRaising

Added test file by same name

* Refactor class TestDoNotImportAsyncio

Added test file by same name. Fixed any merge issues.

---------

Co-authored-by: Joshua Bishop <[email protected]>
  • Loading branch information
JessicaBell00 and MJoshuaB authored Sep 19, 2024
1 parent 54d6470 commit d7456f0
Show file tree
Hide file tree
Showing 36 changed files with 3,122 additions and 2,880 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,6 @@ def visit_importfrom(self, node):
)



class DoNotLogErrorsEndUpRaising(BaseChecker):

"""Rule to check that errors that get raised aren't logged"""
Expand Down Expand Up @@ -2764,7 +2763,6 @@ def check_for_logging(self, node):
)



class NoImportTypingFromTypeCheck(BaseChecker):

"""Rule to check that we aren't importing typing under TYPE_CHECKING."""
Expand Down Expand Up @@ -2830,6 +2828,7 @@ def visit_functiondef(self, node):
confidence=None,
)


class DoNotImportAsyncio(BaseChecker):

"""Rule to check that libraries do not import the asyncio package directly."""
Expand All @@ -2853,7 +2852,7 @@ def visit_importfrom(self, node):
node=node,
confidence=None,
)

def visit_import(self, node):
"""Check that we aren't importing asyncio."""
for name, _ in node.names:
Expand All @@ -2865,6 +2864,12 @@ def visit_import(self, node):
)


# [Pylint] custom linter check for invalid use of @overload #3229
# [Pylint] Custom Linter check for Exception Logging #3227
# [Pylint] Address Commented out Pylint Custom Plugin Checkers #3228
# [Pylint] Add a check for connection_verify hardcoded settings #35355
# [Pylint] Refactor test suite for custom pylint checkers to use files instead of docstrings #3233
# [Pylint] Investigate pylint rule around missing dependency #3231


# if a linter is registered in this function then it will be checked with pylint
Expand Down Expand Up @@ -2901,14 +2906,19 @@ def register(linter):
linter.register_checker(NoLegacyAzureCoreHttpResponseImport(linter))
linter.register_checker(NoImportTypingFromTypeCheck(linter))
linter.register_checker(DoNotUseLegacyTyping(linter))
linter.register_checker(DoNotLogErrorsEndUpRaising(linter))

# [Pylint] custom linter check for invalid use of @overload #3229
# [Pylint] Custom Linter check for Exception Logging #3227
# [Pylint] Address Commented out Pylint Custom Plugin Checkers #3228
# [Pylint] Add a check for connection_verify hardcoded settings #35355
# [Pylint] Refactor test suite for custom pylint checkers to use files instead of docstrings #3233
# [Pylint] Investigate pylint rule around missing dependency #3231

# disabled by default, use pylint --enable=check-docstrings if you want to use it
linter.register_checker(CheckDocstringParameters(linter))


linter.register_checker(DoNotLogErrorsEndUpRaising(linter))

# Rules are disabled until false positive rate improved
# linter.register_checker(CheckForPolicyUse(linter))
# linter.register_checker(ClientHasApprovedMethodNamePrefix(linter))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class _AsyncBaseSomeClient(): # @
# test_ignores_private_client
def create_configuration(self):
pass


# test_ignores_correct_client
class SomeClient(): # @
def create_configuration(self): # @
pass


# test_ignores_async_base_named_client
class AsyncSomeClientBase(): # @
def get_thing(self, **kwargs):
pass


# test_finds_incorrectly_named_client
class AsyncSomeClient(): # @
def get_thing(self, **kwargs):
pass


# test_ignores_non_client
class SomethingElse(): # @
def create_configuration(self): # @
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# test_api_version_violation
class SomeClient(object):
"""
:param str something: something
"""

def __init__(self, something, **kwargs):
pass


# test_api_version_acceptable
class Some1Client(): # @
"""
:param str something: something
:keyword str api_version: api_version
"""

def __init__(self, something, **kwargs):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# test_disallowed_typing
def function(x): # @
# type: (str) -> str
pass


# test_allowed_typing
def function(x: str) -> str: # @
pass


# test_arbitrary_comments
def function(x): # @
# This is a comment
pass

Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# test_ignores_correct_admonition_statement_in_function
def function_foo(x, y, z):
"""docstring
.. admonition:: Example:
.. literalinclude:: ../samples/sample_detect_language.py
"""
pass


# test_ignores_correct_admonition_statement_in_function_with_comments
def function_foo1(x, y, z):
"""docstring
.. admonition:: Example:
This is Example content.
Should support multi-line.
Can also include file:
.. literalinclude:: ../samples/sample_detect_language.py
"""


# test_bad_admonition_statement_in_function
def function_foo2(x, y, z):
"""docstring
.. admonition:: Example:
.. literalinclude:: ../samples/sample_detect_language.py
"""


# test_bad_admonition_statement_in_function_with_comments
def function_foo3(x, y, z):
"""docstring
.. admonition:: Example:
This is Example content.
Should support multi-line.
Can also include file:
.. literalinclude:: ../samples/sample_detect_language.py
"""


# test_ignores_correct_admonition_statement_in_function_async
async def function_foo4(x, y, z):
"""docstring
.. admonition:: Example:
.. literalinclude:: ../samples/sample_detect_language.py
"""


# test_ignores_correct_admonition_statement_in_function_with_comments_async
async def function_foo5(x, y, z):
"""docstring
.. admonition:: Example:
This is Example content.
Should support multi-line.
Can also include file:
.. literalinclude:: ../samples/sample_detect_language.py
"""


# test_bad_admonition_statement_in_function_async
async def function_foo6(x, y, z):
"""docstring
.. admonition:: Example:
.. literalinclude:: ../samples/sample_detect_language.py
"""


# test_bad_admonition_statement_in_function_with_comments_async
async def function_foo7(x, y, z):
"""docstring
.. admonition:: Example:
This is Example content.
Should support multi-line.
Can also include file:
.. literalinclude:: ../samples/sample_detect_language.py
"""


# test_ignores_correct_admonition_statement_in_class
class SomeClient(object):
"""docstring
.. admonition:: Example:
.. literalinclude:: ../samples/sample_detect_language.py
"""

def __init__(self):
pass


# test_ignores_correct_admonition_statement_in_class_with_comments
class Some1Client(): # @
"""docstring
.. admonition:: Example:
This is Example content.
Should support multi-line.
Can also include file:
.. literalinclude:: ../samples/sample_detect_language.py
"""

def __init__(self):
pass


# test_bad_admonition_statement_in_class
class Some2Client(): # @
"""docstring
.. admonition:: Example:
.. literalinclude:: ../samples/sample_detect_language.py
"""

def __init__(self):
pass


# test_bad_admonition_statement_in_class_with_comments
class Some3Client(): # @
"""docstring
.. admonition:: Example:
This is Example content.
Should support multi-line.
Can also include file:
.. literalinclude:: ../samples/sample_detect_language.py
"""

def __init__(self):
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from enum import Enum
from six import with_metaclass
from azure.core import CaseInsensitiveEnumMeta


# test_ignore_normal_class
class SomeClient(object):
my_list = []


# test_enum_capitalized_violation_python_two
class MyBadEnum(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)):
One = "one"


# test_enum_capitalized_violation_python_three
class MyBadEnum2(str, Enum, metaclass=CaseInsensitiveEnumMeta):
One = "one"


# test_inheriting_case_insensitive_violation
class MyGoodEnum(str, Enum):
ONE = "one"


# test_acceptable_python_three
class MyGoodEnum2(str, Enum, metaclass=CaseInsensitiveEnumMeta):
ONE = "one"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# test_import_naming_mismatch_violation
import Something
import Something2 as SomethingTwo

__all__ = (
"Something",
"SomethingTwo",
)

# test_import_from_naming_mismatch_violation
from Something2 import SomethingToo as SomethingTwo

# test_naming_mismatch_acceptable
__all__ = (
"Something",
"Something2",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from azure.core.polling import LROPoller
from azure.core.tracing.decorator import distributed_trace


# test_ignores_private_methods
class SomeClient(): # @
def _begin_thing(self): # @
pass


# test_ignores_non_client_methods
class SomethingElse(): # @
def begin_things(self): # @
pass


# test_ignores_methods_return_LROPoller
class Some1Client(): # @
def begin_thing(self): # @
return LROPoller()

@distributed_trace
def begin_thing2(self): # @
return LROPoller(self._client, raw_result, get_long_running_output, polling_method)


# test_finds_method_returning_something_else
class Some2Client(): # @
def begin_thing(self): # @
return list()

def begin_thing2(self): # @
return {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from azure.core.polling import LROPoller
from azure.core.tracing.decorator import distributed_trace


class SomeClient(): # @
def _do_thing(self):
return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # @


# test_ignores_non_client_methods
class SomethingElse(): # @
def begin_things(self):
return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # @


# test_ignores_methods_return_LROPoller_and_correctly_named
class Some1Client(): # @
def begin_thing(self):
return LROPoller() # @

@distributed_trace
def begin_thing2(self):
return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # @


# test_finds_incorrectly_named_method_returning_LROPoller
class Some2Client(): # @
def poller_thing(self): # @
return LROPoller() # @

@distributed_trace
def start_thing2(self): # @
return LROPoller(self._client, raw_result, get_long_running_output, polling_method) # @

Loading

0 comments on commit d7456f0

Please sign in to comment.