Пример #1
0
"""Components for loading and unloading data using `Storm`_.

See :ref:`Using LoadableFixture<using-loadable-fixture>` for examples.

.. _Storm: https://storm.canonical.com/

"""

from fixture.loadable import DBLoadableFixture
from fixture.util import _mklog

stlog = _mklog('fixture.loadable.storm')

class StormMedium(DBLoadableFixture.StorageMediumAdapter):

    def clear(self, obj):
        self.transaction.remove(obj)

    def save(self, row, column_vals):
        from storm.info import get_cls_info
        from storm.locals import ReferenceSet, Store

        cls_info = get_cls_info(self.medium)

        column_vals = list(column_vals)
        pk = []
        for n, v in column_vals:
            propid = id(getattr(self.medium, n))
            if propid in cls_info.primary_key_idx:
                pk.append((cls_info.primary_key_idx[propid], v, n))
Пример #2
0
"""Components for loading and unloading data using `Storm`_.

See :ref:`Using LoadableFixture<using-loadable-fixture>` for examples.

.. _Storm: https://storm.canonical.com/

"""

from fixture.loadable import DBLoadableFixture
from fixture.util import _mklog

stlog = _mklog('fixture.loadable.storm')


class StormMedium(DBLoadableFixture.StorageMediumAdapter):
    def clear(self, obj):
        self.transaction.remove(obj)

    def save(self, row, column_vals):
        from storm.info import get_cls_info
        from storm.locals import ReferenceSet, Store

        cls_info = get_cls_info(self.medium)

        column_vals = list(column_vals)
        pk = []
        for n, v in column_vals:
            propid = id(getattr(self.medium, n))
            if propid in cls_info.primary_key_idx:
                pk.append((cls_info.primary_key_idx[propid], v, n))
Пример #3
0
.. api_only::
   The fixture.loadable module
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~

"""
# from __future__ import with_statement
import sys, types
from fixture.base import Fixture
from fixture.util import ObjRegistry, _mklog
from fixture.style import OriginalStyle
from fixture.dataset import Ref, dataset_registry, DataRow, is_rowlike
from fixture.exc import LoadError, UnloadError
import logging

log = _mklog("fixture.loadable")
treelog = _mklog("fixture.loadable.tree")


class LoadableFixture(Fixture):
    """knows how to load data into something useful.
    
    This is an abstract class and cannot be used directly.  You can use a 
    LoadableFixture that already knows how to load into a specific medium, 
    such as SQLAlchemyFixture, or create your own to build your own to load 
    DataSet objects into custom storage media.

    Keyword Arguments
    -----------------
    - dataclass
    
Пример #4
0
"""Abstract classes for :class:`fixture.base.Fixture` descendants that load / unload data

See :ref:`Using LoadableFixture<using-loadable-fixture>` for examples.

"""
# from __future__ import with_statement
__all__ = ['LoadableFixture', 'EnvLoadableFixture', 'DBLoadableFixture', 'DeferredStoredObject']
import sys, types
from fixture.base import Fixture
from fixture.util import ObjRegistry, _mklog
from fixture.style import OriginalStyle
from fixture.dataset import Ref, dataset_registry, DataRow, is_rowlike
from fixture.exc import UninitializedError, LoadError, UnloadError, StorageMediaNotFound
import logging

log     = _mklog("fixture.loadable")
treelog = _mklog("fixture.loadable.tree")

class StorageMediumAdapter(object):
    """common interface for working with storable objects.
    """
    def __init__(self, medium, dataset):
        self.medium = medium
        self.dataset = dataset
        self.transaction = None
    
    def __getattr__(self, name):
        return getattr(self.obj, name)
    
    def __repr__(self):
        return "%s at %s for %s" % (