Fix cStringIO usage

Change cStringIO.StringIO() to cStringIO().

Change-Id: Ic72fd2d650bdd656d8b0145f1c347f5b79e1d1ec
Closes-Bug: #1596074
This commit is contained in:
Deklan Dieterly 2016-06-24 13:59:27 -06:00
parent 5c9acf916d
commit 196a93e1af
2 changed files with 12 additions and 5 deletions

View File

@ -85,7 +85,7 @@ def ini_parse(lines):
:return:
"""
try:
fd = cStringIO.StringIO(lines)
fd = cStringIO(lines)
parser = configparser.ConfigParser()
parser.readfp(fd)
return dict(parser.items('default'))

View File

@ -42,7 +42,7 @@ class TestConfig(unittest.TestCase):
user = openstack
password = 'aNiceQuotedPassword'
password2 = "aNiceQuotedPassword"
spaced = value"""
spaced = value"""
res = config.ini_parse(string)
self.assertEqual('127.0.0.1', res['host'])
@ -61,12 +61,19 @@ class TestConfig(unittest.TestCase):
user = openstack
password = 'aNiceQuotedPassword'
password2 = "aNiceQuotedPassword"
spaced = value"""
spaced = value"""
res = config.ini_parse(string)
self.assertEqual('127.0.0.1', res['host'])
self.assertEqual('openstack', res['user'])
self.assertEqual('3306', res['port'])
self.assertEqual('aNiceQuotedPassword', res['password'])
self.assertEqual('aNiceQuotedPassword', res['password2'])
# python 3.4 tests will fail because aNiceQuatedPassword will
# be quoted like "'aNiceQuotedPassword'" and '"aNiceQuotedPassword"'.
# Solution for now is to strip the inside quotation marks.
self.assertEqual('aNiceQuotedPassword', res['password'].strip("\"")
.strip('\''))
self.assertEqual('aNiceQuotedPassword', res['password2'].strip("\"")
.strip('\''))
self.assertEqual('value', res['spaced'])