~fluiddb-dev/storm/trunk

« back to all changes in this revision

Viewing changes to tests/variables.py

  • Committer: Jamu Kakar
  • Date: 2011-02-28 21:25:44 UTC
  • mfrom: (386.1.2 json-property)
  • Revision ID: jkakar@kakar.ca-20110228212544-rm0wpjhqzi3i09fs
- Merged json-property.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from decimal import Decimal
23
23
import cPickle as pickle
24
24
import gc
 
25
import json
25
26
import weakref
26
27
try:
27
28
    import uuid
825
826
        self.assertEquals(variable.get(), value)
826
827
 
827
828
 
828
 
class PickleVariableTest(TestHelper):
 
829
class EncodedValueVariableTestMixin(object):
 
830
 
 
831
    encoding = None
 
832
    variable_type = None
829
833
 
830
834
    def test_get_set(self):
831
835
        d = {"a": 1}
832
 
        d_dump = pickle.dumps(d, -1)
 
836
        d_dump = self.encoding.dumps(d, -1)
833
837
 
834
 
        variable = PickleVariable()
 
838
        variable = self.variable_type()
835
839
 
836
840
        variable.set(d)
837
841
        self.assertEquals(variable.get(), d)
853
857
    def test_pickle_events(self):
854
858
        event = EventSystem(marker)
855
859
 
856
 
        variable = PickleVariable(event=event, value_factory=list)
 
860
        variable = self.variable_type(event=event, value_factory=list)
857
861
 
858
862
        changes = []
859
863
        def changed(owner, variable, old_value, new_value, fromdb):
887
891
        self.assertEquals(changes, [(variable, None, ["a"], False)])
888
892
 
889
893
 
 
894
class PickleVariableTest(EncodedValueVariableTestMixin, TestHelper):
 
895
 
 
896
    encoding = pickle
 
897
    variable_type = PickleVariable
 
898
 
 
899
 
 
900
class JSONVariableTest(EncodedValueVariableTestMixin, TestHelper):
 
901
 
 
902
    encoding = json
 
903
    variable_type = JSONVariable
 
904
 
 
905
 
890
906
class ListVariableTest(TestHelper):
891
907
 
892
908
    def test_get_set(self):