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:
parent
15ee9899b8
commit
5a98ebb8bb
@ -155,8 +155,9 @@ class JenkinsManager(object):
|
|||||||
self.jenkins.delete_job(job_name)
|
self.jenkins.delete_job(job_name)
|
||||||
|
|
||||||
def get_plugins_info(self):
|
def get_plugins_info(self):
|
||||||
""" Return a list of plugin_info dicts, one for each plugin on the
|
"""Return a list of plugin_info dicts.
|
||||||
Jenkins instance.
|
|
||||||
|
Returns one for each plugin on the Jenkins instance.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
plugins_list = self.jenkins.get_plugins().values()
|
plugins_list = self.jenkins.get_plugins().values()
|
||||||
|
@ -35,7 +35,8 @@ def __version__():
|
|||||||
|
|
||||||
|
|
||||||
class JenkinsJobs(object):
|
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
|
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
|
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
|
that prevents test suites from caring overly much about various
|
||||||
|
@ -29,8 +29,7 @@ def __version__():
|
|||||||
|
|
||||||
|
|
||||||
def create_parser():
|
def create_parser():
|
||||||
""" Create an ArgumentParser object usable by JenkinsJobs.
|
"""Create an ArgumentParser object usable by JenkinsJobs."""
|
||||||
"""
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--conf",
|
"--conf",
|
||||||
|
@ -50,8 +50,7 @@ class BaseSubCommand(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_option_recursive_exclude(parser):
|
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(
|
parser.add_argument(
|
||||||
"-r",
|
"-r",
|
||||||
"--recursive",
|
"--recursive",
|
||||||
|
@ -145,8 +145,7 @@ class JJBConfig(object):
|
|||||||
config_fp.close()
|
config_fp.close()
|
||||||
|
|
||||||
def _init_defaults(self):
|
def _init_defaults(self):
|
||||||
""" Initialize default configuration values using DEFAULT_CONF
|
"""Initialize default configuration values using DEFAULT_CONF."""
|
||||||
"""
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
# Load default config always
|
# Load default config always
|
||||||
if PY2:
|
if PY2:
|
||||||
@ -156,9 +155,7 @@ class JJBConfig(object):
|
|||||||
return config
|
return config
|
||||||
|
|
||||||
def _read_config_file(self, config_filename):
|
def _read_config_file(self, config_filename):
|
||||||
""" Given path to configuration file, read it in as a ConfigParser
|
"""Return a ConfigParser object from a file input."""
|
||||||
object and return that object.
|
|
||||||
"""
|
|
||||||
if os.path.isfile(config_filename):
|
if os.path.isfile(config_filename):
|
||||||
self.__config_file = config_filename # remember file we read from
|
self.__config_file = config_filename # remember file we read from
|
||||||
logger.debug("Reading config from {0}".format(config_filename))
|
logger.debug("Reading config from {0}".format(config_filename))
|
||||||
@ -354,7 +351,9 @@ class JJBConfig(object):
|
|||||||
raise JenkinsJobsException("plugins_info must contain a list!")
|
raise JenkinsJobsException("plugins_info must contain a list!")
|
||||||
|
|
||||||
def get_module_config(self, section, key, default=None):
|
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
|
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
|
indicating that the value is not set. Default value returned if no
|
||||||
value is set in the file will be a blank string.
|
value is set in the file will be a blank string.
|
||||||
|
@ -27,8 +27,11 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def deep_format(obj, paramdict, allow_empty=False):
|
def deep_format(obj, paramdict, allow_empty=False):
|
||||||
"""Apply the paramdict via str.format() to all string objects found within
|
"""Deep format configuration.
|
||||||
the supplied obj. Lists and dicts are traversed recursively."""
|
|
||||||
|
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
|
# YAML serialisation was originally used to achieve this, but that places
|
||||||
# limitations on the values in paramdict - the post-format result must
|
# limitations on the values in paramdict - the post-format result must
|
||||||
# still be valid YAML (so substituting-in a string containing quotes, for
|
# still be valid YAML (so substituting-in a string containing quotes, for
|
||||||
|
@ -1171,8 +1171,7 @@ def gradle(registry, xml_parent, data):
|
|||||||
|
|
||||||
|
|
||||||
def _groovy_common_scriptSource(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")
|
scriptSource = XML.Element("scriptSource")
|
||||||
if "command" in data and "file" in data:
|
if "command" in data and "file" in data:
|
||||||
@ -4004,8 +4003,8 @@ def build_publish_docker_image(registry, xml_parent, data):
|
|||||||
registry (default '')
|
registry (default '')
|
||||||
:arg bool clean-images: Option to clean local images (default false)
|
:arg bool clean-images: Option to clean local images (default false)
|
||||||
:arg bool jenkins-job-delete: Attempt to remove images when jenkins
|
:arg bool jenkins-job-delete: Attempt to remove images when jenkins
|
||||||
deletes the run (default false)
|
deletes the run (default false)
|
||||||
:arg str cloud: Cloud to use to build image (default '')
|
:arg str cloud: Cloud to use to build image (default '')
|
||||||
|
|
||||||
Minimal example:
|
Minimal example:
|
||||||
|
|
||||||
|
@ -26,12 +26,10 @@ import pkg_resources
|
|||||||
|
|
||||||
|
|
||||||
def build_trends_publisher(plugin_name, xml_element, data):
|
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):
|
def append_thresholds(element, data, only_totals):
|
||||||
"""Appends the status thresholds.
|
"""Appends the status thresholds."""
|
||||||
"""
|
|
||||||
|
|
||||||
for status in ["unstable", "failed"]:
|
for status in ["unstable", "failed"]:
|
||||||
status_data = data.get(status, {})
|
status_data = data.get(status, {})
|
||||||
|
@ -98,8 +98,9 @@ class HipChat(jenkins_jobs.modules.base.Base):
|
|||||||
|
|
||||||
def _load_global_data(self):
|
def _load_global_data(self):
|
||||||
"""Load data from the global config object.
|
"""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
|
jjb_config = self.registry.jjb_config
|
||||||
if not self.authToken:
|
if not self.authToken:
|
||||||
|
@ -2141,8 +2141,7 @@ def checkstyle(registry, xml_parent, data):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def convert_settings(lookup, 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()):
|
for old_key in list(data.keys()):
|
||||||
if old_key in lookup:
|
if old_key in lookup:
|
||||||
|
@ -51,8 +51,7 @@ def gerrit_handle_legacy_configuration(data):
|
|||||||
hyphenizer = re.compile("[A-Z]")
|
hyphenizer = re.compile("[A-Z]")
|
||||||
|
|
||||||
def hyphenize(attr):
|
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)
|
return hyphenizer.sub(lambda x: "-%s" % x.group(0).lower(), attr)
|
||||||
|
|
||||||
def convert_dict(d, old_keys):
|
def convert_dict(d, old_keys):
|
||||||
|
@ -88,9 +88,10 @@ class ModuleRegistry(object):
|
|||||||
return plugins_info_dict
|
return plugins_info_dict
|
||||||
|
|
||||||
def get_plugin_info(self, plugin_name):
|
def get_plugin_info(self, plugin_name):
|
||||||
""" This method is intended to provide information about plugins within
|
"""Provide information about plugins within a module's impl of Base.gen_xml.
|
||||||
a given module's implementation of Base.gen_xml. The return value is a
|
|
||||||
dictionary with data obtained directly from a running Jenkins instance.
|
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
|
This allows module authors to differentiate generated XML output based
|
||||||
on information such as specific plugin versions.
|
on information such as specific plugin versions.
|
||||||
|
|
||||||
|
@ -110,8 +110,9 @@ class XmlGenerator(object):
|
|||||||
|
|
||||||
|
|
||||||
class XmlJobGenerator(XmlGenerator):
|
class XmlJobGenerator(XmlGenerator):
|
||||||
""" This class is responsible for generating Jenkins Configuration XML from
|
"""Class for generating Jenkins Configuration XML.
|
||||||
a compatible intermediate representation of Jenkins Jobs.
|
|
||||||
|
Generates XML from a compatible intermediate representation of Jenkins Jobs.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
entry_point_group = "jenkins_jobs.projects"
|
entry_point_group = "jenkins_jobs.projects"
|
||||||
@ -120,8 +121,9 @@ class XmlJobGenerator(XmlGenerator):
|
|||||||
|
|
||||||
|
|
||||||
class XmlViewGenerator(XmlGenerator):
|
class XmlViewGenerator(XmlGenerator):
|
||||||
""" This class is responsible for generating Jenkins Configuration XML from
|
"""Class for generating Jenkins Configuration XML.
|
||||||
a compatible intermediate representation of Jenkins Views.
|
|
||||||
|
Generates XML from a compatible intermediate representation of Jenkins Views.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
entry_point_group = "jenkins_jobs.views"
|
entry_point_group = "jenkins_jobs.views"
|
||||||
|
@ -243,7 +243,9 @@ class TestTests(CmdTestsBase):
|
|||||||
|
|
||||||
|
|
||||||
class TestJenkinsGetPluginInfoError(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
|
to validate its behavior without mocking
|
||||||
jenkins_jobs.builder.JenkinsManager.get_plugins_info
|
jenkins_jobs.builder.JenkinsManager.get_plugins_info
|
||||||
"""
|
"""
|
||||||
@ -354,7 +356,7 @@ class MatchesDir(object):
|
|||||||
for root, _, files in os.walk(directory):
|
for root, _, files in os.walk(directory):
|
||||||
return files
|
return files
|
||||||
|
|
||||||
def __str__(self,):
|
def __str__(self, directory):
|
||||||
return "MatchesDir({0})".format(self.__dirname)
|
return "MatchesDir({0})".format(self.__dirname)
|
||||||
|
|
||||||
def match(self, other_directory):
|
def match(self, other_directory):
|
||||||
|
@ -79,8 +79,7 @@ class UpdateTests(CmdTestsBase):
|
|||||||
jenkins_get_all_jobs,
|
jenkins_get_all_jobs,
|
||||||
jenkins_job_exists,
|
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
|
* mock out a call to jenkins.Jenkins.get_jobs() to return a known list
|
||||||
of job names.
|
of job names.
|
||||||
@ -117,11 +116,9 @@ class UpdateTests(CmdTestsBase):
|
|||||||
self.assertEqual(jenkins_delete_job.call_count, len(calls))
|
self.assertEqual(jenkins_delete_job.call_count, len(calls))
|
||||||
|
|
||||||
def test_update_timeout_not_set(self):
|
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.")
|
self.skipTest("TODO: Develop actual update timeout test approach.")
|
||||||
|
|
||||||
def test_update_timeout_set(self):
|
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.")
|
self.skipTest("TODO: Develop actual update timeout test approach.")
|
||||||
|
Loading…
Reference in New Issue
Block a user