def dump_load(self, **data): s = dumps(data) restored = loads(s) eq_(len(data), len(restored)) eq_(data.keys(), restored.keys()) for key in data.keys(): eq_(data[key], restored[key])
def load(self, data): # FIXME: The type is deprecated. remove this if not hasattr(data, 'items'): data = serializer.loads(data) if "type" in data: data["task_type"] = data["type"] del data["type"] super(ProblemData, self).load(data)
def loads(self, data): try: if not hasattr(data, 'items'): data = serializer.loads(data) for field_name, value in data.items(): field = self._meta.get_field(field_name) setattr(self, field.attname, field.loads(value)) except (ValueError, KeyError) as e: raise self.InvalidObject(e)
def test_blankline_with_space(self): data = loads(' ') eq_(len(data), 0)
def test_blankline(self): data = loads('') eq_(len(data), 0)
def test_multiline_comment(self): data = loads('# foo\n bar\n baz') eq_(len(data), 0)
def test_comment(self): data = loads('# foo') eq_(len(data), 0)
def test_multiline(self): data = loads('multiline: foo\n bar\n baz') eq_(len(data), 1) eq_(data['multiline'], 'foo\nbar\nbaz')
def test_oneline(self): data = loads('oneline: foo') eq_(len(data), 1) eq_(data['oneline'], 'foo')
def test_none(self): data = loads('none: ') eq_(len(data), 1) eq_(data['none'], None)