How to use _get_value_type_name method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

zcl-compiler.py

Source:zcl-compiler.py Github

copy

Full Screen

...81 ctype = self.C_PRIMITIVE_TYPES_MAP.get(vtype, 'struct %s' % vtype)82 return ctype83 def _get_value_type(self, vtype):84 return self.C_PRIMITIVE_TYPES_MAP.get(vtype, 'struct %s' % vtype)85 def _get_value_type_name(self, vtype):86 return self.C_PRIMITIVE_TYPES_NAME_MAP.get(vtype, vtype)87 def add_struct(self, entity):88 fields = []89 for field in entity.fields:90 ctype = self._get_def_type(field)91 fields.append(' %-10s %s;%s/* %2d: %s %s */' % (ctype,92 field.name, spacing(28, field.name), field.uid, field.type(), field.default or ''))93 has_macros = []94 for fid, field in enumerate(entity.fields):95 has_macros.append('#define {ENTITY_NAME}_has_%s(msg) z_bitmap_test((msg)->{ENTITY_NAME}_fields_bitmap, %d)' % (field.name, fid))96 has_macros.append('#define {ENTITY_NAME}_set_%s(msg) z_bitmap_set((msg)->{ENTITY_NAME}_fields_bitmap, %d)' % (field.name, fid))97 fields_free = []98 fields_alloc = []99 parse_fields = []100 for fid, field in enumerate(entity.fields):101 ctype = self._get_def_value_type(field.vtype)102 rvars = {103 '{FIELD_UID}': field.uid,104 '{FIELD_VTYPE}': self._get_value_type_name(field.vtype),105 '{FIELD_CTYPE}': ctype,106 '{FIELD_NAME}': field.name,107 '{FIELD_BITMAP_ID}': fid,108 }109 if field.repeated:110 array_push = 'z_array_push_back_copy(&(msg->{FIELD_NAME}), &{FIELD_NAME})'111 rvars['{ARRAY_PUSH}'] = replace(array_push, rvars)112 fields_alloc.append(' z_array_open(&(msg->%s), sizeof(%s));' % (field.name, ctype))113 if field.vtype == 'bytes':114 parse_blob = """115 do {116 size_t i;117 for (i = 0; i < msg->{FIELD_NAME}.count; ++i) {118 {FIELD_CTYPE} *value = z_array_get(&(msg->{FIELD_NAME}), {FIELD_CTYPE}, i);119 z_bytes_ref_release(value);120 }121 } while (0);122"""123 fields_free.append(replace(parse_blob, rvars))124 fields_free.append(' z_array_close(&(msg->%s));' % field.name)125 parse_blob = """126 case {FIELD_UID}: { /* list[{FIELD_VTYPE}] {FIELD_NAME} */127 {FIELD_CTYPE} {FIELD_NAME};128 if (Z_UNLIKELY(length > sizeof({FIELD_CTYPE}))) return(-1);129 r = z_reader_decode_{FIELD_VTYPE}(reader, length, &{FIELD_NAME});130 if (Z_UNLIKELY(r)) return(-1);131 r = {ARRAY_PUSH};132 if (Z_UNLIKELY(r)) return(-1);133 z_bitmap_set(msg->{ENTITY_NAME}_fields_bitmap, {FIELD_BITMAP_ID});134 break;135 }136"""137 elif field.vtype in 'bytes':138 fields_alloc.append(' z_bytes_ref_reset(&(msg->%s));' % field.name)139 fields_free.append(' z_bytes_ref_release(&(msg->%s));' % field.name)140 parse_blob = """141 case {FIELD_UID}: { /* {FIELD_VTYPE} {FIELD_NAME} */142 if (Z_UNLIKELY(length > 1024)) return(-1);143 r = z_reader_decode_{FIELD_VTYPE}(reader, length, &(msg->{FIELD_NAME}));144 if (Z_UNLIKELY(r)) return(-1);145 z_bitmap_set(msg->{ENTITY_NAME}_fields_bitmap, {FIELD_BITMAP_ID});146 break;147 }148"""149 elif field.vtype in self.C_PRIMITIVE_TYPES_MAP:150 if field.default is not None:151 default_value = field.default.replace('false', '0').replace('true', '1')152 fields_alloc.append(' msg->%s = %s;' % (field.name, default_value))153 fields_alloc.append(' %s_set_%s(msg);' % (entity.name, field.name))154 parse_blob = """155 case {FIELD_UID}: { /* {FIELD_VTYPE} {FIELD_NAME} */156 if (Z_UNLIKELY(length > sizeof({FIELD_CTYPE}))) return(-1);157 r = z_reader_decode_{FIELD_VTYPE}(reader, length, &(msg->{FIELD_NAME}));158 if (Z_UNLIKELY(r)) return(-1);159 z_bitmap_set(msg->{ENTITY_NAME}_fields_bitmap, {FIELD_BITMAP_ID});160 break;161 }162"""163 else:164 fields_alloc.append(replace(' {FIELD_VTYPE}_alloc(&(msg->%s));' % field.name, rvars))165 fields_free.append(replace(' {FIELD_VTYPE}_free(&(msg->%s));' % field.name, rvars))166 parse_blob = """167 case {FIELD_UID}: { /* {FIELD_VTYPE} {FIELD_NAME} */168 r = {FIELD_VTYPE}_parse(&(msg->{FIELD_NAME}), reader, length);169 if (Z_UNLIKELY(r)) return(-1);170 z_bitmap_set(msg->{ENTITY_NAME}_fields_bitmap, {FIELD_BITMAP_ID});171 break;172 }173"""174 parse_fields.append(replace(parse_blob, rvars))175 dump_fields = []176 for field in entity.fields:177 if not field.vtype in self.C_PRIMITIVE_TYPES_MAP:178 continue179 ctype = self.C_PRIMITIVE_TYPES_MAP[field.vtype]180 if field.vtype == 'bytes':181 value_field = '&(msg->{FIELD_NAME})'182 repeated_field_value = 'value'183 else:184 value_field = 'msg->{FIELD_NAME}'185 repeated_field_value = '*value'186 rvars = {187 '{FIELD_UID}': field.uid,188 '{FIELD_VTYPE}': self._get_value_type_name(field.vtype),189 '{FIELD_CTYPE}': ctype,190 '{FIELD_NAME}': field.name,191 '{VALUE_FIELD}': value_field,192 '{REPEATED_FIELD_VALUE}': repeated_field_value,193 }194 parse_blob = """195 fprintf(stream, "\\n {FIELD_UID}: {FIELD_VTYPE} {FIELD_NAME} = ");196 if ({ENTITY_NAME}_has_{FIELD_NAME}(msg)) {197"""198 if field.repeated:199 array_get = 'z_array_get(&(msg->{FIELD_NAME}), {FIELD_CTYPE}, i)'200 rvars['{ARRAY_GET}'] = replace(array_get, rvars)201 parse_blob += """202 size_t i;203 for (i = 0; i < msg->{FIELD_NAME}.count; ++i) {204 const {FIELD_CTYPE} *value = {ARRAY_GET};205 fprintf(stream, "[%zu]", i);206 z_dump_{FIELD_VTYPE}(stream, {REPEATED_FIELD_VALUE});207 }208"""209 else:210 parse_blob += " z_dump_{FIELD_VTYPE}(stream, {VALUE_FIELD});"211 parse_blob += """212 } else {213 fprintf(stream, "MISSING");214 }215"""216 dump_fields.append(replace(parse_blob, rvars))217 all_fields_write = []218 all_fields_size = []219 for field in entity.fields:220 ctype = self._get_value_type(field.vtype)221 if field.vtype == 'bytes':222 value_field = '&(msg->{FIELD_NAME})'223 repeated_field_value = 'value'224 else:225 value_field = 'msg->{FIELD_NAME}'226 repeated_field_value = '*value'227 rvars = {228 '{FIELD_UID}': field.uid,229 '{FIELD_VTYPE}': self._get_value_type_name(field.vtype),230 '{FIELD_CTYPE}': ctype,231 '{FIELD_NAME}': field.name,232 '{FIELD_BITMAP_ID}': fid,233 '{VALUE_FIELD}': value_field,234 '{REPEATED_FIELD_VALUE}': repeated_field_value,235 }236 if field.repeated:237 array_get = 'z_array_get(&(msg->{FIELD_NAME}), {FIELD_CTYPE}, i)'238 rvars['{ARRAY_GET}'] = replace(array_get, rvars)239 # TODO WRITE struct240 parse_blob_write = """241 if ({ENTITY_NAME}_has_{FIELD_NAME}(msg)) {242 size_t i;243 for (i = 0; i < msg->{FIELD_NAME}.count; ++i) {...

Full Screen

Full Screen

types_.py

Source:types_.py Github

copy

Full Screen

...27 if self.value_matcher:28 ret += " that %s" % self.value_matcher.build_description(MatcherDescriptionTransformer(conjugate=True))29 return ret30 @staticmethod31 def _get_value_type_name(value):32 try:33 return _TYPE_NAMES[type(value)]34 except KeyError:35 return str(type(value))36 def matches(self, actual):37 if type(actual) in self.types:38 if self.value_matcher:39 return self.value_matcher.matches(actual)40 else:41 return MatchResult.success("got %s" % jsonify(actual))42 else:43 return MatchResult.failure("got %s (%s)" % (jsonify(actual), self._get_value_type_name(actual)))44def _is_type(types, type_name):45 def wrapper(value_matcher=None):46 return IsValueOfType(47 types, type_name, is_(value_matcher) if value_matcher is not None else None48 )49 wrapper.__doc__ = "Test if value is of type %s" % type_name50 return wrapper51is_integer = _is_type([int], "an integer")52is_float = _is_type([float], "a float")53is_bool = _is_type([bool], "a boolean")54is_str = _is_type(STRING_TYPES, "a string")55is_dict = _is_type([dict], "a collection")...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful