示例#1
0
 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')})
示例#2
0
 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
示例#3
0
 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
示例#4
0
    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
示例#5
0
    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
示例#6
0
 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})
示例#7
0
 def test_ok(self):
     statedict.validate_statedict(EXAMPLE_SDICT)