Fix flake8 BLK100 and BLK999 issues

Resolves flake8 BLK related issues.

"BLK100 Black would make changes."
"BLK999 Unexpected exception: ..."

Change-Id: Ic6d4265e3d02b2f2a15ab851eaed98288c62730c
Signed-off-by: Thanh Ha <zxiiro@gmail.com>
This commit is contained in:
Thanh Ha 2020-08-31 10:54:19 -04:00
parent 15ee9899b8
commit 5a98ebb8bb
No known key found for this signature in database
GPG Key ID: 5783F720616E3180
15 changed files with 44 additions and 44 deletions

View File

@ -155,8 +155,9 @@ class JenkinsManager(object):
self.jenkins.delete_job(job_name)
def get_plugins_info(self):
""" Return a list of plugin_info dicts, one for each plugin on the
Jenkins instance.
"""Return a list of plugin_info dicts.
Returns one for each plugin on the Jenkins instance.
"""
try:
plugins_list = self.jenkins.get_plugins().values()

View File

@ -35,7 +35,8 @@ def __version__():
class JenkinsJobs(object):
""" This is the entry point class for the `jenkins-jobs` command line tool.
"""This is the entry point class for the `jenkins-jobs` command line tool.
While this class can be used programmatically by external users of the JJB
API, the main goal here is to abstract the `jenkins_jobs` tool in a way
that prevents test suites from caring overly much about various

View File

@ -29,8 +29,7 @@ def __version__():
def create_parser():
""" Create an ArgumentParser object usable by JenkinsJobs.
"""
"""Create an ArgumentParser object usable by JenkinsJobs."""
parser = argparse.ArgumentParser()
parser.add_argument(
"--conf",

View File

@ -50,8 +50,7 @@ class BaseSubCommand(object):
@staticmethod
def parse_option_recursive_exclude(parser):
"""Add '--recursive' and '--exclude' arguments to given parser.
"""
"""Add '--recursive' and '--exclude' arguments to given parser."""
parser.add_argument(
"-r",
"--recursive",

View File

@ -145,8 +145,7 @@ class JJBConfig(object):
config_fp.close()
def _init_defaults(self):
""" Initialize default configuration values using DEFAULT_CONF
"""
"""Initialize default configuration values using DEFAULT_CONF."""
config = configparser.ConfigParser()
# Load default config always
if PY2:
@ -156,9 +155,7 @@ class JJBConfig(object):
return config
def _read_config_file(self, config_filename):
""" Given path to configuration file, read it in as a ConfigParser
object and return that object.
"""
"""Return a ConfigParser object from a file input."""
if os.path.isfile(config_filename):
self.__config_file = config_filename # remember file we read from
logger.debug("Reading config from {0}".format(config_filename))
@ -354,7 +351,9 @@ class JJBConfig(object):
raise JenkinsJobsException("plugins_info must contain a list!")
def get_module_config(self, section, key, default=None):
""" Given a section name and a key value, return the value assigned to
"""Returns the value of a config in a config module.
Given a section name and a key value, return the value assigned to
the key in the JJB .ini file if it exists, otherwise emit a warning
indicating that the value is not set. Default value returned if no
value is set in the file will be a blank string.

View File

@ -27,8 +27,11 @@ logger = logging.getLogger(__name__)
def deep_format(obj, paramdict, allow_empty=False):
"""Apply the paramdict via str.format() to all string objects found within
the supplied obj. Lists and dicts are traversed recursively."""
"""Deep format configuration.
Apply the paramdict via str.format() to all string objects found within
the supplied obj. Lists and dicts are traversed recursively.
"""
# YAML serialisation was originally used to achieve this, but that places
# limitations on the values in paramdict - the post-format result must
# still be valid YAML (so substituting-in a string containing quotes, for

View File

@ -1171,8 +1171,7 @@ def gradle(registry, xml_parent, data):
def _groovy_common_scriptSource(data):
"""Helper function to generate the XML element common to groovy builders
"""
"""Helper function to generate the XML element common to groovy builders."""
scriptSource = XML.Element("scriptSource")
if "command" in data and "file" in data:
@ -4004,8 +4003,8 @@ def build_publish_docker_image(registry, xml_parent, data):
registry (default '')
:arg bool clean-images: Option to clean local images (default false)
:arg bool jenkins-job-delete: Attempt to remove images when jenkins
deletes the run (default false)
:arg str cloud: Cloud to use to build image (default '')
deletes the run (default false)
:arg str cloud: Cloud to use to build image (default '')
Minimal example:

View File

@ -26,12 +26,10 @@ import pkg_resources
def build_trends_publisher(plugin_name, xml_element, data):
"""Helper to create various trend publishers.
"""
"""Helper to create various trend publishers."""
def append_thresholds(element, data, only_totals):
"""Appends the status thresholds.
"""
"""Appends the status thresholds."""
for status in ["unstable", "failed"]:
status_data = data.get(status, {})

View File

@ -98,8 +98,9 @@ class HipChat(jenkins_jobs.modules.base.Base):
def _load_global_data(self):
"""Load data from the global config object.
This is done lazily to avoid looking up the '[hipchat]' section
unless actually required.
This is done lazily to avoid looking up the '[hipchat]' section
unless actually required.
"""
jjb_config = self.registry.jjb_config
if not self.authToken:

View File

@ -2141,8 +2141,7 @@ def checkstyle(registry, xml_parent, data):
"""
def convert_settings(lookup, data):
"""Helper to convert settings from one key to another
"""
"""Helper to convert settings from one key to another."""
for old_key in list(data.keys()):
if old_key in lookup:

