From bc79ae4890fe618ff7888f8f27dd82e9fd53da22 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Tue, 3 Jun 2014 20:12:41 -0700 Subject: [PATCH] Fix hacking docstring warnings Fix "H404 multi line docstring should start with a summary" hacking warnings Change-Id: I76bf4f0504569b4ea6adbdb555d8921562e705bf --- jenkins/__init__.py | 121 ++++++++++++++++++------------------------ tests/test_jenkins.py | 102 ----------------------------------- 2 files changed, 52 insertions(+), 171 deletions(-) diff --git a/jenkins/__init__.py b/jenkins/__init__.py index 3029472..7c8235d 100644 --- a/jenkins/__init__.py +++ b/jenkins/__init__.py @@ -121,16 +121,14 @@ RECONFIG_XML = ''' class JenkinsException(Exception): - ''' - General exception type for jenkins-API-related failures. - ''' + '''General exception type for jenkins-API-related failures.''' pass def auth_headers(username, password): - ''' - Simple implementation of HTTP Basic Authentication. Returns the - 'Authentication' header value. + '''Simple implementation of HTTP Basic Authentication. + + Returns the 'Authentication' header value. ''' auth = '%s:%s' % (username, password) if isinstance(auth, six.text_type): @@ -141,8 +139,7 @@ def auth_headers(username, password): class Jenkins(object): def __init__(self, url, username=None, password=None): - ''' - Create handle to Jenkins instance. + '''Create handle to Jenkins instance. All methods will raise :class:`JenkinsException` on failure. @@ -174,8 +171,7 @@ class Jenkins(object): req.add_header(self.crumb['crumbRequestField'], self.crumb['crumb']) def get_job_info(self, name): - ''' - Get job information dictionary. + '''Get job information dictionary. :param name: Job name, ``str`` :returns: dictionary of job information @@ -194,10 +190,11 @@ class Jenkins(object): "Could not parse JSON info for job[%s]" % name) def get_job_name(self, name): - ''' - Return the name of a job using the API. That is roughly an identity - method which can be used to quickly verify a job exist or is accessible - without causing too much stress on the server side. + '''Return the name of a job using the API. + + That is roughly an identity method which can be used to quickly verify + a job exist or is accessible without causing too much stress on the + server side. :param name: Job name, ``str`` :returns: Name of job or None @@ -215,17 +212,14 @@ class Jenkins(object): return None def debug_job_info(self, job_name): - ''' - Print out job info in more readable format - ''' + '''Print out job info in more readable format.''' for k, v in self.get_job_info(job_name).items(): print(k, v) def jenkins_open(self, req, add_crumb=True): - ''' + '''Utility routine for opening an HTTP request to a Jenkins server. - Utility routine for opening an HTTP request to a Jenkins server. This - should only be used to extends the :class:`Jenkins` API. + This should only be used to extends the :class:`Jenkins` API. ''' try: if self.auth: @@ -244,8 +238,7 @@ class Jenkins(object): # right now I'm getting 302 infinites on a successful delete def get_build_info(self, name, number): - ''' - Get build information dictionary. + '''Get build information dictionary. :param name: Job name, ``str`` :param name: Build number, ``int`` @@ -278,8 +271,7 @@ class Jenkins(object): ) def get_queue_info(self): - ''' - :returns: list of job dictionaries, ``[dict]`` + ''':returns: list of job dictionaries, ``[dict]`` Example:: >>> queue_info = j.get_queue_info() @@ -291,8 +283,7 @@ class Jenkins(object): ))['items'] def cancel_queue(self, number): - ''' - Cancel a queued build. + '''Cancel a queued build. :param number: Jenkins queue number for the build, ``int`` ''' @@ -304,9 +295,9 @@ class Jenkins(object): headers={'Referer': self.server})) def get_info(self): - """ - Get information on this Master. This information - includes job list and view information. + """Get information on this Master. + + This information includes job list and view information. :returns: dictionary of information about Master, ``dict`` @@ -333,17 +324,16 @@ class Jenkins(object): % self.server) def get_jobs(self): - """ - Get list of jobs running. Each job is a dictionary with - 'name', 'url', and 'color' keys. + """Get list of jobs running. + + Each job is a dictionary with 'name', 'url', and 'color' keys. :returns: list of jobs, ``[ { str: str} ]`` """ return self.get_info()['jobs'] def copy_job(self, from_name, to_name): - ''' - Copy a Jenkins job + '''Copy a Jenkins job :param from_name: Name of Jenkins job to copy from, ``str`` :param to_name: Name of Jenkins job to copy to, ``str`` @@ -355,8 +345,7 @@ class Jenkins(object): raise JenkinsException('create[%s] failed' % (to_name)) def rename_job(self, name, new_name): - ''' - Rename an existing Jenkins job + '''Rename an existing Jenkins job :param name: Name of Jenkins job to rename, ``str`` :param new_name: New Jenkins job name, ``str`` @@ -368,8 +357,7 @@ class Jenkins(object): raise JenkinsException('rename[%s] failed' % (new_name)) def delete_job(self, name): - ''' - Delete Jenkins job permanently. + '''Delete Jenkins job permanently. :param name: Name of Jenkins job, ``str`` ''' @@ -380,8 +368,7 @@ class Jenkins(object): raise JenkinsException('delete[%s] failed' % (name)) def enable_job(self, name): - ''' - Enable Jenkins job. + '''Enable Jenkins job. :param name: Name of Jenkins job, ``str`` ''' @@ -390,8 +377,9 @@ class Jenkins(object): self.server + ENABLE_JOB % locals(), '')) def disable_job(self, name): - ''' - Disable Jenkins job. To re-enable, call :meth:`Jenkins.enable_job`. + '''Disable Jenkins job. + + To re-enable, call :meth:`Jenkins.enable_job`. :param name: Name of Jenkins job, ``str`` ''' @@ -400,7 +388,8 @@ class Jenkins(object): self.server + DISABLE_JOB % locals(), '')) def job_exists(self, name): - ''' + '''Check whether a job exists + :param name: Name of Jenkins job, ``str`` :returns: ``True`` if Jenkins job exists ''' @@ -408,8 +397,7 @@ class Jenkins(object): return True def create_job(self, name, config_xml): - ''' - Create a new Jenkins job + '''Create a new Jenkins job :param name: Name of Jenkins job, ``str`` :param config_xml: config file text, ``str`` @@ -424,8 +412,7 @@ class Jenkins(object): raise JenkinsException('create[%s] failed' % (name)) def get_job_config(self, name): - ''' - Get configuration of existing Jenkins job. + '''Get configuration of existing Jenkins job. :param name: Name of Jenkins job, ``str`` :returns: job configuration (XML format) @@ -435,9 +422,9 @@ class Jenkins(object): return self.jenkins_open(request) def reconfig_job(self, name, config_xml): - ''' - Change configuration of existing Jenkins job. To create a new job, see - :meth:`Jenkins.create_job`. + '''Change configuration of existing Jenkins job. + + To create a new job, see :meth:`Jenkins.create_job`. :param name: Name of Jenkins job, ``str`` :param config_xml: New XML configuration, ``str`` @@ -448,9 +435,10 @@ class Jenkins(object): self.jenkins_open(Request(reconfig_url, config_xml, headers)) def build_job_url(self, name, parameters=None, token=None): - ''' - Get URL to trigger build job. Authenticated setups may require - configuring a token on the server side. + '''Get URL to trigger build job. + + Authenticated setups may require configuring a token on the server + side. :param parameters: parameters for job, or None., ``dict`` :param token: (optional) token for building job, ``str`` @@ -468,8 +456,7 @@ class Jenkins(object): return self.server + BUILD_JOB % locals() def build_job(self, name, parameters=None, token=None): - ''' - Trigger build job. + '''Trigger build job. :param name: name of job :param parameters: parameters for job, or ``None``, ``dict`` @@ -481,8 +468,7 @@ class Jenkins(object): self.build_job_url(name, parameters, token))) def stop_build(self, name, number): - ''' - Stop a running Jenkins build. + '''Stop a running Jenkins build. :param name: Name of Jenkins job, ``str`` :param number: Jenkins build number for the job, ``int`` @@ -490,8 +476,7 @@ class Jenkins(object): self.jenkins_open(Request(self.server + STOP_BUILD % locals())) def get_node_info(self, name): - ''' - Get node information dictionary + '''Get node information dictionary :param name: Node name, ``str`` :returns: Dictionary of node info, ``dict`` @@ -510,7 +495,8 @@ class Jenkins(object): % name) def node_exists(self, name): - ''' + '''Check whether a node exists + :param name: Name of Jenkins node, ``str`` :returns: ``True`` if Jenkins node exists ''' @@ -521,8 +507,7 @@ class Jenkins(object): return False def delete_node(self, name): - ''' - Delete Jenkins node permanently. + '''Delete Jenkins node permanently. :param name: Name of Jenkins node, ``str`` ''' @@ -533,8 +518,7 @@ class Jenkins(object): raise JenkinsException('delete[%s] failed' % (name)) def disable_node(self, name, msg=''): - ''' - Disable a node + '''Disable a node :param name: Jenkins node name, ``str`` :param msg: Offline message, ``str`` @@ -546,8 +530,7 @@ class Jenkins(object): self.server + TOGGLE_OFFLINE % locals())) def enable_node(self, name): - ''' - Enable a node + '''Enable a node :param name: Jenkins node name, ``str`` ''' @@ -561,7 +544,8 @@ class Jenkins(object): def create_node(self, name, numExecutors=2, nodeDescription=None, remoteFS='/var/lib/jenkins', labels=None, exclusive=False, launcher=LAUNCHER_COMMAND, launcher_params={}): - ''' + '''Create a node + :param name: name of node to create, ``str`` :param numExecutors: number of executors for node, ``int`` :param nodeDescription: Description of node, ``str`` @@ -609,8 +593,7 @@ class Jenkins(object): raise JenkinsException('create[%s] failed' % (name)) def get_build_console_output(self, name, number): - ''' - Get build console text. + '''Get build console text. :param name: Job name, ``str`` :param name: Build number, ``int`` diff --git a/tests/test_jenkins.py b/tests/test_jenkins.py index 8206372..afc920b 100644 --- a/tests/test_jenkins.py +++ b/tests/test_jenkins.py @@ -47,9 +47,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_job_config_encodes_job_name(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ j = jenkins.Jenkins('http://example.com/', 'test', 'test') j.get_job_config(u'Test Job') @@ -134,9 +131,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_create_job(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ config_xml = """ @@ -157,9 +151,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_create_job__already_exists(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ config_xml = """ @@ -182,9 +173,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_create_job__create_failed(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ config_xml = """ @@ -211,9 +199,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_reconfig_job(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ config_xml = """ @@ -232,9 +217,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_build_job(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = [ json.dumps({'name': 'TestJob'}), {'foo': 'bar'}, @@ -249,9 +231,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_build_job__with_token(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = [ json.dumps({'name': 'TestJob'}), {'foo': 'bar'}, @@ -266,9 +245,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_build_job__with_parameters_and_token(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = [ json.dumps({'name': 'TestJob'}), {'foo': 'bar'}, @@ -287,9 +263,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_build_job__job_doesnt_exist(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = [None] j = jenkins.Jenkins('http://example.com/', 'test', 'test') @@ -304,9 +277,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_stop_build(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ j = jenkins.Jenkins('http://example.com/', 'test', 'test') j.stop_build(u'TestJob', number=52) @@ -317,9 +287,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_build_console_output(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.return_value = "build console output..." j = jenkins.Jenkins('http://example.com/', 'test', 'test') @@ -332,9 +299,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_build_console_output__None(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.return_value = None j = jenkins.Jenkins('http://example.com/', 'test', 'test') @@ -346,9 +310,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_build_console_output__invalid_json(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.return_value = 'Invalid JSON' j = jenkins.Jenkins('http://example.com/', 'test', 'test') @@ -357,9 +318,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_build_console_output__HTTPError(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = jenkins.HTTPError( 'http://example.com/job/TestJob/52/consoleText', code=401, @@ -379,9 +337,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_build_info(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ build_info_to_return = { u'building': False, u'msg': u'test', @@ -400,9 +355,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_build_info__None(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.return_value = None j = jenkins.Jenkins('http://example.com/', 'test', 'test') @@ -414,9 +366,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_build_info__invalid_json(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.return_value = 'Invalid JSON' j = jenkins.Jenkins('http://example.com/', 'test', 'test') @@ -428,9 +377,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_build_info__HTTPError(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = jenkins.HTTPError( 'http://example.com/job/TestJob/api/json?depth=0', code=401, @@ -447,9 +393,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_job_info(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ job_info_to_return = { u'building': False, u'msg': u'test', @@ -468,9 +411,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_job_info__None(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.return_value = None j = jenkins.Jenkins('http://example.com/', 'test', 'test') @@ -485,9 +425,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_job_info__invalid_json(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.return_value = 'Invalid JSON' j = jenkins.Jenkins('http://example.com/', 'test', 'test') @@ -502,9 +439,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_job_info__HTTPError(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = jenkins.HTTPError( 'http://example.com/job/TestJob/api/json?depth=0', code=401, @@ -524,9 +458,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_debug_job_info(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ job_info_to_return = { u'building': False, u'msg': u'test', @@ -628,9 +559,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_copy_job(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = [ json.dumps({'name': 'TestJob'}), json.dumps({'name': 'TestJob_2'}), @@ -649,9 +577,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_copy_job__create_failed(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = [ json.dumps({'name': 'TestJob'}), None, @@ -672,9 +597,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_rename_job(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = [ json.dumps({'name': 'TestJob'}), json.dumps({'name': 'TestJob_2'}), @@ -692,9 +614,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_rename_job__rename_failed(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = [ json.dumps({'name': 'TestJob'}), None, @@ -714,9 +633,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_delete_job(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = [ json.dumps({'name': 'TestJob'}), None, @@ -734,9 +650,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_delete_job__delete_failed(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = [ json.dumps({'name': 'TestJob'}), json.dumps({'name': 'TestJob'}), @@ -756,9 +669,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_enable_job(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = [ json.dumps({'name': 'TestJob'}), json.dumps({'name': 'TestJob'}), @@ -775,9 +685,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_disable_job(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.side_effect = [ json.dumps({'name': 'TestJob'}), json.dumps({'name': 'TestJob'}), @@ -794,9 +701,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_job_name(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ job_name_to_return = {u'name': 'TestJob'} jenkins_mock.return_value = json.dumps(job_name_to_return) j = jenkins.Jenkins('http://example.com/', 'test', 'test') @@ -810,9 +714,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_job_name__None(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ jenkins_mock.return_value = None j = jenkins.Jenkins('http://example.com/', 'test', 'test') @@ -825,9 +726,6 @@ class JenkinsTest(unittest.TestCase): @patch.object(jenkins.Jenkins, 'jenkins_open') def test_get_job_name__unexpected_job_name(self, jenkins_mock): - """ - The job name parameter specified should be urlencoded properly. - """ job_name_to_return = {u'name': 'not the right name'} jenkins_mock.return_value = json.dumps(job_name_to_return) j = jenkins.Jenkins('http://example.com/', 'test', 'test')