Up-rev hacking
And fix readfp to read_file and make sure it reads from the start of any filelike object. Change-Id: I8ecb3143536b9c97438af7b6b2797fb22768e7d3
This commit is contained in:

committed by
Matthew Oliver

parent
666fc883fa
commit
dee1430b42
@@ -322,7 +322,7 @@ class DistributedBenchController(object):
|
|||||||
self.logger = logger
|
self.logger = logger
|
||||||
# ... INFO 1000 PUTS **FINAL** [0 failures], 34.9/s
|
# ... INFO 1000 PUTS **FINAL** [0 failures], 34.9/s
|
||||||
self.final_re = re.compile(
|
self.final_re = re.compile(
|
||||||
'INFO (\d+) (.*) \*\*FINAL\*\* \[(\d+) failures\], (\d+\.\d+)/s')
|
r'INFO (\d+) (.*) \*\*FINAL\*\* \[(\d+) failures\], (\d+\.\d+)/s')
|
||||||
self.clients = conf.bench_clients
|
self.clients = conf.bench_clients
|
||||||
del conf.bench_clients
|
del conf.bench_clients
|
||||||
for key, minval in [('put_concurrency', 1),
|
for key, minval in [('put_concurrency', 1),
|
||||||
|
@@ -44,7 +44,10 @@ def readconf(conf_path, section_name=None, log_name=None, defaults=None,
|
|||||||
else:
|
else:
|
||||||
c = configparser.ConfigParser(defaults)
|
c = configparser.ConfigParser(defaults)
|
||||||
if hasattr(conf_path, 'readline'):
|
if hasattr(conf_path, 'readline'):
|
||||||
c.readfp(conf_path)
|
# make sure filelike is at the start of the file
|
||||||
|
if hasattr(conf_path, "seekable"):
|
||||||
|
conf_path.seek(0)
|
||||||
|
c.read_file(conf_path)
|
||||||
else:
|
else:
|
||||||
success = c.read(conf_path)
|
success = c.read(conf_path)
|
||||||
if not success:
|
if not success:
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
hacking>=0.10.0,<0.11
|
hacking>=7.0.0,<8.0.0
|
||||||
|
|
||||||
coverage>=3.6
|
coverage>=3.6
|
||||||
mock>=1.0
|
mock>=1.0
|
||||||
|
@@ -40,37 +40,33 @@ foo = bar
|
|||||||
|
|
||||||
[section2]
|
[section2]
|
||||||
log_name = yarr'''
|
log_name = yarr'''
|
||||||
# setup a real file
|
|
||||||
fd, temppath = tempfile.mkstemp(dir='/tmp')
|
fd, temppath = tempfile.mkstemp(dir='/tmp')
|
||||||
with os.fdopen(fd, 'w') as f:
|
with os.fdopen(fd, 'w') as f:
|
||||||
f.write(conf)
|
f.write(conf)
|
||||||
make_filename = lambda: temppath
|
# Test both a real file and a file-like object
|
||||||
# setup a file stream
|
for conffile in (temppath, io.StringIO(conf)):
|
||||||
make_fp = lambda: io.StringIO(conf)
|
|
||||||
for conf_object_maker in (make_filename, make_fp):
|
|
||||||
conffile = conf_object_maker()
|
|
||||||
result = utils.readconf(conffile)
|
result = utils.readconf(conffile)
|
||||||
expected = {'__file__': conffile,
|
expected = {'__file__': conffile,
|
||||||
'log_name': None,
|
'log_name': None,
|
||||||
'section1': {'foo': 'bar'},
|
'section1': {'foo': 'bar'},
|
||||||
'section2': {'log_name': 'yarr'}}
|
'section2': {'log_name': 'yarr'}}
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
conffile = conf_object_maker()
|
|
||||||
result = utils.readconf(conffile, 'section1')
|
result = utils.readconf(conffile, 'section1')
|
||||||
expected = {'__file__': conffile, 'log_name': 'section1',
|
expected = {'__file__': conffile, 'log_name': 'section1',
|
||||||
'foo': 'bar'}
|
'foo': 'bar'}
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
conffile = conf_object_maker()
|
|
||||||
result = utils.readconf(conffile,
|
result = utils.readconf(conffile,
|
||||||
'section2').get('log_name')
|
'section2').get('log_name')
|
||||||
expected = 'yarr'
|
expected = 'yarr'
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
conffile = conf_object_maker()
|
|
||||||
result = utils.readconf(conffile, 'section1',
|
result = utils.readconf(conffile, 'section1',
|
||||||
log_name='foo').get('log_name')
|
log_name='foo').get('log_name')
|
||||||
expected = 'foo'
|
expected = 'foo'
|
||||||
self.assertEqual(result, expected)
|
self.assertEqual(result, expected)
|
||||||
conffile = conf_object_maker()
|
|
||||||
result = utils.readconf(conffile, 'section1',
|
result = utils.readconf(conffile, 'section1',
|
||||||
defaults={'bar': 'baz'})
|
defaults={'bar': 'baz'})
|
||||||
expected = {'__file__': conffile, 'log_name': 'section1',
|
expected = {'__file__': conffile, 'log_name': 'section1',
|
||||||
@@ -86,15 +82,11 @@ foo = bar
|
|||||||
|
|
||||||
[section2]
|
[section2]
|
||||||
log_name = %(yarr)s'''
|
log_name = %(yarr)s'''
|
||||||
# setup a real file
|
|
||||||
fd, temppath = tempfile.mkstemp(dir='/tmp')
|
fd, temppath = tempfile.mkstemp(dir='/tmp')
|
||||||
with os.fdopen(fd, 'w') as f:
|
with os.fdopen(fd, 'w') as f:
|
||||||
f.write(conf)
|
f.write(conf)
|
||||||
make_filename = lambda: temppath
|
# Test both a real file and a file-like object
|
||||||
# setup a file stream
|
for conffile in (temppath, io.StringIO(conf)):
|
||||||
make_fp = lambda: io.StringIO(conf)
|
|
||||||
for conf_object_maker in (make_filename, make_fp):
|
|
||||||
conffile = conf_object_maker()
|
|
||||||
result = utils.readconf(conffile, raw=True)
|
result = utils.readconf(conffile, raw=True)
|
||||||
expected = {'__file__': conffile,
|
expected = {'__file__': conffile,
|
||||||
'log_name': None,
|
'log_name': None,
|
||||||
@@ -155,5 +147,6 @@ log_name = %(yarr)s'''
|
|||||||
with self.assertRaises(TypeError):
|
with self.assertRaises(TypeError):
|
||||||
utils.get_size_bytes(1)
|
utils.get_size_bytes(1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Reference in New Issue
Block a user