View File

@ -51,8 +51,7 @@ def gerrit_handle_legacy_configuration(data):
hyphenizer = re.compile("[A-Z]")
def hyphenize(attr):
"""Convert strings like triggerOn to trigger-on.
"""
"""Convert strings like triggerOn to trigger-on."""
return hyphenizer.sub(lambda x: "-%s" % x.group(0).lower(), attr)
def convert_dict(d, old_keys):

View File

@ -88,9 +88,10 @@ class ModuleRegistry(object):
return plugins_info_dict
def get_plugin_info(self, plugin_name):
""" This method is intended to provide information about plugins within
a given module's implementation of Base.gen_xml. The return value is a
dictionary with data obtained directly from a running Jenkins instance.
"""Provide information about plugins within a module's impl of Base.gen_xml.
The return value is a dictionary with data obtained directly from a
running Jenkins instance.
This allows module authors to differentiate generated XML output based
on information such as specific plugin versions.

View File

@ -110,8 +110,9 @@ class XmlGenerator(object):
class XmlJobGenerator(XmlGenerator):
""" This class is responsible for generating Jenkins Configuration XML from
a compatible intermediate representation of Jenkins Jobs.
"""Class for generating Jenkins Configuration XML.
Generates XML from a compatible intermediate representation of Jenkins Jobs.
"""
entry_point_group = "jenkins_jobs.projects"
@ -120,8 +121,9 @@ class XmlJobGenerator(XmlGenerator):
class XmlViewGenerator(XmlGenerator):
""" This class is responsible for generating Jenkins Configuration XML from
a compatible intermediate representation of Jenkins Views.
"""Class for generating Jenkins Configuration XML.
Generates XML from a compatible intermediate representation of Jenkins Views.
"""
entry_point_group = "jenkins_jobs.views"

View File

@ -243,7 +243,9 @@ class TestTests(CmdTestsBase):
class TestJenkinsGetPluginInfoError(CmdTestsBase):
""" This test class is used for testing the 'test' subcommand when we want
"""Test without mocking get_plugins_info.
This test class is used for testing the 'test' subcommand when we want
to validate its behavior without mocking
jenkins_jobs.builder.JenkinsManager.get_plugins_info
"""
@ -354,7 +356,7 @@ class MatchesDir(object):
for root, _, files in os.walk(directory):
return files
def __str__(self,):
def __str__(self, directory):
return "MatchesDir({0})".format(self.__dirname)
def match(self, other_directory):

View File

@ -79,8 +79,7 @@ class UpdateTests(CmdTestsBase):
jenkins_get_all_jobs,
jenkins_job_exists,
):
"""
Test update behaviour with --delete-old option
"""Test update behaviour with --delete-old option.
* mock out a call to jenkins.Jenkins.get_jobs() to return a known list
of job names.
@ -117,11 +116,9 @@ class UpdateTests(CmdTestsBase):
self.assertEqual(jenkins_delete_job.call_count, len(calls))
def test_update_timeout_not_set(self):
"""Validate update timeout behavior when timeout not explicitly configured.
"""
"""Validate update timeout behavior when timeout not explicitly configured."""
self.skipTest("TODO: Develop actual update timeout test approach.")
def test_update_timeout_set(self):
"""Validate update timeout behavior when timeout is explicitly configured.
"""
"""Validate update timeout behavior when timeout is explicitly configured."""
self.skipTest("TODO: Develop actual update timeout test approach.")