summaryrefslogtreecommitdiff
path: root/test/ext/test_mutable.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/ext/test_mutable.py')
-rw-r--r--test/ext/test_mutable.py49
1 files changed, 24 insertions, 25 deletions
diff --git a/test/ext/test_mutable.py b/test/ext/test_mutable.py
index 1d8208743..9ae28a7fc 100644
--- a/test/ext/test_mutable.py
+++ b/test/ext/test_mutable.py
@@ -13,10 +13,10 @@ class _MutableDictTestBase(object):
@classmethod
def _type_fixture(cls):
from sqlalchemy.ext.mutable import Mutable
-
+
# needed for pickle support
global MutationDict
-
+
class MutationDict(Mutable, dict):
@classmethod
def coerce(cls, key, value):
@@ -26,27 +26,27 @@ class _MutableDictTestBase(object):
return Mutable.coerce(key, value)
else:
return value
-
+
def __getstate__(self):
return dict(self)
-
+
def __setstate__(self, dict):
self.update(dict)
-
+
def __setitem__(self, key, value):
dict.__setitem__(self, key, value)
self.change()
-
+
def __delitem__(self, key):
dict.__delitem__(self, key)
self.change()
return MutationDict
-
+
@testing.resolve_artifact_names
def setup_mappers(cls):
class Foo(_base.BasicEntity):
pass
-
+
mapper(Foo, foo)
def teardown(self):
@@ -54,7 +54,7 @@ class _MutableDictTestBase(object):
Mapper.dispatch._clear()
ClassManager.dispatch._clear()
super(_MutableDictTestBase, self).teardown()
-
+
@testing.resolve_artifact_names
def test_in_place_mutation(self):
sess = Session()
@@ -85,16 +85,16 @@ class MutableWithScalarPickleTest(_MutableDictTestBase, _base.MappedTest):
@classmethod
def define_tables(cls, metadata):
MutationDict = cls._type_fixture()
-
+
Table('foo', metadata,
Column('id', Integer, primary_key=True, test_needs_pk=True),
Column('data', MutationDict.as_mutable(PickleType)),
Column('non_mutable_data', PickleType)
)
-
+
def test_non_mutable(self):
self._test_non_mutable()
-
+
class MutableWithScalarJSONTest(_MutableDictTestBase, _base.MappedTest):
# json introduced in 2.6
__skip_if__ = lambda : sys.version_info < (2, 6),
@@ -116,7 +116,7 @@ class MutableWithScalarJSONTest(_MutableDictTestBase, _base.MappedTest):
if value is not None:
value = json.loads(value)
return value
-
+
MutationDict = cls._type_fixture()
Table('foo', metadata,
@@ -133,7 +133,7 @@ class MutableAssociationScalarPickleTest(_MutableDictTestBase, _base.MappedTest)
def define_tables(cls, metadata):
MutationDict = cls._type_fixture()
MutationDict.associate_with(PickleType)
-
+
Table('foo', metadata,
Column('id', Integer, primary_key=True, test_needs_pk=True),
Column('data', PickleType)
@@ -163,12 +163,12 @@ class MutableAssociationScalarJSONTest(_MutableDictTestBase, _base.MappedTest):
MutationDict = cls._type_fixture()
MutationDict.associate_with(JSONEncodedDict)
-
+
Table('foo', metadata,
Column('id', Integer, primary_key=True, test_needs_pk=True),
Column('data', JSONEncodedDict)
)
-
+
class MutableCompositesTest(_base.MappedTest):
@classmethod
def define_tables(cls, metadata):
@@ -186,12 +186,12 @@ class MutableCompositesTest(_base.MappedTest):
@classmethod
def _type_fixture(cls):
-
+
from sqlalchemy.ext.mutable import Mutable
from sqlalchemy.ext.mutable import MutableComposite
-
+
global Point
-
+
class Point(MutableComposite):
def __init__(self, x, y):
self.x = x
@@ -200,24 +200,24 @@ class MutableCompositesTest(_base.MappedTest):
def __setattr__(self, key, value):
object.__setattr__(self, key, value)
self.change()
-
+
def __composite_values__(self):
return self.x, self.y
-
+
def __eq__(self, other):
return isinstance(other, Point) and \
other.x == self.x and \
other.y == self.y
return Point
-
+
@classmethod
@testing.resolve_artifact_names
def setup_mappers(cls):
Point = cls._type_fixture()
-
+
class Foo(_base.BasicEntity):
pass
-
+
mapper(Foo, foo, properties={
'data':composite(Point, foo.c.x, foo.c.y)
})
@@ -235,4 +235,3 @@ class MutableCompositesTest(_base.MappedTest):
eq_(f1.data, Point(3, 5))
- \ No newline at end of file