Merge "Ensure tests run with ConfigParser object"

This commit is contained in:
Jenkins 2015-08-26 06:53:17 +00:00 committed by Gerrit Code Review
commit 6fd8c4ec0e
7 changed files with 33 additions and 20 deletions

View File

@ -36,6 +36,8 @@ try:
from unittest import mock
except ImportError:
import mock # noqa
from jenkins_jobs.cmd import DEFAULT_CONF
import jenkins_jobs.local_yaml as yaml
from jenkins_jobs.parser import YamlParser
from jenkins_jobs.xml_config import XmlJob
@ -119,15 +121,19 @@ class BaseTestCase(object):
yaml_content = yaml.load(yaml_file)
return yaml_content
def _get_config(self):
config = configparser.ConfigParser()
config.readfp(StringIO(DEFAULT_CONF))
if self.conf_filename is not None:
with io.open(self.conf_filename, 'r', encoding='utf-8') as cf:
config.readfp(cf)
return config
def test_yaml_snippet(self):
if not self.in_filename:
return
if self.conf_filename is not None:
config = configparser.ConfigParser()
config.readfp(io.open(self.conf_filename, 'r', encoding='utf-8'))
else:
config = {}
config = self._get_config()
expected_xml = self._read_utf8_content()
yaml_content = self._read_yaml_content(self.in_filename)
@ -178,13 +184,10 @@ class BaseTestCase(object):
class SingleJobTestCase(BaseTestCase):
def test_yaml_snippet(self):
config = self._get_config()
expected_xml = self._read_utf8_content()
if self.conf_filename:
config = configparser.ConfigParser()
config.readfp(io.open(self.conf_filename, 'r', encoding='utf-8'))
else:
config = None
parser = YamlParser(config)
parser.parse(self.in_filename)

View File

@ -0,0 +1,5 @@
[hipchat]
authtoken=blue
send-as=Jenkins
[jenkins]
url=green

View File

@ -14,8 +14,8 @@
</properties>
<publishers>
<jenkins.plugins.hipchat.HipChatNotifier>
<jenkinsUrl>url</jenkinsUrl>
<authToken>authtoken</authToken>
<jenkinsUrl>green</jenkinsUrl>
<authToken>blue</authToken>
<room/>
</jenkins.plugins.hipchat.HipChatNotifier>
</publishers>

View File

@ -0,0 +1,5 @@
[hipchat]
authtoken=blue
send-as=Jenkins
[jenkins]
url=green

View File

@ -8,8 +8,8 @@
</properties>
<publishers>
<jenkins.plugins.hipchat.HipChatNotifier>
<jenkinsUrl>url</jenkinsUrl>
<authToken>authtoken</authToken>
<jenkinsUrl>green</jenkinsUrl>
<authToken>blue</authToken>
<room/>
</jenkins.plugins.hipchat.HipChatNotifier>
</publishers>

View File

@ -14,9 +14,9 @@
</properties>
<publishers>
<jenkins.plugins.hipchat.HipChatNotifier>
<buildServerUrl>url</buildServerUrl>
<sendAs>send-as</sendAs>
<authToken>authtoken</authToken>
<buildServerUrl>http://localhost:8080/</buildServerUrl>
<sendAs>Jenkins</sendAs>
<authToken>dummy</authToken>
<room/>
</jenkins.plugins.hipchat.HipChatNotifier>
</publishers>

View File

@ -14,9 +14,9 @@
</properties>
<publishers>
<jenkins.plugins.hipchat.HipChatNotifier>
<buildServerUrl>url</buildServerUrl>
<sendAs>send-as</sendAs>
<authToken>authtoken</authToken>
<buildServerUrl>http://localhost:8080/</buildServerUrl>
<sendAs>Jenkins</sendAs>
<authToken>dummy</authToken>
<room/>
</jenkins.plugins.hipchat.HipChatNotifier>
</publishers>