def test_tdict_notype(self): d = tdict() d[0] = 1 assert d[0] == 1 d = tdict() d.update({0:1}) assert d[0] == 1 d = tdict.fromkeys([0], 1) assert d[0] == 1
def test_tdict_v(self): d = tdict(vt=str) try: d[0] = 1 except TypeError: pass else: raise Exception("must fail") d = tdict(vt=str) d[0] = 's' assert d[0] == 's'
def test_tdict_k(self): d = tdict(str) try: d[0] = 1 except TypeError: pass else: raise Exception("must fail") d = tdict(str) d['s'] = 1 assert d['s'] == 1
def _gen_input_attrs_novalue(self, ctx, cls, name, cls_attrs, **kwargs): elt_class = oset([ camel_case_to_uscore(cls.get_type_name()), name.rsplit(self.hier_delim, 1)[-1], re.sub(r'\[[0-9]+\]', '', name).replace(self.hier_delim, '__'), ]) if self.input_class is not None: elt_class.add(self.input_class) elt_class = ' '.join(elt_class) elt_attrs = tdict(six.string_types, six.string_types, { 'id': self._gen_input_elt_id(name, **kwargs), 'name': self._gen_input_name(name), 'type': 'text', 'class': elt_class, }) if cls_attrs.pattern is not None: elt_attrs['pattern'] = cls_attrs.pattern if cls_attrs.read_only: elt_attrs['readonly'] = "" placeholder = cls_attrs.placeholder if placeholder is None: placeholder = self.placeholder if isinstance(placeholder, six.string_types): elt_attrs['placeholder'] = placeholder elif placeholder: elt_attrs['placeholder'] = self.trc(cls, ctx.locale, name) # Required bool means, in HTML context, a checkbox that needs to be # checked, which is not what we mean here at all. if not issubclass(cls, Boolean): # We used OR here because html forms send empty values anyway. So a # missing value is sent as null as well. if cls_attrs.min_occurs >= 1 or cls_attrs.nullable == False: elt_attrs['required'] = '' return elt_attrs