From c50c68fef179d9306f1a3432f48985bf20555e38 Mon Sep 17 00:00:00 2001 From: Jonathan Abrahams Date: Tue, 27 Mar 2018 14:30:46 -0400 Subject: SERVER-23312 Python linting - Lint using pylint, pydocstyle & mypy --- buildscripts/resmokelib/testing/hooks/interface.py | 53 +++++++++------------- 1 file changed, 21 insertions(+), 32 deletions(-) (limited to 'buildscripts/resmokelib/testing/hooks/interface.py') diff --git a/buildscripts/resmokelib/testing/hooks/interface.py b/buildscripts/resmokelib/testing/hooks/interface.py index 877b2cc565f..8e938355001 100644 --- a/buildscripts/resmokelib/testing/hooks/interface.py +++ b/buildscripts/resmokelib/testing/hooks/interface.py @@ -1,6 +1,4 @@ -""" -Interface for customizing the behavior of a test fixture. -""" +"""Interface for customizing the behavior of a test fixture.""" from __future__ import absolute_import @@ -11,13 +9,11 @@ from ... import errors from ...logging import loggers from ...utils import registry -_HOOKS = {} +_HOOKS = {} # type: ignore def make_hook(class_name, *args, **kwargs): - """ - Factory function for creating Hook instances. - """ + """Provide factory function for creating Hook instances.""" if class_name not in _HOOKS: raise ValueError("Unknown hook class '%s'" % class_name) @@ -26,18 +22,14 @@ def make_hook(class_name, *args, **kwargs): class Hook(object): - """ - The common interface all Hooks will inherit from. - """ + """Common interface all Hooks will inherit from.""" - __metaclass__ = registry.make_registry_metaclass(_HOOKS) + __metaclass__ = registry.make_registry_metaclass(_HOOKS) # type: ignore REGISTERED_NAME = registry.LEAVE_UNREGISTERED def __init__(self, hook_logger, fixture, description): - """ - Initializes the Hook with the specified fixture. - """ + """Initialize the Hook with the specified fixture.""" if not isinstance(hook_logger, loggers.HookLogger): raise TypeError("logger must be a HookLogger instance") @@ -47,42 +39,38 @@ class Hook(object): self.description = description def before_suite(self, test_report): - """ - The test runner calls this exactly once before they start - running the suite. - """ + """Test runner calls this exactly once before they start running the suite.""" pass def after_suite(self, test_report): - """ - The test runner calls this exactly once after all tests have - finished executing. Be sure to reset the behavior back to its - original state so that it can be run again. + """Invoke by test runner calls this exactly once after all tests have finished executing. + + Be sure to reset the behavior back to its original state so that it can be run again. """ pass def before_test(self, test, test_report): - """ - Each test will call this before it executes. - """ + """Each test will call this before it executes.""" pass def after_test(self, test, test_report): - """ - Each test will call this after it executes. - """ + """Each test will call this after it executes.""" pass class DynamicTestCase(testcase.TestCase): # pylint: disable=abstract-method - def __init__(self, logger, test_name, description, base_test_name, hook): + """DynamicTestCase class.""" + + def __init__( # pylint: disable=too-many-arguments + self, logger, test_name, description, base_test_name, hook): + """Initialize DynamicTestCase.""" testcase.TestCase.__init__(self, logger, "Hook", test_name) self.description = description self._hook = hook self._base_test_name = base_test_name def run_dynamic_test(self, test_report): - """Helper method to run a dynamic test and update the test report.""" + """Provide helper method to run a dynamic test and update the test report.""" test_report.startTest(self, dynamic=True) try: self.run_test() @@ -102,11 +90,12 @@ class DynamicTestCase(testcase.TestCase): # pylint: disable=abstract-method test_report.stopTest(self) def as_command(self): + """Provide base method.""" return "(dynamic test case)" @classmethod def create_before_test(cls, logger, base_test, hook, *args, **kwargs): - """Creates a hook dynamic test to be run before an existing test.""" + """Create a hook dynamic test to be run before an existing test.""" base_test_name = base_test.short_name() test_name = cls._make_test_name(base_test_name, hook) description = "{} before running '{}'".format(hook.description, base_test_name) @@ -114,7 +103,7 @@ class DynamicTestCase(testcase.TestCase): # pylint: disable=abstract-method @classmethod def create_after_test(cls, logger, base_test, hook, *args, **kwargs): - """Creates a hook dynamic test to be run after an existing test.""" + """Create a hook dynamic test to be run after an existing test.""" base_test_name = base_test.short_name() test_name = cls._make_test_name(base_test_name, hook) description = "{} after running '{}'".format(hook.description, base_test_name) -- cgit v1.2.1