Minimal test of Server Options Handling
=======================================

This is initially motivated by a desire to remove the requirement of
specifying a storage name when there is only one storage.

Storage Names
-------------

It is an error not to specify any storages:

    >>> import StringIO, sys, ZEO.runzeo
    >>> stderr = sys.stderr

    >>> open('config', 'w').write("""
    ... <zeo>
    ...     address 8100
    ... </zeo>
    ... """)
    
    >>> sys.stderr = StringIO.StringIO() 
    >>> options = ZEO.runzeo.ZEOOptions()
    >>> options.realize('-C config'.split())
    Traceback (most recent call last):
    ...
    SystemExit: 2

    >>> print sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    Error: not enough values for section type 'zodb.storage';
     0 found, 1 required
    ...


But we can specify a storage without a name:

    >>> open('config', 'w').write("""
    ... <zeo>
    ...     address 8100
    ... </zeo>
    ... <mappingstorage>
    ... </mappingstorage>
    ... """)
    >>> options = ZEO.runzeo.ZEOOptions()
    >>> options.realize('-C config'.split())
    >>> [storage.name for storage in options.storages]
    ['1']

We can't have multiple unnamed storages:

    >>> sys.stderr = StringIO.StringIO() 
    >>> open('config', 'w').write("""
    ... <zeo>
    ...     address 8100
    ... </zeo>
    ... <mappingstorage>
    ... </mappingstorage>
    ... <mappingstorage>
    ... </mappingstorage>
    ... """)
    >>> options = ZEO.runzeo.ZEOOptions()
    >>> options.realize('-C config'.split())
    Traceback (most recent call last):
    ...
    SystemExit: 2

    >>> print sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    Error: No more than one storage may be unnamed.
    ...

Or an unnamed storage and one named '1':

    >>> sys.stderr = StringIO.StringIO() 
    >>> open('config', 'w').write("""
    ... <zeo>
    ...     address 8100
    ... </zeo>
    ... <mappingstorage>
    ... </mappingstorage>
    ... <mappingstorage 1>
    ... </mappingstorage>
    ... """)
    >>> options = ZEO.runzeo.ZEOOptions()
    >>> options.realize('-C config'.split())
    Traceback (most recent call last):
    ...
    SystemExit: 2

    >>> print sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    Error: Can't have an unnamed storage and a storage named 1.
    ...

But we can have multiple storages:

    >>> open('config', 'w').write("""
    ... <zeo>
    ...     address 8100
    ... </zeo>
    ... <mappingstorage x>
    ... </mappingstorage>
    ... <mappingstorage y>
    ... </mappingstorage>
    ... """)
    >>> options = ZEO.runzeo.ZEOOptions()
    >>> options.realize('-C config'.split())
    >>> [storage.name for storage in options.storages]
    ['x', 'y']

As long as the names are unique:

    >>> sys.stderr = StringIO.StringIO() 
    >>> open('config', 'w').write("""
    ... <zeo>
    ...     address 8100
    ... </zeo>
    ... <mappingstorage 1>
    ... </mappingstorage>
    ... <mappingstorage 1>
    ... </mappingstorage>
    ... """)
    >>> options = ZEO.runzeo.ZEOOptions()
    >>> options.realize('-C config'.split())
    Traceback (most recent call last):
    ...
    SystemExit: 2

    >>> print sys.stderr.getvalue() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
    Error: section names must not be re-used within the same container:'1'
    ...

.. Cleanup =====================================================

    >>> sys.stderr = stderr
