Merge "Removed some deprecation warnings and enabled py35 on tox."

This commit is contained in:
Jenkins 2017-03-15 18:51:42 +00:00 committed by Gerrit Code Review
commit e91b31fad2
11 changed files with 53 additions and 36 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
.*.swp
*.egg
*.eggs
*.egg-info
*.pyc
.test

View File

@ -109,7 +109,8 @@ class JenkinsManager(object):
Jenkins instance.
"""
try:
plugins_list = self.jenkins.get_plugins_info()
plugins_list = self.jenkins.get_plugins().values()
except jenkins.JenkinsException as e:
if re.search("Connection refused", str(e)):
logger.warning(

View File

@ -106,8 +106,8 @@ class JenkinsJobs(object):
key = 'CTRL+Z'
else:
key = 'CTRL+D'
logger.warn("Reading configuration from STDIN. "
"Press %s to end input.", key)
logger.warning("Reading configuration from STDIN. "
"Press %s to end input.", key)
else:
# take list of paths
self.options.path = self.options.path.split(os.pathsep)

View File

@ -113,8 +113,8 @@ class JJBConfig(object):
if config_file_required:
raise JJBConfigException(CONFIG_REQUIRED_MESSAGE)
else:
logger.warn("Config file, {0}, not found. Using default "
"config values.".format(conf))
logger.warning("Config file, {0}, not found. Using "
"default config values.".format(conf))
if config_fp is not None:
if PY2:
@ -172,10 +172,10 @@ class JJBConfig(object):
# check the ignore_cache setting
if config.has_option('jenkins', 'ignore_cache'):
logging.warn("ignore_cache option should be moved to the "
"[job_builder] section in the config file, the "
"one specified in the [jenkins] section will be "
"ignored in the future")
logging.warning("ignore_cache option should be moved to the "
"[job_builder] section in the config file, the "
"one specified in the [jenkins] section will be "
"ignored in the future")
self.ignore_cache = config.getboolean('jenkins', 'ignore_cache')
elif config.has_option('job_builder', 'ignore_cache'):
self.ignore_cache = config.getboolean('job_builder',

View File

@ -365,10 +365,10 @@ class YamlIncludeRawEscape(YamlIncludeRaw):
def from_yaml(cls, loader, node):
data = YamlIncludeRaw.from_yaml(loader, node)
if isinstance(data, LazyLoader):
logger.warn("Replacing %s tag with %s since lazy loading means "
"file contents will not be deep formatted for "
"variable substitution.", cls.yaml_tag,
YamlIncludeRaw.yaml_tag)
logger.warning("Replacing %s tag with %s since lazy loading means "
"file contents will not be deep formatted for "
"variable substitution.", cls.yaml_tag,
YamlIncludeRaw.yaml_tag)
return data
else:
return loader.escape_callback(data)

View File

@ -56,13 +56,13 @@ def http_endpoint(registry, xml_parent, data):
'com.tikal.hudson.plugins.notification.'
'Endpoint')
supported_formats = ['JSON', 'XML']
format = data.get('format', 'JSON').upper()
if format not in supported_formats:
fmt = data.get('format', 'JSON').upper()
if fmt not in supported_formats:
raise JenkinsJobsException(
"format must be one of %s" %
", ".join(supported_formats))
else:
XML.SubElement(endpoint_element, 'format').text = format
XML.SubElement(endpoint_element, 'format').text = fmt
XML.SubElement(endpoint_element, 'protocol').text = 'HTTP'

View File

@ -747,7 +747,7 @@ def slack(registry, xml_parent, data):
plugin_ver = pkg_resources.parse_version(plugin_info.get('version', "0"))
if plugin_ver >= pkg_resources.parse_version("2.0"):
logger.warn(
logger.warning(
"properties section is not used with plugin version >= 2.0",
)

View File

@ -154,12 +154,12 @@ class YamlParser(object):
"named '{0}'. Missing indent?"
.format(n))
# allow any entry to specify an id that can also be used
id = dfn.get('id', dfn['name'])
if id in group:
_id = dfn.get('id', dfn['name'])
if _id in group:
self._handle_dups(
"Duplicate entry found in '{0}: '{1}' already "
"defined".format(fp.name, id))
group[id] = dfn
"defined".format(fp.name, _id))
group[_id] = dfn
self.data[cls] = group
def parse(self, fn):

View File

@ -203,9 +203,9 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase):
jenkins_jobs.builder.JenkinsManager.get_plugins_info
"""
@mock.patch('jenkins.Jenkins.get_plugins_info')
@mock.patch('jenkins.Jenkins.get_plugins')
def test_console_output_jenkins_connection_failure_warning(
self, get_plugins_info_mock):
self, get_plugins_mock):
"""
Run test mode and verify that failed Jenkins connection attempt
exception does not bubble out of cmd.main. Ideally, we would also test
@ -214,7 +214,7 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase):
suite.
"""
get_plugins_info_mock.side_effect = \
get_plugins_mock.side_effect = \
jenkins.JenkinsException("Connection refused")
with mock.patch('sys.stdout'):
try:
@ -226,9 +226,9 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase):
except:
pass # only care about jenkins.JenkinsException for now
@mock.patch('jenkins.Jenkins.get_plugins_info')
@mock.patch('jenkins.Jenkins.get_plugins')
def test_skip_plugin_retrieval_if_no_config_provided(
self, get_plugins_info_mock):
self, get_plugins_mock):
"""
Verify that retrieval of information from Jenkins instance about its
plugins will be skipped when run if no config file provided.
@ -237,10 +237,10 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase):
args = ['--conf', self.default_config_file, 'test',
os.path.join(self.fixtures_path, 'cmd-001.yaml')]
entry.JenkinsJobs(args)
self.assertFalse(get_plugins_info_mock.called)
self.assertFalse(get_plugins_mock.called)
@mock.patch('jenkins.Jenkins.get_plugins_info')
def test_skip_plugin_retrieval_if_disabled(self, get_plugins_info_mock):
def test_skip_plugin_retrieval_if_disabled(self, get_plugins_mock):
"""
Verify that retrieval of information from Jenkins instance about its
plugins will be skipped when run if a config file provided and disables
@ -253,7 +253,7 @@ class TestJenkinsGetPluginInfoError(CmdTestsBase):
'test',
os.path.join(self.fixtures_path, 'cmd-001.yaml')]
entry.JenkinsJobs(args)
self.assertFalse(get_plugins_info_mock.called)
self.assertFalse(get_plugins_mock.called)
class MatchesDirMissingFilesMismatch(object):

