moin-2.0 / build / lib / MoinMoin / storage / middleware / _tests /

# Copyright: 2011 MoinMoin:RonnyPfannschmidt
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

MoinMoin - serializer / deserializer tests

from __future__ import absolute_import, division

from StringIO import StringIO

from ..indexing import IndexingMiddleware
from ..routing import Backend as RoutingBackend
from ..serialization import serialize, deserialize

from import MutableBackend
from import BytesStore, FileStore

contents = [
    (u'Foo', {'name': u'Foo'}, ''),
    (u'Foo', {'name': u'Foo'}, '2nd'),
    (u'Subdir', {'name': u'Subdir'}, ''),
    (u'Subdir/Foo', {'name': u'Subdir/Foo'}, ''),
    (u'Subdir/Bar', {'name': u'Subdir/Bar'}, ''),

scenarios = [
    ('Simple', ['']),
    ('Nested', ['', 'Subdir']),

def pytest_generate_tests(metafunc):
    metafunc.addcall(id='Simple->Simple', param=('Simple', 'Simple'))

def pytest_funcarg__source(request):
    # scenario
    return make_middleware(request)

def pytest_funcarg__target(request):
    # scenario
    return make_middleware(request)

def make_middleware(request):
    tmpdir = request.getfuncargvalue('tmpdir')
    # scenario

    meta_store = BytesStore()
    data_store = FileStore()
    _backend = MutableBackend(meta_store, data_store)
    mapping = [('', _backend)]
    backend = RoutingBackend(mapping)

    mw = IndexingMiddleware(index_dir=str(tmpdir/'foo'),
    return mw

def test_serialize_deserialize(source, target):
    i = 0
    for name, meta, data in contents:
        item = source['name']
        item.store_revision(dict(meta, mtime=i), StringIO(data))
        i += 1

    io = StringIO()
    serialize(source.backend, io)
    deserialize(io, target.backend)

    print sorted(source.backend)
    print sorted(target.backend)
    assert sorted(source.backend) == sorted(target.backend)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.