def test_invalid_values(self): with self.assertRaises(ValueError): statedict.validate_statedict({'foo': {}}) with self.assertRaises(ValueError): statedict.validate_statedict({'foo': object()}) with self.assertRaises(ValueError): statedict.validate_statedict({'foo': [object()]}) with self.assertRaises(ValueError): statedict.validate_statedict({'foo': (object(),)}) with self.assertRaises(ValueError): statedict.validate_statedict({'foo': "föö".encode('utf-8')})
def cached_sdict(self): status = self.sdict() try: validate_statedict(status) except ValueError as e: raise ValueError( _("{item} from bundle '{bundle}' returned invalid status: {msg}").format( bundle=self.bundle.name, item=self.id, msg=repr(e) ) ) return status
def cached_sdict(self): status = self.sdict() try: validate_statedict(status) except ValueError as e: raise ValueError( _("{item} from bundle '{bundle}' returned invalid status: {msg}" ).format( bundle=self.bundle.name, item=self.id, msg=repr(e), )) return status
def cached_cdict(self): if self._faults_missing_for_attributes: self._raise_for_faults() cdict = self.cdict() try: validate_statedict(cdict) except ValueError as e: raise ValueError( _("{item} from bundle '{bundle}' returned invalid cdict: {msg}").format( bundle=self.bundle.name, item=self.id, msg=repr(e) ) ) return cdict
def cached_cdict(self): if self._faults_missing_for_attributes: self._raise_for_faults() cdict = self.cdict() try: validate_statedict(cdict) except ValueError as e: raise ValueError( _("{item} from bundle '{bundle}' returned invalid cdict: {msg}" ).format( bundle=self.bundle.name, item=self.id, msg=repr(e), )) return cdict
def test_invalid_keys(self): with self.assertRaises(ValueError): statedict.validate_statedict({1: 2}) with self.assertRaises(ValueError): statedict.validate_statedict({1.0: 2}) with self.assertRaises(ValueError): statedict.validate_statedict({True: 2}) with self.assertRaises(ValueError): statedict.validate_statedict({None: 2}) with self.assertRaises(ValueError): statedict.validate_statedict({(): 2}) with self.assertRaises(ValueError): statedict.validate_statedict({object(): 2})
def test_ok(self): statedict.validate_statedict(EXAMPLE_SDICT)