View File

@ -20,28 +20,42 @@ from tests import base
from tests.base import mock
_plugins_info = {}
_plugins_info['plugin1'] = {'longName': '',
'shortName': '',
'version': ''}
@mock.patch('jenkins_jobs.builder.JobCache', mock.MagicMock)
class TestCaseTestJenkinsManager(base.BaseTestCase):
def setUp(self):
super(TestCaseTestJenkinsManager, self).setUp()
self.jjb_config = JJBConfig()
self.jjb_config.validate()
def test_plugins_list(self):
self.jjb_config.builder['plugins_info'] = ['plugin1', 'plugin2']
self.jjb_config.builder['plugins_info'] = _plugins_info
self.builder = jenkins_jobs.builder.JenkinsManager(self.jjb_config)
self.assertEqual(self.builder.plugins_list, ['plugin1', 'plugin2'])
self.assertEqual(self.builder.plugins_list, _plugins_info)
@mock.patch.object(jenkins_jobs.builder.jenkins.Jenkins,
'get_plugins_info', return_value=['p1', 'p2'])
'get_plugins',
return_value=_plugins_info)
def test_plugins_list_from_jenkins(self, jenkins_mock):
# Trigger fetching the plugins from jenkins when accessing the property
self.jjb_config.builder['plugins_info'] = None
self.jjb_config.builder['plugins_info'] = {}
self.builder = jenkins_jobs.builder.JenkinsManager(self.jjb_config)
self.assertEqual(self.builder.plugins_list, ['p1', 'p2'])
# See https://github.com/formiaczek/multi_key_dict/issues/17
# self.assertEqual(self.builder.plugins_list, k)
for key_tuple in self.builder.plugins_list.keys():
for key in key_tuple:
self.assertEqual(self.builder.plugins_list[key],
_plugins_info[key])
def test_delete_managed(self):
self.jjb_config.builder['plugins_info'] = []
self.jjb_config.builder['plugins_info'] = {}
self.builder = jenkins_jobs.builder.JenkinsManager(self.jjb_config)
with mock.patch.multiple('jenkins_jobs.builder.JenkinsManager',

View File

@ -1,6 +1,7 @@
[tox]
minversion = 1.6
envlist = pep8, py34, py27
envlist = pep8, py34, py35, py27
skip_missing_interpreters = true
[testenv]
# Note(Vek): JJB is not compatible with a non-zero PYTHONHASHSEED