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:
Tim Burke
2025-02-26 16:21:35 -08:00
committed by Matthew Oliver
parent 666fc883fa
commit dee1430b42
4 changed files with 15 additions and 19 deletions

View File

@@ -322,7 +322,7 @@ class DistributedBenchController(object):
self.logger = logger
# ... INFO 1000 PUTS **FINAL** [0 failures], 34.9/s
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
del conf.bench_clients
for key, minval in [('put_concurrency', 1),

View File

@@ -44,7 +44,10 @@ def readconf(conf_path, section_name=None, log_name=None, defaults=None,
else:
c = configparser.ConfigParser(defaults)
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:
success = c.read(conf_path)
if not success:

View File

@@ -1,4 +1,4 @@
hacking>=0.10.0,<0.11
hacking>=7.0.0,<8.0.0
coverage>=3.6
mock>=1.0

View File

@@ -40,37 +40,33 @@ foo = bar
[section2]
log_name = yarr'''
# setup a real file
fd, temppath = tempfile.mkstemp(dir='/tmp')
with os.fdopen(fd, 'w') as f:
f.write(conf)
make_filename = lambda: temppath
# setup a file stream
make_fp = lambda: io.StringIO(conf)
for conf_object_maker in (make_filename, make_fp):
conffile = conf_object_maker()
# Test both a real file and a file-like object
for conffile in (temppath, io.StringIO(conf)):
result = utils.readconf(conffile)
expected = {'__file__': conffile,
'log_name': None,
'section1': {'foo': 'bar'},
'section2': {'log_name': 'yarr'}}
self.assertEqual(result, expected)
conffile = conf_object_maker()
result = utils.readconf(conffile, 'section1')
expected = {'__file__': conffile, 'log_name': 'section1',
'foo': 'bar'}
self.assertEqual(result, expected)
conffile = conf_object_maker()
result = utils.readconf(conffile,
'section2').get('log_name')
expected = 'yarr'
self.assertEqual(result, expected)
conffile = conf_object_maker()
result = utils.readconf(conffile, 'section1',
log_name='foo').get('log_name')
expected = 'foo'
self.assertEqual(result, expected)
conffile = conf_object_maker()
result = utils.readconf(conffile, 'section1',
defaults={'bar': 'baz'})
expected = {'__file__': conffile, 'log_name': 'section1',
@@ -86,15 +82,11 @@ foo = bar
[section2]
log_name = %(yarr)s'''
# setup a real file
fd, temppath = tempfile.mkstemp(dir='/tmp')
with os.fdopen(fd, 'w') as f:
f.write(conf)
make_filename = lambda: temppath
# setup a file stream
make_fp = lambda: io.StringIO(conf)
for conf_object_maker in (make_filename, make_fp):
conffile = conf_object_maker()
# Test both a real file and a file-like object
for conffile in (temppath, io.StringIO(conf)):
result = utils.readconf(conffile, raw=True)
expected = {'__file__': conffile,
'log_name': None,
@@ -155,5 +147,6 @@ log_name = %(yarr)s'''
with self.assertRaises(TypeError):
utils.get_size_bytes(1)
if __name__ == '__main__':
unittest.main()