Commit 81fc69e1 authored by Jim Fulton's avatar Jim Fulton

Allow bytes units for large_record_size

parent dc8cb352
...@@ -23,6 +23,9 @@ connection_parameters = ''' ...@@ -23,6 +23,9 @@ connection_parameters = '''
historical_timeout large_record_size historical_timeout large_record_size
'''.strip().split() '''.strip().split()
bytes_parameters = (
'cache_size_bytes', 'historical_cache_size_bytes', 'large_record_size')
parameters = dict(database_name = 'database_name') parameters = dict(database_name = 'database_name')
for parameter in connection_parameters: for parameter in connection_parameters:
parameters['connection_' + parameter] = parameter parameters['connection_' + parameter] = parameter
...@@ -47,7 +50,7 @@ def _get_dbkw(kw): ...@@ -47,7 +50,7 @@ def _get_dbkw(kw):
if parameter in kw: if parameter in kw:
v = kw.pop(parameter) v = kw.pop(parameter)
if parameter.startswith('connection_'): if parameter.startswith('connection_'):
if parameter.endswith('_bytes'): if parameters[parameter] in bytes_parameters:
v = _parse_bytes(v) v = _parse_bytes(v)
else: else:
v = int(v) v = int(v)
......
...@@ -461,7 +461,7 @@ class TestZConfigURIResolver(unittest.TestCase): ...@@ -461,7 +461,7 @@ class TestZConfigURIResolver(unittest.TestCase):
'database_name': 'foo'}) 'database_name': 'foo'})
def test_database_all_options(self): def test_database_all_options(self):
from zodburi import connection_parameters from zodburi import connection_parameters, bytes_parameters
self.tmp.write((""" self.tmp.write(("""
<zodb x> <zodb x>
<mappingstorage> <mappingstorage>
...@@ -471,7 +471,7 @@ class TestZConfigURIResolver(unittest.TestCase): ...@@ -471,7 +471,7 @@ class TestZConfigURIResolver(unittest.TestCase):
</zodb> </zodb>
""" % '\n'.join("%s %s" % ( """ % '\n'.join("%s %s" % (
name.replace('_', '-'), name.replace('_', '-'),
'%sMB' % i if name.endswith('_bytes') else i, '%sMB' % i if name in bytes_parameters else i,
) )
for (i, name) for (i, name)
in enumerate(connection_parameters) in enumerate(connection_parameters)
...@@ -484,10 +484,10 @@ class TestZConfigURIResolver(unittest.TestCase): ...@@ -484,10 +484,10 @@ class TestZConfigURIResolver(unittest.TestCase):
self.assertTrue(isinstance(storage, MappingStorage)) self.assertTrue(isinstance(storage, MappingStorage))
expect = dict(database_name='foo') expect = dict(database_name='foo')
for i, parameter in enumerate(connection_parameters): for i, parameter in enumerate(connection_parameters):
parameter = 'connection_' + parameter cparameter = 'connection_' + parameter
expect[parameter] = i expect[cparameter] = i
if parameter.endswith('_bytes'): if parameter in bytes_parameters:
expect[parameter] *= 1<<20 expect[cparameter] *= 1<<20
self.assertEqual(dbkw, expect) self.assertEqual(dbkw, expect)
class TestMappingStorageURIResolver(Base, unittest.TestCase): class TestMappingStorageURIResolver(Base, unittest.TestCase):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment