From 2a950078cdae44240f6cb210d3e12fc5d9714a74 Mon Sep 17 00:00:00 2001 From: "biao716.wang" Date: Wed, 15 Mar 2023 19:35:54 +0900 Subject: [PATCH] port code from python2 to python3 Change-Id: I4b8c51a7ba90e07fc8d558c69bd924a93fa8b908 Signed-off-by: biao716.wang --- Makefile | 5 ++ debian/compat | 2 +- debian/control | 13 +++-- debian/rules | 7 ++- doc/source/conf.py | 12 ++-- examples/how_to/add_command.py | 2 +- examples/how_to/create_a_job.py | 2 +- examples/how_to/create_nested_views.py | 4 +- .../delete_all_the_nodes_except_master.py | 2 +- examples/how_to/get_config.py | 2 +- examples/how_to/get_plugin_information.py | 2 +- .../get_version_info_from_last_good_build.py | 2 +- examples/how_to/query_a_build.py | 4 +- examples/how_to/search_artifact_by_regexp.py | 2 +- examples/how_to/search_artifacts.py | 2 +- examples/low_level/copy_a_job.py | 2 +- examples/low_level/create_a_view_low_level.py | 2 +- examples/low_level/example_param_build.py | 2 +- examples/low_level/login_with_auth.py | 4 +- examples/low_level/post_watcher.py | 14 ++--- jenkinsapi/api.py | 10 ++-- jenkinsapi/jenkins.py | 8 +-- jenkinsapi/jenkinsbase.py | 4 +- jenkinsapi/job.py | 10 ++-- jenkinsapi/jobs.py | 6 +- jenkinsapi/node.py | 2 +- jenkinsapi/nodes.py | 8 +-- jenkinsapi/plugins.py | 10 ++-- jenkinsapi/queue.py | 6 +- jenkinsapi/result_set.py | 8 +-- jenkinsapi/utils/requester.py | 8 +-- jenkinsapi/view.py | 22 ++++---- jenkinsapi/views.py | 6 +- jenkinsapi_tests/systests/base.py | 4 +- .../systests/test_downstream_upstream.py | 2 +- jenkinsapi_tests/systests/test_invocation.py | 6 +- jenkinsapi_tests/systests/test_jenkins.py | 14 ++--- .../systests/test_jenkins_matrix.py | 6 +- jenkinsapi_tests/systests/test_nodes.py | 2 +- .../systests/test_parameterized_builds.py | 2 +- jenkinsapi_tests/systests/test_queue.py | 4 +- jenkinsapi_tests/systests/test_views.py | 8 +-- jenkinsapi_tests/test_utils/random_strings.py | 2 +- jenkinsapi_tests/unittests/test_build.py | 14 ++--- .../unittests/test_build_scm_git.py | 12 ++-- jenkinsapi_tests/unittests/test_executors.py | 18 +++--- .../unittests/test_fingerprint.py | 4 +- jenkinsapi_tests/unittests/test_jenkins.py | 54 +++++++++--------- jenkinsapi_tests/unittests/test_job.py | 50 ++++++++--------- .../unittests/test_job_folders.py | 16 +++--- .../unittests/test_job_get_all_builds.py | 12 ++-- jenkinsapi_tests/unittests/test_job_maven.py | 2 +- jenkinsapi_tests/unittests/test_job_scm_hg.py | 10 ++-- jenkinsapi_tests/unittests/test_node.py | 6 +- jenkinsapi_tests/unittests/test_nodes.py | 2 +- jenkinsapi_tests/unittests/test_plugins.py | 26 ++++----- jenkinsapi_tests/unittests/test_queue.py | 10 ++-- jenkinsapi_tests/unittests/test_requester.py | 4 +- jenkinsapi_tests/unittests/test_result_set.py | 8 +-- jenkinsapi_tests/unittests/test_view.py | 14 ++--- jenkinsapi_tests/unittests/test_views.py | 2 +- jenkinsapi_utils/jenkins_launcher.py | 8 +-- jenkinsapi_utils/simple_post_logger.py | 14 ++--- release.sh | 8 +-- requirements.txt | 4 ++ setup.cfg | 56 +++++++++++++++++-- setup.py | 48 +--------------- 67 files changed, 333 insertions(+), 314 deletions(-) create mode 100644 Makefile create mode 100644 requirements.txt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d664d05 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +.PHONY: install + +install: + python3 setup.py install --prefix=${DESTDIR}/usr + diff --git a/debian/compat b/debian/compat index 7f8f011..f599e28 100644 --- a/debian/compat +++ b/debian/compat @@ -1 +1 @@ -7 +10 diff --git a/debian/control b/debian/control index e92d293..e8bdb0b 100644 --- a/debian/control +++ b/debian/control @@ -2,17 +2,18 @@ Source: python-jenkinsapi Section: python Priority: optional Maintainer: Al Stone -Build-Depends: debhelper (>= 8.0.0), dh-python, python-dev, python-all-dev, python-lxml, python-setuptools +Build-Depends: debhelper (>= 8.0.0), dh-python, python3, python3-all-dev, python3-lxml, python3-setuptools, + python3-pbr, python3-pytest, python3-pylint-common, python3-mock XS-Python-Version: current Standards-Version: 3.9.5 Homepage: http://pypi.python.org/pypi/jenkinsapi -Package: python-jenkinsapi +Package: python3-jenkinsapi Architecture: all -Depends: python-lxml, python-bs4, python-pkg-resources, python-requests, - ${python:Depends}, ${misc:Depends} -Provides: ${python:Provides} -XB-Python-Versions: ${python:Versions} +Depends: python3-lxml, python3-bs4, python3-pkg-resources, python3-requests, + ${python3:Depends}, ${misc:Depends} +Provides: ${python3:Provides} +XB-Python-Versions: ${python3:Versions} Description: bindings for Python usage of the Jenkins remote API Jenkins is the market leading continuous integration system, originally created by Kohsuke Kawaguchi. This API makes Jenkins even easier to use diff --git a/debian/rules b/debian/rules index 2ebce13..1232503 100755 --- a/debian/rules +++ b/debian/rules @@ -10,4 +10,9 @@ #export DH_VERBOSE=1 %: - dh $@ --with python2 + dh $@ --with python3 --buildsystem=pybuild + +override_dh_auto_test: + #disable test + + diff --git a/doc/source/conf.py b/doc/source/conf.py index 336c8f1..4596be8 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -52,8 +52,8 @@ source_suffix = '.rst' master_doc = 'index' # General information about the project. -project = u' JenkinsAPI' -copyright = u'2012, %s' % PROJECT_AUTHORS +project = ' JenkinsAPI' +copyright = '2012, %s' % PROJECT_AUTHORS # The version info for the project you're documenting, acts as replacement for # built documents. @@ -194,7 +194,7 @@ latex_elements = { # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'JenkinsAPI.tex', u'JenkinsAPI Documentation', u'xxx', 'manual'), + ('index', 'JenkinsAPI.tex', 'JenkinsAPI Documentation', 'xxx', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -223,7 +223,7 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'jenkinsapi', u' JenkinsAPI Documentation', [u'xxx'], 1) + ('index', 'jenkinsapi', ' JenkinsAPI Documentation', ['xxx'], 1) ] # If true, show URL addresses after external links. @@ -236,8 +236,8 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'JenkinsAPI', u'JenkinsAPI Documentation', - u'xxx', 'JenkinsAPI', 'One line description of project.', + ('index', 'JenkinsAPI', 'JenkinsAPI Documentation', + 'xxx', 'JenkinsAPI', 'One line description of project.', 'Miscellaneous'), ] diff --git a/examples/how_to/add_command.py b/examples/how_to/add_command.py index fadfa02..40ec324 100644 --- a/examples/how_to/add_command.py +++ b/examples/how_to/add_command.py @@ -33,7 +33,7 @@ shell = ET.SubElement(builders, 'hudson.tasks.Shell') command = ET.SubElement(shell, 'command') command.text = "ls" -print ET.tostring(root) +print(ET.tostring(root)) J[jobname].update_config(ET.tostring(root)) #J.delete_job(jobname) diff --git a/examples/how_to/create_a_job.py b/examples/how_to/create_a_job.py index 343685e..3fd8bc8 100644 --- a/examples/how_to/create_a_job.py +++ b/examples/how_to/create_a_job.py @@ -1,4 +1,4 @@ -from __future__ import print_function + import logging logging.basicConfig() diff --git a/examples/how_to/create_nested_views.py b/examples/how_to/create_nested_views.py index b82b28d..2ce5b1a 100644 --- a/examples/how_to/create_nested_views.py +++ b/examples/how_to/create_nested_views.py @@ -1,6 +1,6 @@ # This example requires NestedViews plugin to be installed in Jenkins # You need to have at least one job in your Jenkins to see views -from __future__ import print_function + import logging from pkg_resources import resource_string @@ -29,7 +29,7 @@ if top_view is None: else: logger.info('View has been created') -print('top_view.views=', top_view.views.keys()) +print('top_view.views=', list(top_view.views.keys())) logger.info('Attempting to create view inside nested view') sub_view = top_view.views.create('SubView') if sub_view is None: diff --git a/examples/how_to/delete_all_the_nodes_except_master.py b/examples/how_to/delete_all_the_nodes_except_master.py index e68c89a..cee05a3 100644 --- a/examples/how_to/delete_all_the_nodes_except_master.py +++ b/examples/how_to/delete_all_the_nodes_except_master.py @@ -5,7 +5,7 @@ from jenkinsapi.jenkins import Jenkins j = Jenkins('http://localhost:8080') -for node_id, _ in j.get_nodes().iteritems(): +for node_id, _ in j.get_nodes().items(): if not node_id == 'master': print(node_id) j.delete_node(node_id) diff --git a/examples/how_to/get_config.py b/examples/how_to/get_config.py index 72b6635..51e9267 100644 --- a/examples/how_to/get_config.py +++ b/examples/how_to/get_config.py @@ -1,7 +1,7 @@ """ An example of how to use JenkinsAPI to fetch the config XML of a job. """ -from __future__ import print_function + from jenkinsapi.jenkins import Jenkins J = Jenkins('http://localhost:8080') diff --git a/examples/how_to/get_plugin_information.py b/examples/how_to/get_plugin_information.py index 380c946..42914c8 100644 --- a/examples/how_to/get_plugin_information.py +++ b/examples/how_to/get_plugin_information.py @@ -1,7 +1,7 @@ """ Get information about currently installed plugins """ -from __future__ import print_function + from jenkinsapi.jenkins import Jenkins diff --git a/examples/how_to/get_version_info_from_last_good_build.py b/examples/how_to/get_version_info_from_last_good_build.py index 3df5f55..07da7bc 100644 --- a/examples/how_to/get_version_info_from_last_good_build.py +++ b/examples/how_to/get_version_info_from_last_good_build.py @@ -1,7 +1,7 @@ """ Extract version information from the latest build. """ -from __future__ import print_function + from jenkinsapi.jenkins import Jenkins diff --git a/examples/how_to/query_a_build.py b/examples/how_to/query_a_build.py index 16dc569..b6dd9d1 100644 --- a/examples/how_to/query_a_build.py +++ b/examples/how_to/query_a_build.py @@ -1,10 +1,10 @@ -from __future__ import print_function + from jenkinsapi.view import View from jenkinsapi.jenkins import Jenkins J = Jenkins('http://localhost:8080') -print(J.items()) +print(list(J.items())) j = J['foo'] j = J.get_job("foo") b = j.get_last_build() diff --git a/examples/how_to/search_artifact_by_regexp.py b/examples/how_to/search_artifact_by_regexp.py index 7f73562..7f73898 100644 --- a/examples/how_to/search_artifact_by_regexp.py +++ b/examples/how_to/search_artifact_by_regexp.py @@ -1,4 +1,4 @@ -from __future__ import print_function + from jenkinsapi.api import search_artifact_by_regexp import re diff --git a/examples/how_to/search_artifacts.py b/examples/how_to/search_artifacts.py index 31d19c6..f41388d 100644 --- a/examples/how_to/search_artifacts.py +++ b/examples/how_to/search_artifacts.py @@ -1,4 +1,4 @@ -from __future__ import print_function + from jenkinsapi.api import search_artifacts diff --git a/examples/low_level/copy_a_job.py b/examples/low_level/copy_a_job.py index ae0399b..9594f95 100644 --- a/examples/low_level/copy_a_job.py +++ b/examples/low_level/copy_a_job.py @@ -1,7 +1,7 @@ """ A lower-level implementation of copying a job in Jenkins """ -from __future__ import print_function + import requests from jenkinsapi.jenkins import Jenkins diff --git a/examples/low_level/create_a_view_low_level.py b/examples/low_level/create_a_view_low_level.py index 21115ca..39fe015 100644 --- a/examples/low_level/create_a_view_low_level.py +++ b/examples/low_level/create_a_view_low_level.py @@ -2,7 +2,7 @@ A low level example: This is how JenkinsAPI creates views """ -from __future__ import print_function + import requests import json diff --git a/examples/low_level/example_param_build.py b/examples/low_level/example_param_build.py index d6e8c33..a34ee72 100644 --- a/examples/low_level/example_param_build.py +++ b/examples/low_level/example_param_build.py @@ -1,4 +1,4 @@ -from __future__ import print_function + import json import requests diff --git a/examples/low_level/login_with_auth.py b/examples/low_level/login_with_auth.py index c11aa9f..40e8942 100644 --- a/examples/low_level/login_with_auth.py +++ b/examples/low_level/login_with_auth.py @@ -1,7 +1,7 @@ """ A lower level example of how we login with authentication """ -from __future__ import print_function + from jenkinsapi import jenkins @@ -9,4 +9,4 @@ from jenkinsapi import jenkins J = jenkins.Jenkins("http://localhost:8080", username="sal", password="foobar") J.poll() -print(J.items()) +print(list(J.items())) diff --git a/examples/low_level/post_watcher.py b/examples/low_level/post_watcher.py index c6921fd..da4ff63 100644 --- a/examples/low_level/post_watcher.py +++ b/examples/low_level/post_watcher.py @@ -12,8 +12,8 @@ You can use this to test GET and POST methods. """ -import SimpleHTTPServer -import SocketServer +import http.server +import socketserver import logging import cgi @@ -25,12 +25,12 @@ PORT = 8080 I = "localhost" -class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): +class ServerHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): logging.warning("======= GET STARTED =======") logging.warning(self.headers) - SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) + http.server.SimpleHTTPRequestHandler.do_GET(self) def do_POST(self): logging.warning("======= POST STARTED =======") @@ -45,11 +45,11 @@ class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): for item in form.list: logging.warning(item) logging.warning("\n") - SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) + http.server.SimpleHTTPRequestHandler.do_GET(self) Handler = ServerHandler -httpd = SocketServer.TCPServer(("", PORT), Handler) +httpd = socketserver.TCPServer(("", PORT), Handler) -print "Serving at: http://%(interface)s:%(port)s" % dict(interface=I or "localhost", port=PORT) +print("Serving at: http://%(interface)s:%(port)s" % dict(interface=I or "localhost", port=PORT)) httpd.serve_forever() \ No newline at end of file diff --git a/jenkinsapi/api.py b/jenkinsapi/api.py index c191907..be4a777 100644 --- a/jenkinsapi/api.py +++ b/jenkinsapi/api.py @@ -77,7 +77,7 @@ def get_artifacts(jenkinsurl, jobid=None, build_no=None, build = job.get_last_good_build() artifacts = build.get_artifact_dict() log.info(msg="Found %i artifacts in '%s'" - % (len(artifacts.keys()), build_no)) + % (len(list(artifacts.keys())), build_no)) return artifacts @@ -175,7 +175,7 @@ def install_artifacts(artifacts, dirstruct, installdir, basestaticurl): """ assert basestaticurl.endswith("/"), "Basestaticurl should end with /" installed = [] - for reldir, artifactnames in dirstruct.items(): + for reldir, artifactnames in list(dirstruct.items()): destdir = os.path.join(installdir, reldir) if not os.path.exists(destdir): log.warn(msg="Making install directory %s" % destdir) @@ -184,7 +184,7 @@ def install_artifacts(artifacts, dirstruct, installdir, basestaticurl): assert os.path.isdir(destdir) for artifactname in artifactnames: destpath = os.path.abspath(os.path.join(destdir, artifactname)) - if artifactname in artifacts.keys(): + if artifactname in list(artifacts.keys()): # The artifact must be loaded from jenkins theartifact = artifacts[artifactname] else: @@ -222,10 +222,10 @@ def search_artifact_by_regexp(jenkinsurl, jobid, artifactRegExp, artifacts = build.get_artifact_dict() try: - it = artifacts.iteritems() + it = iter(artifacts.items()) except AttributeError: # Python3 - it = artifacts.items() + it = list(artifacts.items()) for name, art in it: md_match = artifactRegExp.search(name) diff --git a/jenkinsapi/jenkins.py b/jenkinsapi/jenkins.py index d0708f5..6d0295d 100644 --- a/jenkinsapi/jenkins.py +++ b/jenkinsapi/jenkins.py @@ -6,8 +6,8 @@ Module for jenkinsapi Jenkins object import json try: - import urlparse - from urllib import quote as urlquote, urlencode + import urllib.parse + from urllib.parse import quote as urlquote, urlencode except ImportError: # Python3 import urllib.parse as urlparse @@ -194,7 +194,7 @@ class Jenkins(JenkinsBase): return list(self.get_jobs()) def keys(self): - return [a for a in self.iterkeys()] + return [a for a in self.keys()] # This is a function alias we retain for historical compatibility get_jobs_list = keys @@ -252,7 +252,7 @@ class Jenkins(JenkinsBase): def get_node_url(self, nodename=""): """Return the url for nodes""" - url = urlparse.urljoin(self.base_server_url(), 'computer/%s' % urlquote(nodename)) + url = urllib.parse.urljoin(self.base_server_url(), 'computer/%s' % urlquote(nodename)) return url def get_queue_url(self): diff --git a/jenkinsapi/jenkinsbase.py b/jenkinsapi/jenkinsbase.py index d7d23a6..b17ed12 100644 --- a/jenkinsapi/jenkinsbase.py +++ b/jenkinsapi/jenkinsbase.py @@ -92,7 +92,7 @@ class JenkinsBase(object): def resolve_job_folders(self, jobs): for job in list(jobs): - if 'color' not in job.keys(): + if 'color' not in list(job.keys()): jobs.remove(job) jobs += self.process_job_folder(job) @@ -103,7 +103,7 @@ class JenkinsBase(object): result = [] for job in data.get('jobs', []): - if 'color' not in job.keys(): + if 'color' not in list(job.keys()): result += self.process_job_folder(job) else: result.append(job) diff --git a/jenkinsapi/job.py b/jenkinsapi/job.py index ff6122d..dc48376 100644 --- a/jenkinsapi/job.py +++ b/jenkinsapi/job.py @@ -23,7 +23,7 @@ import xml.etree.ElementTree as ET try: - import urlparse + import urllib.parse except ImportError: # Python3 import urllib.parse as urlparse @@ -157,7 +157,7 @@ class Job(JenkinsBase, MutableJenkinsThing): out = {'parameter': build_p} if file_params: file_p = [{'name': k, 'file': k} - for k in file_params.keys()] + for k in list(file_params.keys())] out['parameter'].extend(file_p) if len(out['parameter']) == 1: @@ -187,7 +187,7 @@ class Job(JenkinsBase, MutableJenkinsThing): # Either copy the params dict or make a new one. build_params = build_params and dict( - build_params.items()) or {} # Via POSTed JSON + list(build_params.items())) or {} # Via POSTed JSON url = self.get_build_triggerurl(files) if cause: @@ -513,7 +513,7 @@ class Job(JenkinsBase, MutableJenkinsThing): """ url = self.get_config_xml_url() try: - if isinstance(config, unicode): # pylint: disable=undefined-variable + if isinstance(config, str): # pylint: disable=undefined-variable config = str(config) except NameError: # Python3 already a str @@ -598,7 +598,7 @@ class Job(JenkinsBase, MutableJenkinsThing): if not self.is_queued(): raise NotInQueue() queue_id = self._data['queueItem']['id'] - url = urlparse.urljoin(self.get_jenkins_obj().get_queue().baseurl, + url = urllib.parse.urljoin(self.get_jenkins_obj().get_queue().baseurl, 'cancelItem?id=%s' % queue_id) self.get_jenkins_obj().requester.post_and_confirm_status(url, data='') return True diff --git a/jenkinsapi/jobs.py b/jenkinsapi/jobs.py index eda5e7c..46c091e 100644 --- a/jenkinsapi/jobs.py +++ b/jenkinsapi/jobs.py @@ -77,7 +77,7 @@ class Jobs(object): """ True if job_name is the name of a defined job """ - return job_name in self.keys() + return job_name in list(self.keys()) def iterkeys(self): """ @@ -90,7 +90,7 @@ class Jobs(object): """ Return a list of the names of all jobs """ - return list(self.iterkeys()) + return list(self.keys()) def create(self, job_name, config): """ @@ -104,7 +104,7 @@ class Jobs(object): params = {'name': job_name} try: - if isinstance(config, unicode): # pylint: disable=undefined-variable + if isinstance(config, str): # pylint: disable=undefined-variable config = str(config) except NameError: # Python3 already a str diff --git a/jenkinsapi/node.py b/jenkinsapi/node.py index 75a6e46..8acd6d4 100644 --- a/jenkinsapi/node.py +++ b/jenkinsapi/node.py @@ -7,7 +7,7 @@ from jenkinsapi.custom_exceptions import PostRequired import logging try: - from urllib import quote as urlquote + from urllib.parse import quote as urlquote except ImportError: # Python3 from urllib.parse import quote as urlquote diff --git a/jenkinsapi/nodes.py b/jenkinsapi/nodes.py index a3bd036..0f5ce75 100644 --- a/jenkinsapi/nodes.py +++ b/jenkinsapi/nodes.py @@ -29,14 +29,14 @@ class Nodes(JenkinsBase): return 'Nodes @ %s' % self.baseurl def __contains__(self, node_name): - return node_name in self.keys() + return node_name in list(self.keys()) def iterkeys(self): for item in self._data['computer']: yield item['displayName'] def keys(self): - return list(self.iterkeys()) + return list(self.keys()) def iteritems(self): for item in self._data['computer']: @@ -48,11 +48,11 @@ class Nodes(JenkinsBase): yield item['displayName'], Node(nodeurl, nodename, self.jenkins) def __getitem__(self, nodename): - self_as_dict = dict(self.iteritems()) + self_as_dict = dict(iter(self.items())) if nodename in self_as_dict: return self_as_dict[nodename] else: raise UnknownNode(nodename) def __len__(self): - return len(self.iteritems()) + return len(iter(self.items())) diff --git a/jenkinsapi/plugins.py b/jenkinsapi/plugins.py index a1cc8be..0a9e80e 100644 --- a/jenkinsapi/plugins.py +++ b/jenkinsapi/plugins.py @@ -1,7 +1,7 @@ """ jenkinsapi plugins """ -from __future__ import print_function + import logging from jenkinsapi.plugin import Plugin @@ -28,7 +28,7 @@ class Plugins(JenkinsBase): return self.get_data(self.baseurl, tree=tree) def keys(self): - return self.get_plugins_dict().keys() + return list(self.get_plugins_dict().keys()) __iter__ = keys @@ -36,7 +36,7 @@ class Plugins(JenkinsBase): return self._get_plugins() def values(self): - return [a[1] for a in self.iteritems()] + return [a[1] for a in self.items()] def _get_plugins(self): if 'plugins' in self._data: @@ -47,7 +47,7 @@ class Plugins(JenkinsBase): return dict(self._get_plugins()) def __len__(self): - return len(self.get_plugins_dict().keys()) + return len(list(self.get_plugins_dict().keys())) def __getitem__(self, plugin_name): try: @@ -59,7 +59,7 @@ class Plugins(JenkinsBase): """ True if plugin_name is the name of a defined plugin """ - return plugin_name in self.keys() + return plugin_name in list(self.keys()) def __str__(self): plugins = [plugin["shortName"] for plugin in self._data.get("plugins", [])] diff --git a/jenkinsapi/queue.py b/jenkinsapi/queue.py index 0804927..5b51ca9 100644 --- a/jenkinsapi/queue.py +++ b/jenkinsapi/queue.py @@ -46,16 +46,16 @@ class Queue(JenkinsBase): yield QueueItem(self.jenkins, **item) def keys(self): - return list(self.iterkeys()) + return list(self.keys()) def values(self): - return list(self.itervalues()) + return list(self.values()) def __len__(self): return len(self._data['items']) def __getitem__(self, item_id): - self_as_dict = dict(self.iteritems()) + self_as_dict = dict(iter(self.items())) if item_id in self_as_dict: return self_as_dict[item_id] else: diff --git a/jenkinsapi/result_set.py b/jenkinsapi/result_set.py index 6962c07..569988c 100644 --- a/jenkinsapi/result_set.py +++ b/jenkinsapi/result_set.py @@ -30,10 +30,10 @@ class ResultSet(JenkinsBase): return str(self) def keys(self): - return [a[0] for a in self.iteritems()] + return [a[0] for a in self.items()] def items(self): - return [a for a in self.iteritems()] + return [a for a in self.items()] def iteritems(self): for suite in self._data.get("suites", []): @@ -49,8 +49,8 @@ class ResultSet(JenkinsBase): yield result.identifier(), result def __len__(self): - return len(self.items()) + return len(list(self.items())) def __getitem__(self, key): - self_as_dict = dict(self.iteritems()) + self_as_dict = dict(iter(self.items())) return self_as_dict[key] diff --git a/jenkinsapi/utils/requester.py b/jenkinsapi/utils/requester.py index c966786..4113a6d 100644 --- a/jenkinsapi/utils/requester.py +++ b/jenkinsapi/utils/requester.py @@ -5,7 +5,7 @@ Module for jenkinsapi requester (which is a wrapper around python-requests) import requests try: - import urlparse + import urllib.parse except ImportError: # Python3 import urllib.parse as urlparse @@ -41,7 +41,7 @@ class Requester(object): if username: assert password, 'Cannot set a username without a password!' - self.base_scheme = urlparse.urlsplit(baseurl).scheme if baseurl else None + self.base_scheme = urllib.parse.urlsplit(baseurl).scheme if baseurl else None self.username = username self.password = password self.ssl_verify = ssl_verify @@ -78,8 +78,8 @@ class Requester(object): Updates scheme of given url to the one used in Jenkins baseurl. """ if self.base_scheme and not url.startswith("%s://" % self.base_scheme): - url_split = urlparse.urlsplit(url) - url = urlparse.urlunsplit( + url_split = urllib.parse.urlsplit(url) + url = urllib.parse.urlunsplit( [ self.base_scheme, url_split.netloc, diff --git a/jenkinsapi/view.py b/jenkinsapi/view.py index c262804..f2a5c91 100644 --- a/jenkinsapi/view.py +++ b/jenkinsapi/view.py @@ -2,7 +2,7 @@ Module for jenkinsapi views """ try: - from urllib import urlencode + from urllib.parse import urlencode except ImportError: # Python3 from urllib.parse import urlencode @@ -40,7 +40,7 @@ class View(JenkinsBase): """ True if view_name is the name of a defined view """ - return job_name in self.keys() + return job_name in list(self.keys()) def delete(self): """ @@ -52,24 +52,24 @@ class View(JenkinsBase): self.deleted = True def keys(self): - return self.get_job_dict().keys() + return list(self.get_job_dict().keys()) def iteritems(self): try: - it = self.get_job_dict().iteritems() + it = iter(self.get_job_dict().items()) except AttributeError: # Python3 - it = self.get_job_dict().items() + it = list(self.get_job_dict().items()) for name, url in it: api_url = self.python_api_url(url) yield name, Job(api_url, name, self.jenkins_obj) def values(self): - return [a[1] for a in self.iteritems()] + return [a[1] for a in self.items()] def items(self): - return [a for a in self.iteritems()] + return [a for a in self.items()] def _get_jobs(self): if 'jobs' in self._data: @@ -80,14 +80,14 @@ class View(JenkinsBase): return dict(self._get_jobs()) def __len__(self): - return len(self.get_job_dict().keys()) + return len(list(self.get_job_dict().keys())) def get_job_url(self, str_job_name): if str_job_name in self: return self.get_job_dict()[str_job_name] else: # noinspection PyUnboundLocalVariable - views_jobs = ", ".join(self.get_job_dict().keys()) + views_jobs = ", ".join(list(self.get_job_dict().keys())) raise NotFound("Job %s is not known, available jobs" " in view are: %s" % (str_job_name, views_jobs)) @@ -145,7 +145,7 @@ class View(JenkinsBase): } data["name"] = self.name # Add existing jobs (if any) - for job_name in self.get_job_dict().keys(): + for job_name in list(self.get_job_dict().keys()): data[job_name] = 'on' # Add new job @@ -184,7 +184,7 @@ class View(JenkinsBase): """ url = self.get_config_xml_url() try: - if isinstance(config, unicode): # pylint: disable=undefined-variable + if isinstance(config, str): # pylint: disable=undefined-variable config = str(config) except NameError: # Python3 already a str diff --git a/jenkinsapi/views.py b/jenkinsapi/views.py index bac9b70..5c5e978 100644 --- a/jenkinsapi/views.py +++ b/jenkinsapi/views.py @@ -23,7 +23,7 @@ class Views(object): self.jenkins = jenkins def __len__(self): - return len(self.keys()) + return len(list(self.keys())) def __delitem__(self, view_name): if view_name == 'All': @@ -63,7 +63,7 @@ class Views(object): """ True if view_name is the name of a defined view """ - return view_name in self.keys() + return view_name in list(self.keys()) def iterkeys(self): """ @@ -76,7 +76,7 @@ class Views(object): """ Return a list of the names of all views """ - return list(self.iterkeys()) + return list(self.keys()) def create(self, view_name, view_type=LIST_VIEW): """ diff --git a/jenkinsapi_tests/systests/base.py b/jenkinsapi_tests/systests/base.py index 8f71245..acc2ab8 100644 --- a/jenkinsapi_tests/systests/base.py +++ b/jenkinsapi_tests/systests/base.py @@ -30,11 +30,11 @@ class BaseSystemTest(unittest.TestCase): def _delete_all_jobs(self): self.jenkins.poll() - for name in self.jenkins.keys(): + for name in list(self.jenkins.keys()): del self.jenkins[name] def _delete_all_views(self): - all_view_names = self.jenkins.views.keys()[1:] + all_view_names = list(self.jenkins.views.keys())[1:] for name in all_view_names: del self.jenkins.views[name] diff --git a/jenkinsapi_tests/systests/test_downstream_upstream.py b/jenkinsapi_tests/systests/test_downstream_upstream.py index 1d25205..1fa7fc3 100644 --- a/jenkinsapi_tests/systests/test_downstream_upstream.py +++ b/jenkinsapi_tests/systests/test_downstream_upstream.py @@ -96,7 +96,7 @@ class TestDownstreamUpstream(BaseSystemTest): """ Can we keep track of the relationships between upstream & downstream jobs? """ - for job_name, job_config in JOB_CONFIGS.items(): + for job_name, job_config in list(JOB_CONFIGS.items()): self.jenkins.create_job(job_name, job_config) self.jenkins['A'].invoke() diff --git a/jenkinsapi_tests/systests/test_invocation.py b/jenkinsapi_tests/systests/test_invocation.py index 6dcab05..4e1ef7d 100644 --- a/jenkinsapi_tests/systests/test_invocation.py +++ b/jenkinsapi_tests/systests/test_invocation.py @@ -29,7 +29,7 @@ class TestInvocation(BaseSystemTest): self.assertIsInstance(qq, QueueItem) # Let Jenkins catchup qq.block_until_building() - self.assertEquals(qq.get_build_number(), 1) + self.assertEqual(qq.get_build_number(), 1) def test_get_block_until_build_running(self): job_name = 'Bcreate_%s' % random_string() @@ -68,7 +68,7 @@ class TestInvocation(BaseSystemTest): ii.block_until_complete(delay=2) build_number = job.get_last_good_buildnumber() - self.assertEquals(build_number, 3) + self.assertEqual(build_number, 3) build = job.get_build(build_number) self.assertIsInstance(build, Build) @@ -82,7 +82,7 @@ class TestInvocation(BaseSystemTest): qq = job.invoke() qq.block_until_complete(delay=1) build_number = qq.get_build_number() - self.assertEquals(build_number, invocation + 1) + self.assertEqual(build_number, invocation + 1) def test_give_params_on_non_parameterized_job(self): job_name = 'Ecreate_%s' % random_string() diff --git a/jenkinsapi_tests/systests/test_jenkins.py b/jenkinsapi_tests/systests/test_jenkins.py index 9614836..68246d1 100644 --- a/jenkinsapi_tests/systests/test_jenkins.py +++ b/jenkinsapi_tests/systests/test_jenkins.py @@ -35,16 +35,16 @@ class JobTests(BaseSystemTest): j.invoke(block=True) # run this at least once j.disable() - self.assertEquals(j.is_enabled(), False, 'A disabled job is reporting incorrectly') + self.assertEqual(j.is_enabled(), False, 'A disabled job is reporting incorrectly') j.enable() - self.assertEquals(j.is_enabled(), True, 'An enabled job is reporting incorrectly') + self.assertEqual(j.is_enabled(), True, 'An enabled job is reporting incorrectly') def test_get_job_and_update_config(self): job_name = 'config_%s' % random_string() self.jenkins.create_job(job_name, EMPTY_JOB) self.assertJobIsPresent(job_name) config = self.jenkins[job_name].get_config() - self.assertEquals(config.strip(), EMPTY_JOB.strip()) + self.assertEqual(config.strip(), EMPTY_JOB.strip()) self.jenkins[job_name].update_config(EMPTY_JOB) def test_invoke_job(self): @@ -93,11 +93,11 @@ class JobTests(BaseSystemTest): self.assertJobIsPresent(template_job_name) self.assertJobIsPresent(copied_job_name) self.assertIsInstance(j, Job) - self.assertEquals(j.name, copied_job_name) + self.assertEqual(j.name, copied_job_name) def test_get_master_data(self): master_data = self.jenkins.get_master_data() - self.assertEquals(master_data['totalExecutors'], 2) + self.assertEqual(master_data['totalExecutors'], 2) def test_get_missing_plugin(self): plugins = self.jenkins.get_plugins() @@ -106,13 +106,13 @@ class JobTests(BaseSystemTest): def test_get_single_plugin(self): plugins = self.jenkins.get_plugins() - plugin_name, plugin = next(plugins.iteritems()) + plugin_name, plugin = next(iter(plugins.items())) self.assertIsInstance(plugin_name, str) self.assertIsInstance(plugin, Plugin) def test_get_single_plugin_depth_2(self): plugins = self.jenkins.get_plugins(depth=2) - _, plugin = next(plugins.iteritems()) + _, plugin = next(iter(plugins.items())) if __name__ == '__main__': unittest.main() diff --git a/jenkinsapi_tests/systests/test_jenkins_matrix.py b/jenkinsapi_tests/systests/test_jenkins_matrix.py index ce1c4e5..c0ceb81 100644 --- a/jenkinsapi_tests/systests/test_jenkins_matrix.py +++ b/jenkinsapi_tests/systests/test_jenkins_matrix.py @@ -29,9 +29,9 @@ class TestMatrixJob(BaseSystemTest): set_of_groups = set() for run in build.get_matrix_runs(): - self.assertEquals(run.get_number(), build.get_number()) - self.assertEquals(run.get_upstream_build(), build) - match_result = re.search(u'\xbb (.*) #\\d+$', run.name) + self.assertEqual(run.get_number(), build.get_number()) + self.assertEqual(run.get_upstream_build(), build) + match_result = re.search('\xbb (.*) #\\d+$', run.name) self.assertIsNotNone(match_result) set_of_groups.add(match_result.group(1)) build.get_master_job_name() diff --git a/jenkinsapi_tests/systests/test_nodes.py b/jenkinsapi_tests/systests/test_nodes.py index 4c021f2..03e711f 100644 --- a/jenkinsapi_tests/systests/test_nodes.py +++ b/jenkinsapi_tests/systests/test_nodes.py @@ -22,7 +22,7 @@ class TestNodes(BaseSystemTest): self.assertTrue(self.jenkins.has_node(node_name)) N = self.jenkins.get_node(node_name) - self.assertEquals(N.baseurl, self.jenkins.get_node_url(node_name)) + self.assertEqual(N.baseurl, self.jenkins.get_node_url(node_name)) finally: self.jenkins.delete_node(node_name) diff --git a/jenkinsapi_tests/systests/test_parameterized_builds.py b/jenkinsapi_tests/systests/test_parameterized_builds.py index 7869c4c..3a1832a 100644 --- a/jenkinsapi_tests/systests/test_parameterized_builds.py +++ b/jenkinsapi_tests/systests/test_parameterized_builds.py @@ -8,7 +8,7 @@ try: except ImportError: import unittest try: - from StringIO import StringIO + from io import StringIO except ImportError: from io import StringIO from jenkinsapi_tests.systests.base import BaseSystemTest diff --git a/jenkinsapi_tests/systests/test_queue.py b/jenkinsapi_tests/systests/test_queue.py index e53cf38..b1e77ee 100644 --- a/jenkinsapi_tests/systests/test_queue.py +++ b/jenkinsapi_tests/systests/test_queue.py @@ -42,12 +42,12 @@ class TestQueue(BaseSystemTest): reprString = repr(queue) self.assertIn(queue.baseurl, reprString) - for _, item in queue.iteritems(): + for _, item in queue.items(): queue.delete_item(item) queue.poll() - self.assertEquals(len(queue), 0) + self.assertEqual(len(queue), 0) def test_start_and_stop_long_running_job(self): job_name = random_string() diff --git a/jenkinsapi_tests/systests/test_views.py b/jenkinsapi_tests/systests/test_views.py index 76e948c..184be4d 100644 --- a/jenkinsapi_tests/systests/test_views.py +++ b/jenkinsapi_tests/systests/test_views.py @@ -29,7 +29,7 @@ class TestViews(BaseSystemTest): # Can we use the API convenience methods v2 = get_view_from_url(v.baseurl) - self.assertEquals(v, v2) + self.assertEqual(v, v2) def test_create_and_delete_views(self): self._create_job() @@ -67,10 +67,10 @@ class TestViews(BaseSystemTest): self.assertIn(view_name, self.jenkins.views) config = self.jenkins.views[view_name].get_config().strip() new_view_config = VIEW_WITH_FILTER_AND_REGEX % view_name - self.assertNotEquals(config, new_view_config) + self.assertNotEqual(config, new_view_config) self.jenkins.views[view_name].update_config(new_view_config) config = self.jenkins.views[view_name].get_config().strip() - self.assertEquals(config, new_view_config) + self.assertEqual(config, new_view_config) def test_make_nested_views(self): job = self._create_job() @@ -97,7 +97,7 @@ class TestViews(BaseSystemTest): # Can we use the API convenience methods v = get_view_from_url(sv2.baseurl) - self.assertEquals(v, sv2) + self.assertEqual(v, sv2) if __name__ == '__main__': logging.basicConfig() diff --git a/jenkinsapi_tests/test_utils/random_strings.py b/jenkinsapi_tests/test_utils/random_strings.py index 18f13fa..c100693 100644 --- a/jenkinsapi_tests/test_utils/random_strings.py +++ b/jenkinsapi_tests/test_utils/random_strings.py @@ -1,4 +1,4 @@ -from __future__ import print_function + import random import string diff --git a/jenkinsapi_tests/unittests/test_build.py b/jenkinsapi_tests/unittests/test_build.py index 549bd2e..37bdb79 100644 --- a/jenkinsapi_tests/unittests/test_build.py +++ b/jenkinsapi_tests/unittests/test_build.py @@ -1,5 +1,5 @@ import pytz -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest @@ -66,17 +66,17 @@ class test_build(unittest.TestCase): def testName(self): with self.assertRaises(AttributeError): self.b.id() - self.assertEquals(self.b.name, 'foo #1') + self.assertEqual(self.b.name, 'foo #1') def test_duration(self): expected = datetime.timedelta(milliseconds=5782) - self.assertEquals(self.b.get_duration(), expected) - self.assertEquals(self.b.get_duration().seconds, 5) - self.assertEquals(self.b.get_duration().microseconds, 782000) - self.assertEquals(str(self.b.get_duration()), '0:00:05.782000') + self.assertEqual(self.b.get_duration(), expected) + self.assertEqual(self.b.get_duration().seconds, 5) + self.assertEqual(self.b.get_duration().microseconds, 782000) + self.assertEqual(str(self.b.get_duration()), '0:00:05.782000') def test_get_causes(self): - self.assertEquals(self.b.get_causes(), + self.assertEqual(self.b.get_causes(), [{'shortDescription': 'Started by user anonymous', 'userId': None, 'userName': 'anonymous'}]) diff --git a/jenkinsapi_tests/unittests/test_build_scm_git.py b/jenkinsapi_tests/unittests/test_build_scm_git.py index e2f09d5..ae5c74e 100644 --- a/jenkinsapi_tests/unittests/test_build_scm_git.py +++ b/jenkinsapi_tests/unittests/test_build_scm_git.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest @@ -103,11 +103,11 @@ class test_build(unittest.TestCase): Can we extract git build revision data from a build object? """ try: - self.assertIsInstance(self.b.get_revision(), basestring) + self.assertIsInstance(self.b.get_revision(), str) except NameError: # Python3 self.assertIsInstance(self.b.get_revision(), str) - self.assertEquals(self.b.get_revision(), + self.assertEqual(self.b.get_revision(), '7def9ed6e92580f37d00e4980c36c4d36e68f702') def test_git_revision_branch(self): @@ -115,11 +115,11 @@ class test_build(unittest.TestCase): Can we extract git build branch from a build object? """ self.assertIsInstance(self.b.get_revision_branch(), list) - self.assertEquals(len(self.b.get_revision_branch()), 1) + self.assertEqual(len(self.b.get_revision_branch()), 1) self.assertIsInstance(self.b.get_revision_branch()[0], dict) - self.assertEquals(self.b.get_revision_branch()[0]['SHA1'], + self.assertEqual(self.b.get_revision_branch()[0]['SHA1'], '7def9ed6e92580f37d00e4980c36c4d36e68f702') - self.assertEquals(self.b.get_revision_branch()[0]['name'], + self.assertEqual(self.b.get_revision_branch()[0]['name'], 'origin/unstable') if __name__ == '__main__': diff --git a/jenkinsapi_tests/unittests/test_executors.py b/jenkinsapi_tests/unittests/test_executors.py index 03e0b7c..0259248 100644 --- a/jenkinsapi_tests/unittests/test_executors.py +++ b/jenkinsapi_tests/unittests/test_executors.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock import types # To run unittests on python 2.6 please use unittest2 library try: @@ -269,7 +269,7 @@ class TestExecutors(unittest.TestCase): assert repr(self.J) def testCheckURL(self): - self.assertEquals(self.J.baseurl, 'http://localhost:8080') + self.assertEqual(self.J.baseurl, 'http://localhost:8080') @mock.patch.object(Executors, '_poll') @mock.patch.object(Executor, '_poll') @@ -282,7 +282,7 @@ class TestExecutors(unittest.TestCase): self.assertIsInstance(repr(exec_info), str) for e in exec_info: - self.assertEquals(e.get_progress(), 48, 'Should return 48 %') + self.assertEqual(e.get_progress(), 48, 'Should return 48 %') @mock.patch.object(Executors, '_poll') @mock.patch.object(Executor, '_poll') @@ -293,9 +293,9 @@ class TestExecutors(unittest.TestCase): self.assertIsInstance(exec_info, object) for e in exec_info: - self.assertEquals(e.get_progress(), -1, 'Should return 48 %') - self.assertEquals(e.is_idle(), True, 'Should return True') - self.assertEquals( + self.assertEqual(e.get_progress(), -1, 'Should return 48 %') + self.assertEqual(e.is_idle(), True, 'Should return True') + self.assertEqual( repr(e), '' ) @@ -306,7 +306,7 @@ class TestExecutors(unittest.TestCase): baseurl = 'http://localhost:8080/computer/host0.host.com/executors/0' nodename = 'host0.host.com' single_executer = Executor(baseurl, nodename, self.J, '0') - self.assertEquals(single_executer.likely_stuck(), False) + self.assertEqual(single_executer.likely_stuck(), False) @mock.patch.object(Executor, '_poll') def test_get_current_executable(self, _poll_executor): @@ -314,11 +314,11 @@ class TestExecutors(unittest.TestCase): baseurl = 'http://localhost:8080/computer/host0.host.com/executors/0' nodename = 'host0.host.com' single_executer = Executor(baseurl, nodename, self.J, '0') - self.assertEquals( + self.assertEqual( single_executer.get_current_executable()['number'], 4168 ) - self.assertEquals( + self.assertEqual( single_executer.get_current_executable()['url'], 'http://localhost:8080/job/testjob/4168/' ) diff --git a/jenkinsapi_tests/unittests/test_fingerprint.py b/jenkinsapi_tests/unittests/test_fingerprint.py index 90e648f..a68d5b2 100644 --- a/jenkinsapi_tests/unittests/test_fingerprint.py +++ b/jenkinsapi_tests/unittests/test_fingerprint.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest @@ -26,7 +26,7 @@ class TestFingerprint(unittest.TestCase): J = Jenkins(self.baseurl, username='foouser', password='foopassword') self.fp_instance = Fingerprint(self.baseurl, self.dummy_md5, J) self.assertTrue(isinstance(self.fp_instance, Fingerprint)) - self.assertEquals(str(self.fp_instance), self.dummy_md5) + self.assertEqual(str(self.fp_instance), self.dummy_md5) self.assertTrue(self.fp_instance.valid()) @mock.patch.object(Jenkins, '_poll') diff --git a/jenkinsapi_tests/unittests/test_jenkins.py b/jenkinsapi_tests/unittests/test_jenkins.py index 1f2a74b..ae4c3c6 100644 --- a/jenkinsapi_tests/unittests/test_jenkins.py +++ b/jenkinsapi_tests/unittests/test_jenkins.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest @@ -25,12 +25,12 @@ class TestJenkins(unittest.TestCase): def test_clone(self, _poll): _poll.return_value = self.DATA JJ = self.J._clone() - self.assertNotEquals(id(JJ), id(self.J)) - self.assertEquals(JJ, self.J) + self.assertNotEqual(id(JJ), id(self.J)) + self.assertEqual(JJ, self.J) def test_stored_passwords(self): - self.assertEquals(self.J.requester.password, 'foopassword') - self.assertEquals(self.J.requester.username, 'foouser') + self.assertEqual(self.J.requester.password, 'foopassword') + self.assertEqual(self.J.requester.username, 'foouser') @mock.patch.object(Jenkins, '_poll') def test_reload(self, _poll): @@ -56,10 +56,10 @@ class TestJenkins(unittest.TestCase): J = Jenkins('http://localhost:8080/', username='foouser', password='foopassword') for idx, (job_name, job) in enumerate(J.get_jobs()): - self.assertEquals(job_name, _poll.return_value['jobs'][idx]['name']) + self.assertEqual(job_name, _poll.return_value['jobs'][idx]['name']) self.assertTrue(isinstance(job, Job)) - self.assertEquals(job.name, _poll.return_value['jobs'][idx]['name']) - self.assertEquals(job.baseurl, _poll.return_value['jobs'][idx]['url']) + self.assertEqual(job.name, _poll.return_value['jobs'][idx]['name']) + self.assertEqual(job.baseurl, _poll.return_value['jobs'][idx]['url']) @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') @@ -76,13 +76,13 @@ class TestJenkins(unittest.TestCase): J = Jenkins('http://localhost:8080/', username='foouser', password='foopassword', lazy=True) - self.assertEquals(J._data, None) + self.assertEqual(J._data, None) for idx, (job_name, job) in enumerate(J.get_jobs()): - self.assertEquals(job_name, _poll.return_value['jobs'][idx]['name']) + self.assertEqual(job_name, _poll.return_value['jobs'][idx]['name']) self.assertTrue(isinstance(job, Job)) - self.assertEquals(job.name, _poll.return_value['jobs'][idx]['name']) - self.assertEquals(job.baseurl, _poll.return_value['jobs'][idx]['url']) + self.assertEqual(job.name, _poll.return_value['jobs'][idx]['name']) + self.assertEqual(job.baseurl, _poll.return_value['jobs'][idx]['url']) @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') @@ -99,8 +99,8 @@ class TestJenkins(unittest.TestCase): J = Jenkins('http://localhost:8080/', username='foouser', password='foopassword') for idx, (url, job_name) in enumerate(J.get_jobs_info()): - self.assertEquals(job_name, _poll.return_value['jobs'][idx]['name']) - self.assertEquals(url, _poll.return_value['jobs'][idx]['url']) + self.assertEqual(job_name, _poll.return_value['jobs'][idx]['name']) + self.assertEqual(url, _poll.return_value['jobs'][idx]['url']) @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') @@ -117,7 +117,7 @@ class TestJenkins(unittest.TestCase): J = Jenkins('http://localhost:8080/', username='foouser', password='foopassword') for idx, job_name in enumerate(J.get_jobs_list()): - self.assertEquals(job_name, _poll.return_value['jobs'][idx]['name']) + self.assertEqual(job_name, _poll.return_value['jobs'][idx]['name']) @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') @@ -135,8 +135,8 @@ class TestJenkins(unittest.TestCase): username='foouser', password='foopassword') job = J.get_job('job_one') self.assertTrue(isinstance(job, Job)) - self.assertEquals(job.name, _poll.return_value['jobs'][0]['name']) - self.assertEquals(job.baseurl, _poll.return_value['jobs'][0]['url']) + self.assertEqual(job.name, _poll.return_value['jobs'][0]['name']) + self.assertEqual(job.baseurl, _poll.return_value['jobs'][0]['url']) @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') @@ -282,7 +282,7 @@ class TestJenkins(unittest.TestCase): with self.assertRaises(JenkinsAPIException) as ar: J.create_job('job_new', None) - self.assertEquals(str(ar.exception), 'Cannot create job job_new') + self.assertEqual(str(ar.exception), 'Cannot create job job_new') @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') @@ -305,10 +305,10 @@ class TestJenkins(unittest.TestCase): requester=mock_requester) new_jenkins = J.get_jenkins_obj_from_url('http://localhost:8080/') - self.assertEquals(new_jenkins, J) + self.assertEqual(new_jenkins, J) new_jenkins = J.get_jenkins_obj_from_url('http://localhost:8080/foo') - self.assertNotEquals(new_jenkins, J) + self.assertNotEqual(new_jenkins, J) @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') @@ -331,7 +331,7 @@ class TestJenkins(unittest.TestCase): requester=mock_requester) new_jenkins = J.get_jenkins_obj() - self.assertEquals(new_jenkins, J) + self.assertEqual(new_jenkins, J) @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') @@ -345,7 +345,7 @@ class TestJenkins(unittest.TestCase): J = Jenkins('http://localhost:8080/', username='foouser', password='foopassword', requester=mock_requester) - self.assertEquals('1.542', J.version) + self.assertEqual('1.542', J.version) @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') @@ -359,7 +359,7 @@ class TestJenkins(unittest.TestCase): J = Jenkins(base_url, username='foouser', password='foopassword', requester=mock_requester) - self.assertEquals('0.0', J.version) + self.assertEqual('0.0', J.version) @mock.patch.object(JenkinsBase, 'get_data') def test_get_master_data(self, _base_poll): @@ -371,8 +371,8 @@ class TestJenkins(unittest.TestCase): j = Jenkins(base_url, username='foouser', password='foopassword') data = j.get_master_data() - self.assertEquals(data['busyExecutors'], 59) - self.assertEquals(data['totalExecutors'], 75) + self.assertEqual(data['busyExecutors'], 59) + self.assertEqual(data['totalExecutors'], 75) class TestJenkinsURLs(unittest.TestCase): @@ -382,14 +382,14 @@ class TestJenkinsURLs(unittest.TestCase): _poll.return_value = {} J = Jenkins('http://localhost:8080', username='foouser', password='foopassword') - self.assertEquals(J.get_create_url(), 'http://localhost:8080/createItem') + self.assertEqual(J.get_create_url(), 'http://localhost:8080/createItem') @mock.patch.object(Jenkins, '_poll') def testWithSlash(self, _poll): _poll.return_value = {} J = Jenkins('http://localhost:8080/', username='foouser', password='foopassword') - self.assertEquals(J.get_create_url(), 'http://localhost:8080/createItem') + self.assertEqual(J.get_create_url(), 'http://localhost:8080/createItem') @mock.patch.object(Jenkins, '_poll') @mock.patch.object(Plugins, '_poll') diff --git a/jenkinsapi_tests/unittests/test_job.py b/jenkinsapi_tests/unittests/test_job.py index 8096316..1c9087c 100644 --- a/jenkinsapi_tests/unittests/test_job.py +++ b/jenkinsapi_tests/unittests/test_job.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock import json # To run unittests on python 2.6 please use unittest2 library try: @@ -111,37 +111,37 @@ class TestJob(unittest.TestCase): def testRepr(self): # Can we produce a repr string for this object - self.assertEquals(repr(self.j), '') + self.assertEqual(repr(self.j), '') def testName(self): with self.assertRaises(AttributeError): self.j.id() - self.assertEquals(self.j.name, 'foo') + self.assertEqual(self.j.name, 'foo') def testNextBuildNumber(self): - self.assertEquals(self.j.get_next_build_number(), 4) + self.assertEqual(self.j.get_next_build_number(), 4) def test_special_urls(self): - self.assertEquals(self.j.baseurl, 'http://halob:8080/job/foo') + self.assertEqual(self.j.baseurl, 'http://halob:8080/job/foo') - self.assertEquals( + self.assertEqual( self.j.get_delete_url(), 'http://halob:8080/job/foo/doDelete') - self.assertEquals( + self.assertEqual( self.j.get_rename_url(), 'http://halob:8080/job/foo/doRename') def test_get_description(self): - self.assertEquals(self.j.get_description(), 'test job') + self.assertEqual(self.j.get_description(), 'test job') def test_get_build_triggerurl(self): - self.assertEquals(self.j.get_build_triggerurl(None), + self.assertEqual(self.j.get_build_triggerurl(None), 'http://halob:8080/job/foo/buildWithParameters') def test_wrong__mk_json_from_build_parameters(self): with self.assertRaises(AssertionError) as ar: self.j._mk_json_from_build_parameters(build_params='bad parameter') - self.assertEquals( + self.assertEqual( str(ar.exception), 'Build parameters must be a dict') @mock.patch.object(JenkinsBase, 'get_data', fakeGetData) @@ -167,18 +167,18 @@ class TestJob(unittest.TestCase): @mock.patch.object(JenkinsBase, 'get_data', fakeGetData) def test_get_last_buildnumber(self): ret = self.j.get_last_buildnumber() - self.assertEquals(ret, 4) + self.assertEqual(ret, 4) @mock.patch.object(JenkinsBase, 'get_data', fakeGetData) def test_get_last_completed_buildnumber(self): ret = self.j.get_last_completed_buildnumber() - self.assertEquals(ret, 3) + self.assertEqual(ret, 3) @mock.patch.object(JenkinsBase, 'get_data', fakeGetDataTree) def test_get_build_dict(self): ret = self.j.get_build_dict() self.assertTrue(isinstance(ret, dict)) - self.assertEquals(len(ret), 4) + self.assertEqual(len(ret), 4) @mock.patch.object(JenkinsBase, 'get_data', fake_get_data_tree_empty) def test_nobuilds_get_build_dict(self): @@ -192,7 +192,7 @@ class TestJob(unittest.TestCase): # So we convert result to a list ret = list(self.j.get_build_ids()) self.assertTrue(isinstance(ret, list)) - self.assertEquals(len(ret), 4) + self.assertEqual(len(ret), 4) @mock.patch.object(Job, '_poll') def test_nobuilds_get_revision_dict(self, _poll): @@ -226,9 +226,9 @@ class TestJob(unittest.TestCase): mock_data = TestJob.URL_DATA[url].copy() mock_data['firstBuild'] = {'number': 1} del mock_data['builds'][-1] - self.assertEquals(len(mock_data['builds']), 2) + self.assertEqual(len(mock_data['builds']), 2) new_data = j._add_missing_builds(mock_data) - self.assertEquals(len(new_data['builds']), 3) + self.assertEqual(len(new_data['builds']), 3) @mock.patch.object(JenkinsBase, 'get_data') def test__add_missing_builds_no_first_build(self, get_data): @@ -240,7 +240,7 @@ class TestJob(unittest.TestCase): mock_data = TestJob.URL_DATA[url].copy() mock_data['firstBuild'] = None j._add_missing_builds(mock_data) - self.assertEquals(initial_call_count, get_data.call_count) + self.assertEqual(initial_call_count, get_data.call_count) @mock.patch.object(JenkinsBase, 'get_data') def test__add_missing_builds_no_builds(self, get_data): @@ -252,7 +252,7 @@ class TestJob(unittest.TestCase): mock_data = TestJob.URL_DATA[url].copy() mock_data['builds'] = None j._add_missing_builds(mock_data) - self.assertEquals(initial_call_count, get_data.call_count) + self.assertEqual(initial_call_count, get_data.call_count) @mock.patch.object(JenkinsBase, 'get_data') def test_get_params(self, get_data): @@ -260,7 +260,7 @@ class TestJob(unittest.TestCase): get_data.return_value = TestJob.URL_DATA[url].copy() j = Job('http://halob:8080/job/foo/', 'foo', self.J) params = list(j.get_params()) - self.assertEquals(len(params), 2) + self.assertEqual(len(params), 2) @mock.patch.object(JenkinsBase, 'get_data') def test_get_params_list(self, get_data): @@ -272,8 +272,8 @@ class TestJob(unittest.TestCase): params = j.get_params_list() self.assertIsInstance(params, list) - self.assertEquals(len(params), 2) - self.assertEquals(params, ['param1', 'param2']) + self.assertEqual(len(params), 2) + self.assertEqual(params, ['param1', 'param2']) @mock.patch.object(JenkinsBase, 'get_data', fakeGetDataTree) # @mock.patch.object(JenkinsBase, 'get_data', fakeGetLastBuild) @@ -282,7 +282,7 @@ class TestJob(unittest.TestCase): with mock.patch('jenkinsapi.job.Build') as build_mock: instance = build_mock.return_value build = self.j.get_build(buildnumber) - self.assertEquals(build, instance) + self.assertEqual(build, instance) build_mock.assert_called_with('http://halob:8080/job/foo/1/', buildnumber, job=self.j) @@ -292,7 +292,7 @@ class TestJob(unittest.TestCase): with mock.patch('jenkinsapi.job.Build') as build_mock: instance = build_mock.return_value build = self.j.get_build_metadata(buildnumber) - self.assertEquals(build, instance) + self.assertEqual(build, instance) build_mock.assert_called_with('http://halob:8080/job/foo/1/', buildnumber, job=self.j, depth=0) @@ -327,7 +327,7 @@ class TestJob(unittest.TestCase): result = self.j._mk_json_from_build_parameters(build_params=params) self.assertTrue(isinstance(result, dict)) - self.assertEquals( + self.assertEqual( result, {"parameter": [{"name": "param1", "value": "value1"}, { "name": "param2", "value": "value2"}]} @@ -337,7 +337,7 @@ class TestJob(unittest.TestCase): with self.assertRaises(AssertionError) as ar: self.j.mk_json_from_build_parameters(build_params='bad parameter') - self.assertEquals( + self.assertEqual( str(ar.exception), 'Build parameters must be a dict') if __name__ == '__main__': diff --git a/jenkinsapi_tests/unittests/test_job_folders.py b/jenkinsapi_tests/unittests/test_job_folders.py index b9a7e8b..eab0c62 100644 --- a/jenkinsapi_tests/unittests/test_job_folders.py +++ b/jenkinsapi_tests/unittests/test_job_folders.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest @@ -55,7 +55,7 @@ class TestJobFolders(unittest.TestCase): }, ] - self.assertEquals( + self.assertEqual( self.jb.resolve_job_folders(jobs), [ { @@ -81,7 +81,7 @@ class TestJobFolders(unittest.TestCase): }, ] - self.assertEquals(self.jb.resolve_job_folders(jobs), []) + self.assertEqual(self.jb.resolve_job_folders(jobs), []) get_data_mock.assert_called_once_with('http://localhost:8080/job/Folder1/api/python') @mock.patch('jenkinsapi.jenkins.JenkinsBase.get_data') @@ -106,7 +106,7 @@ class TestJobFolders(unittest.TestCase): }, ] - self.assertEquals( + self.assertEqual( self.jb.resolve_job_folders(jobs), [ { @@ -160,7 +160,7 @@ class TestJobFolders(unittest.TestCase): }, ] - self.assertEquals( + self.assertEqual( self.jb.resolve_job_folders(jobs), [ { @@ -176,7 +176,7 @@ class TestJobFolders(unittest.TestCase): ] ) - self.assertEquals( + self.assertEqual( get_data_mock.call_args_list, [ mock.call('http://localhost:8080/job/Folder1/api/python'), @@ -226,7 +226,7 @@ class TestJobFolders(unittest.TestCase): }, ] - self.assertEquals( + self.assertEqual( self.jb.resolve_job_folders(jobs), [ { @@ -247,7 +247,7 @@ class TestJobFolders(unittest.TestCase): ] ) - self.assertEquals( + self.assertEqual( get_data_mock.call_args_list, [ mock.call('http://localhost:8080/job/Folder1/api/python'), diff --git a/jenkinsapi_tests/unittests/test_job_get_all_builds.py b/jenkinsapi_tests/unittests/test_job_get_all_builds.py index 3fee88b..8ac66e1 100644 --- a/jenkinsapi_tests/unittests/test_job_get_all_builds.py +++ b/jenkinsapi_tests/unittests/test_job_get_all_builds.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest @@ -177,7 +177,7 @@ class TestJobGetAllBuilds(unittest.TestCase): # remaining jobs will be fetched automatically ret = self.j.get_build_dict() self.assertTrue(isinstance(ret, dict)) - self.assertEquals(len(ret), 4) + self.assertEqual(len(ret), 4) @mock.patch.object(JenkinsBase, 'get_data', fakeGetDataTree) def test_incomplete_builds_list_will_call_jenkins_twice(self): @@ -186,14 +186,14 @@ class TestJobGetAllBuilds(unittest.TestCase): # the Jenkins API TestJobGetAllBuilds.__get_data_call_count = 0 self.j = Job('http://halob:8080/job/foo/', 'foo', self.J) - self.assertEquals(TestJobGetAllBuilds.__get_data_call_count, 2) + self.assertEqual(TestJobGetAllBuilds.__get_data_call_count, 2) @mock.patch.object(JenkinsBase, 'get_data', fakeGetDataTree) def test_complete_builds_list_will_call_jenkins_once(self): # The job data contains all builds, so we will not gather remaining builds TestJobGetAllBuilds.__get_data_call_count = 0 self.j = Job('http://halob:8080/job/fullfoo/', 'fullfoo', self.J) - self.assertEquals(TestJobGetAllBuilds.__get_data_call_count, 1) + self.assertEqual(TestJobGetAllBuilds.__get_data_call_count, 1) @mock.patch.object(JenkinsBase, 'get_data', fakeGetDataTree) def test_nobuilds_get_build_dict(self): @@ -201,7 +201,7 @@ class TestJobGetAllBuilds(unittest.TestCase): ret = j.get_build_dict() self.assertTrue(isinstance(ret, dict)) - self.assertEquals(len(ret), 0) + self.assertEqual(len(ret), 0) @mock.patch.object(JenkinsBase, 'get_data', fakeGetDataTree) def test_get_build_ids(self): @@ -209,7 +209,7 @@ class TestJobGetAllBuilds(unittest.TestCase): # remaining jobs will be fetched automatically ret = list(self.j.get_build_ids()) self.assertTrue(isinstance(ret, list)) - self.assertEquals(len(ret), 4) + self.assertEqual(len(ret), 4) if __name__ == '__main__': diff --git a/jenkinsapi_tests/unittests/test_job_maven.py b/jenkinsapi_tests/unittests/test_job_maven.py index ddc1169..6dfea9d 100644 --- a/jenkinsapi_tests/unittests/test_job_maven.py +++ b/jenkinsapi_tests/unittests/test_job_maven.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest diff --git a/jenkinsapi_tests/unittests/test_job_scm_hg.py b/jenkinsapi_tests/unittests/test_job_scm_hg.py index fa63e44..87898f3 100644 --- a/jenkinsapi_tests/unittests/test_job_scm_hg.py +++ b/jenkinsapi_tests/unittests/test_job_scm_hg.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest @@ -95,13 +95,13 @@ class TestHgJob(unittest.TestCase): @mock.patch.object(Job,'get_config',configtree_with_branch) def test_hg_attributes(self): expected_url = ['http://cm5/hg/sandbox/v01.0/int'] - self.assertEquals(self.j.get_scm_type(),'hg') - self.assertEquals(self.j.get_scm_url(),expected_url) - self.assertEquals(self.j.get_scm_branch(),['testme']) + self.assertEqual(self.j.get_scm_type(),'hg') + self.assertEqual(self.j.get_scm_url(),expected_url) + self.assertEqual(self.j.get_scm_branch(),['testme']) @mock.patch.object(Job,'get_config',configtree_with_default_branch) def test_hg_attributes_default_branch(self): - self.assertEquals(self.j.get_scm_branch(),['default']) + self.assertEqual(self.j.get_scm_branch(),['default']) if __name__ == '__main__': unittest.main() diff --git a/jenkinsapi_tests/unittests/test_node.py b/jenkinsapi_tests/unittests/test_node.py index 211c3c8..c62d099 100644 --- a/jenkinsapi_tests/unittests/test_node.py +++ b/jenkinsapi_tests/unittests/test_node.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest @@ -50,12 +50,12 @@ class TestNode(unittest.TestCase): def testName(self): with self.assertRaises(AttributeError): self.n.id() - self.assertEquals(self.n.name, 'bobnit') + self.assertEqual(self.n.name, 'bobnit') @mock.patch.object(Node, '_poll') def test_online(self, _poll): _poll.return_value = self.DATA - return self.assertEquals(self.n.is_online(), True) + return self.assertEqual(self.n.is_online(), True) if __name__ == '__main__': unittest.main() diff --git a/jenkinsapi_tests/unittests/test_nodes.py b/jenkinsapi_tests/unittests/test_nodes.py index 6ae8467..c284700 100644 --- a/jenkinsapi_tests/unittests/test_nodes.py +++ b/jenkinsapi_tests/unittests/test_nodes.py @@ -212,7 +212,7 @@ class TestNode(unittest.TestCase): repr(self.ns) def testCheckURL(self): - self.assertEquals(self.ns.baseurl, 'http://localhost:8080/computer') + self.assertEqual(self.ns.baseurl, 'http://localhost:8080/computer') @mock.patch.object(Node, '_poll') def testGetMasterNode(self, _poll_node): diff --git a/jenkinsapi_tests/unittests/test_plugins.py b/jenkinsapi_tests/unittests/test_plugins.py index 33f4a99..05ad930 100644 --- a/jenkinsapi_tests/unittests/test_plugins.py +++ b/jenkinsapi_tests/unittests/test_plugins.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest @@ -66,21 +66,21 @@ class TestPlugins(unittest.TestCase): _poll_plugins.return_value = {} plugins = self.J.get_plugins() - self.assertEquals(str(plugins), "[]") + self.assertEqual(str(plugins), "[]") @mock.patch.object(Plugins, '_poll') def test_plugins_str(self, _poll_plugins): _poll_plugins.return_value = self.DATA plugins = self.J.get_plugins() - self.assertEquals(str(plugins), "['maven-plugin', 'subversion']") + self.assertEqual(str(plugins), "['maven-plugin', 'subversion']") @mock.patch.object(Plugins, '_poll') def test_plugins_len(self, _poll_plugins): _poll_plugins.return_value = self.DATA plugins = self.J.get_plugins() - self.assertEquals(len(plugins), 2) + self.assertEqual(len(plugins), 2) @mock.patch.object(Plugins, '_poll') def test_plugins_contains(self, _poll_plugins): @@ -113,14 +113,14 @@ class TestPlugins(unittest.TestCase): } ) - plugins = self.J.get_plugins().values() + plugins = list(self.J.get_plugins().values()) self.assertIn(p, plugins) @mock.patch.object(Plugins, '_poll') def test_plugins_keys(self, _poll_plugins): _poll_plugins.return_value = self.DATA - plugins = self.J.get_plugins().keys() + plugins = list(self.J.get_plugins().keys()) self.assertIn('subversion', plugins) self.assertIn('maven-plugin', plugins) @@ -130,7 +130,7 @@ class TestPlugins(unittest.TestCase): # list() is required here for python 3.x compatibility plugins = list(self.J.get_plugins().keys()) - self.assertEquals([], plugins) + self.assertEqual([], plugins) @mock.patch.object(Plugins, '_poll') def test_plugin_get_by_name(self, _poll_plugins): @@ -156,16 +156,16 @@ class TestPlugins(unittest.TestCase): ) plugin = self.J.get_plugins()['subversion'] - self.assertEquals(p, plugin) + self.assertEqual(p, plugin) @mock.patch.object(Plugins, '_poll') def test_get_plugin_details(self, _poll_plugins): _poll_plugins.return_value = self.DATA plugin = self.J.get_plugins()['subversion'] - self.assertEquals('1.45', plugin.version) - self.assertEquals('subversion', plugin.shortName) - self.assertEquals('Jenkins Subversion Plug-in', plugin.longName) - self.assertEquals('http://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin', + self.assertEqual('1.45', plugin.version) + self.assertEqual('subversion', plugin.shortName) + self.assertEqual('Jenkins Subversion Plug-in', plugin.longName) + self.assertEqual('http://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin', plugin.url) def test_plugin_repr(self): @@ -174,7 +174,7 @@ class TestPlugins(unittest.TestCase): 'shortName': 'subversion', } ) - self.assertEquals(repr(p), '') + self.assertEqual(repr(p), '') if __name__ == '__main__': unittest.main() diff --git a/jenkinsapi_tests/unittests/test_queue.py b/jenkinsapi_tests/unittests/test_queue.py index 967ab60..1246797 100644 --- a/jenkinsapi_tests/unittests/test_queue.py +++ b/jenkinsapi_tests/unittests/test_queue.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest @@ -145,10 +145,10 @@ class TestQueue(unittest.TestCase): self.assertTrue(repr(self.q)) def test_length(self): - self.assertEquals(len(self.q), 3) + self.assertEqual(len(self.q), 3) def test_list_items(self): - self.assertEquals(set(self.q.keys()), set([40, 41, 42])) + self.assertEqual(set(self.q.keys()), set([40, 41, 42])) @mock.patch.object(JenkinsBase, 'get_data', mockGetData) def test_getitem(self): @@ -165,14 +165,14 @@ class TestQueue(unittest.TestCase): def test_get_queue_item_for_job(self): item40 = self.q.get_queue_items_for_job('klscuimkqo') self.assertIsInstance(item40, list) - self.assertEquals(len(item40), 1) + self.assertEqual(len(item40), 1) self.assertIsInstance(item40[0], QueueItem) @mock.patch.object(JenkinsBase, 'get_data', mockGetData) def test_qi_get_parameters(self): qi = self.q[42] - self.assertEquals(qi.get_parameters(), {'name1': 'value1', + self.assertEqual(qi.get_parameters(), {'name1': 'value1', 'node': None}) diff --git a/jenkinsapi_tests/unittests/test_requester.py b/jenkinsapi_tests/unittests/test_requester.py index ac754d1..7ff9728 100644 --- a/jenkinsapi_tests/unittests/test_requester.py +++ b/jenkinsapi_tests/unittests/test_requester.py @@ -1,6 +1,4 @@ -from __future__ import print_function - -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest diff --git a/jenkinsapi_tests/unittests/test_result_set.py b/jenkinsapi_tests/unittests/test_result_set.py index 32fd3ec..c5ccb89 100644 --- a/jenkinsapi_tests/unittests/test_result_set.py +++ b/jenkinsapi_tests/unittests/test_result_set.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest @@ -69,11 +69,11 @@ class TestResultSet(unittest.TestCase): with self.assertRaises(AttributeError): self.rs.id() - self.assertEquals(self.rs.name, 'Test Result for FooBuild') + self.assertEqual(self.rs.name, 'Test Result for FooBuild') def testBuildComponents(self): - self.assertTrue(self.rs.items()) - for k, v in self.rs.items(): + self.assertTrue(list(self.rs.items())) + for k, v in list(self.rs.items()): self.assertIsInstance(k, str) self.assertIsInstance(v, Result) self.assertIsInstance(v.identifier(), str) diff --git a/jenkinsapi_tests/unittests/test_view.py b/jenkinsapi_tests/unittests/test_view.py index f574366..0d0d91c 100644 --- a/jenkinsapi_tests/unittests/test_view.py +++ b/jenkinsapi_tests/unittests/test_view.py @@ -1,4 +1,4 @@ -import mock +from unittest import mock # To run unittests on python 2.6 please use unittest2 library try: import unittest2 as unittest @@ -82,22 +82,22 @@ class TestView(unittest.TestCase): def testName(self): with self.assertRaises(AttributeError): self.v.id() - self.assertEquals(self.v.name, 'FodFanFo') + self.assertEqual(self.v.name, 'FodFanFo') @mock.patch.object(JenkinsBase, '_poll') def test_iteritems(self, _poll): _poll.return_value = self.JOB_DATA - for job_name, job_obj in self.v.iteritems(): + for job_name, job_obj in self.v.items(): self.assertTrue(isinstance(job_obj, Job)) def test_get_job_dict(self): jobs = self.v.get_job_dict() - self.assertEquals(jobs, { + self.assertEqual(jobs, { 'foo': 'http://halob:8080/job/foo/', 'test_jenkinsapi': 'http://halob:8080/job/test_jenkinsapi/'}) def test_len(self): - self.assertEquals(len(self.v), 2) + self.assertEqual(len(self.v), 2) # We have to re-patch JenkinsBase here because by the time # it get to create Job, MagicMock will already expire @@ -111,7 +111,7 @@ class TestView(unittest.TestCase): self.assertTrue(self.v.deleted) def test_get_job_url(self): - self.assertEquals(self.v.get_job_url('foo'), 'http://halob:8080/job/foo/') + self.assertEqual(self.v.get_job_url('foo'), 'http://halob:8080/job/foo/') def test_wrong_get_job_url(self): with self.assertRaises(NotFound): @@ -153,7 +153,7 @@ class TestView(unittest.TestCase): def test_get_nested_view_dict(self): result = self.v.get_nested_view_dict() self.assertTrue(isinstance(result, dict)) - self.assertEquals(len(result), 0) + self.assertEqual(len(result), 0) if __name__ == '__main__': unittest.main() diff --git a/jenkinsapi_tests/unittests/test_views.py b/jenkinsapi_tests/unittests/test_views.py index 27acca4..5f0da2a 100644 --- a/jenkinsapi_tests/unittests/test_views.py +++ b/jenkinsapi_tests/unittests/test_views.py @@ -35,7 +35,7 @@ class TestViews(unittest.TestCase): new_view = J.views.create('NewView') self.assertTrue(isinstance(new_view, View)) - self.assertEquals(new_view.baseurl, + self.assertEqual(new_view.baseurl, 'http://localhost:8080/views/NewView') def test_create_existing_view(self): diff --git a/jenkinsapi_utils/jenkins_launcher.py b/jenkinsapi_utils/jenkins_launcher.py index 785ff93..82b1939 100644 --- a/jenkinsapi_utils/jenkins_launcher.py +++ b/jenkinsapi_utils/jenkins_launcher.py @@ -1,7 +1,7 @@ import os import time try: - import Queue + import queue except ImportError: import queue as Queue import random @@ -14,7 +14,7 @@ import threading import subprocess from pkg_resources import resource_string try: - from urlparse import urlparse + from urllib.parse import urlparse except ImportError: from urllib.parse import urlparse @@ -69,7 +69,7 @@ class JenkinsLancher(object): self.war_directory, self.war_filename = os.path.split(self.war_path) self.jenkins_home = tempfile.mkdtemp(prefix='jenkins-home-') self.jenkins_process = None - self.q = Queue.Queue() + self.q = queue.Queue() self.plugin_urls = plugin_urls or [] def update_war(self): @@ -168,7 +168,7 @@ class JenkinsLancher(object): # Python 3.x if isinstance(line, bytes): line = line.decode('UTF-8') - except Queue.Empty: + except queue.Empty: log.warn("Input ended unexpectedly") break else: diff --git a/jenkinsapi_utils/simple_post_logger.py b/jenkinsapi_utils/simple_post_logger.py index f5be1ab..986dd89 100644 --- a/jenkinsapi_utils/simple_post_logger.py +++ b/jenkinsapi_utils/simple_post_logger.py @@ -1,18 +1,18 @@ -from __future__ import print_function -import SimpleHTTPServer -import SocketServer + +import http.server +import socketserver import logging import cgi PORT = 8080 -class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): +class ServerHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): logging.error(self.headers) - SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) + http.server.SimpleHTTPRequestHandler.do_GET(self) def do_POST(self): logging.error(self.headers) @@ -24,11 +24,11 @@ class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): }) for item in form.list: logging.error(item) - SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self) + http.server.SimpleHTTPRequestHandler.do_GET(self) Handler = ServerHandler -httpd = SocketServer.TCPServer(("", PORT), Handler) +httpd = socketserver.TCPServer(("", PORT), Handler) print("serving at port", PORT) httpd.serve_forever() diff --git a/release.sh b/release.sh index 95d46ed..df1e92a 100755 --- a/release.sh +++ b/release.sh @@ -1,7 +1,7 @@ -pip install wheel -pip install mock -pip install coverage -pip install sphinx +pip3 install wheel +pip3 install mock +pip3 install coverage +pip3 install sphinx ant release git tag v`jenkinsapi_version` ant doc diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a5c7e95 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +pytz>=2014.4 +requests>=2.3.0 +six>=1.10.0 + diff --git a/setup.cfg b/setup.cfg index f0cc800..4fb8a15 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,43 @@ +[metadata] +name = jenkinsapi +author = Salim Fadhley, Aleksey Maksimov +author_email = salimfadhley@gmail.com, ctpeko3a@gmail.com +summary = A Python API for accessing resources on a Jenkins continuous-integration server. +description-file = README.rst +license = MIT +classifier = + Development Status :: 4 - Beta + Environment :: Console + Intended Audience :: Developers + Intended Audience :: Information Technology + Intended Audience :: System Administrators + License :: OSI Approved :: MIT License + Natural Language :: English + Operating System :: OS Independent + Operating System :: OS Independent + Programming Language :: Python + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.4 + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 + Topic :: Software Development :: Testing + Topic :: Utilities + +[files] +packages = + jenkinsapi + jenkinsapi_utils + +[pbr] +warnerrors = True + +[entry_points] +console_scripts = + jenkins_invoke=jenkinsapi.command_line.jenkins_invoke:main + jenkinsapi_version=jenkinsapi.command_line.jenkinsapi_version:main + [build_sphinx] source-dir = doc/source build-dir = doc/build @@ -6,7 +46,15 @@ all_files = 1 [upload_sphinx] upload-dir = doc/build/html -[nosetests] -detailed-errors = 1 -with-coverage = 1 -cover-package = jenkinsapi \ No newline at end of file +[bdist_wheel] +universal = 1 + +[pycodestyle] +exclude = .tox,doc/source/conf.py,build,.venv,.eggs +max-line-length = 99 + +[egg_info] +tag_build = +tag_date = 0 + + diff --git a/setup.py b/setup.py index 765a57a..8674709 100644 --- a/setup.py +++ b/setup.py @@ -1,49 +1,7 @@ from setuptools import setup -import os -PROJECT_ROOT, _ = os.path.split(__file__) -REVISION = '0.2.26' -PROJECT_NAME = 'JenkinsAPI' -PROJECT_AUTHORS = "Salim Fadhley, Aleksey Maksimov" -# Please see readme.rst for a complete list of contributors -PROJECT_EMAILS = 'salimfadhley@gmail.com, ctpeko3a@gmail.com' -PROJECT_URL = "https://github.com/salimfadhley/jenkinsapi" -SHORT_DESCRIPTION = 'A Python API for accessing resources on a Jenkins continuous-integration server.' - -try: - DESCRIPTION = open(os.path.join(PROJECT_ROOT, "README.rst")).read() -except IOError: - DESCRIPTION = SHORT_DESCRIPTION - -GLOBAL_ENTRY_POINTS = { - "console_scripts": ["jenkins_invoke=jenkinsapi.command_line.jenkins_invoke:main", - "jenkinsapi_version=jenkinsapi.command_line.jenkinsapi_version:main"] -} setup( - name=PROJECT_NAME.lower(), - version=REVISION, - author=PROJECT_AUTHORS, - author_email=PROJECT_EMAILS, - packages=['jenkinsapi', 'jenkinsapi.utils', 'jenkinsapi.command_line', 'jenkinsapi_tests'], - zip_safe=True, - include_package_data=False, - install_requires=['requests>=2.3.0', 'pytz>=2014.4'], - test_suite='nose.collector', - tests_require=['mock', 'nose', 'coverage', 'unittest2'], - entry_points=GLOBAL_ENTRY_POINTS, - url=PROJECT_URL, - description=SHORT_DESCRIPTION, - long_description=DESCRIPTION, - license='MIT', - classifiers=[ - 'Development Status :: 4 - Beta', - 'Environment :: Console', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Natural Language :: English', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2.7', - 'Topic :: Software Development :: Testing', - ], -) + setup_requires=['pbr'], + pbr=True) + -- 2.34.1