How to use enum_keys method in tox

Best Python code snippet using tox_python

process_in.py

Source:process_in.py Github

copy

Full Screen

1import os2import pandac3from panda3d.interrogatedb import *4DBG = 05ENUM_KEYS = {}6undefined = object()7def translateTypeName(name, mangle=True):8 # Equivalent to C++ classNameFromCppName9 class_name = ""10 bad_chars = "!@#$%^&*()<>,.-=+~{}? "11 next_cap = False12 first_char = mangle13 for chr in name:14 if (chr == '_' or chr == ' ') and mangle:15 next_cap = True16 elif chr in bad_chars:17 if not mangle:18 class_name += '_'19 elif next_cap or first_char:20 class_name += chr.upper()21 next_cap = False22 first_char = False23 else:24 class_name += chr25 return class_name26def translated_type_name(type, scoped=True):27 while interrogate_type_is_wrapped(type):28 if interrogate_type_is_const(type):29 return 'const ' + translated_type_name(interrogate_type_wrapped_type(type))30 else:31 type = interrogate_type_wrapped_type(type)32 typename = interrogate_type_name(type)33 if typename in ("PyObject", "_object"):34 return "object"35 elif typename == "PN_stdfloat":36 return "float"37 elif typename == "size_t":38 return "int"39 if interrogate_type_is_atomic(type):40 token = interrogate_type_atomic_token(type)41 if token == 7:42 return 'str'43 elif token == 8:44 return 'long'45 elif token == 9:46 return 'NoneType'47 else:48 return typename49 if not typename.endswith('_t'):50 # Hack: don't mangle size_t etc.51 typename = translateTypeName(typename)52 if scoped and interrogate_type_is_nested(type):53 return translated_type_name(interrogate_type_outer_class(type)) + '::' + typename54 else:55 return typename56def process_enums(c, type, name, indent):57 global ENUM_KEYS, undefined58 enums = {}59 enums[name] = []60 docstrings = []61 for i_value in range(interrogate_type_number_of_enum_values(type)):62 docstring = interrogate_type_enum_value_comment(type, i_value)63 key = interrogate_type_enum_value_name(type, i_value)64 docstring = docstring.replace('// ', '')65 docstring = docstring.replace('\n', f"\n{' '*indent}# ")66 docstrings.append((key, docstring))67 value = interrogate_type_enum_value(type, i_value)68 if not name:69 print("ENUM ? : %s = %d" % (key,value) )70 else:71 enums[name].append((key, value))72 ENUM_KEYS.setdefault(key,value)73 if ENUM_KEYS[key] != value:74 ENUM_KEYS[key]= undefined75 enums[name].sort(key=lambda x: x[0])76 if DBG:77 if nesting:78 print(f"\n{' '*indent}class {name}:\n")79 else:80 print(f"\n{' '*indent}# {name}:\n")81 doc = 082 while len(docstrings):83 key, docstring = docstrings.pop(0)84 if docstring:85 doc = 186 if DBG:87 print(f"{' '*indent}# {key} : {docstring}")88 if doc:89 print()90 for (key, value) in enums[name]:91 print(f"{' '*(indent+nesting)}{key} = const({value})")92 if nesting:93 print(f"{' '*indent}{name}= {name}")94 c['enums'].update(enums)95def process_nested(c, type, name, indent=1):96 nesting = 097 if interrogate_type_is_enum(type):98 process_enums(c, type, name, indent)99def process_class(c, type, used_class):100 typename = translated_type_name(type, scoped=False)101 derivations = []102 for n in range(interrogate_type_number_of_derivations(type)):103 deriv = interrogate_type_get_derivation(type, n)104 ttn = translated_type_name(deriv)105 derivations.append(ttn)106 if not ttn in used_class:107 used_class.append(ttn)108 c['bases'].extend(list(derivations))109 if not len(derivations):110 derivations += ['cpp']111 if DBG:112 print()113 print(f"class {typename}({', '.join(derivations)}):")114 for i_ntype in range(interrogate_type_number_of_nested_types(type)):115 ntype = interrogate_type_get_nested_type(type, i_ntype)116 ntype_name = interrogate_type_name(ntype)117 process_nested(c, ntype, ntype_name)118# for i_method in range(interrogate_type_number_of_constructors(type)):119# ctor = interrogate_type_get_constructor(type, i_method)120# ctor_name = interrogate_function_name(ctor)121# print(' ctor:', ctor_name)122# for i_method in range(interrogate_type_number_of_methods(type)):123# print('processFunction(handle,', interrogate_type_get_method(type, i_method))124# for i_method in range(interrogate_type_number_of_make_seqs(type)):125# print('print("list", translateFunctionName(interrogate_make_seq_seq_name(interrogate_type_get_make_seq(type, i_method))), "();", file=handle)')126# for i_element in range(interrogate_type_number_of_elements(type)):127# elem = interrogate_type_get_element(type, i_element)128# elem_name = interrogate_element_name(elem)129# print('processElement(handle,', elem_name)130def process_in(fname, source):131 global ENUM_KEYS132 used_class = []133 interrogate_request_database(fname)134 for i_type in range(interrogate_number_of_global_types()):135 type = interrogate_get_global_type(i_type)136 cn = interrogate_type_name(type)137 decl = source['classes'].get(cn, None)138 if decl:139 process_class(decl, type, used_class)140 else:141 if interrogate_type_is_enum(type):142 # a global enum143 process_enums(source['classes'][''], type, cn, 0)144 for decl_class in source['classes'].keys():145 if decl_class in used_class:146 used_class.remove(decl_class)147 to_del = []148 for k, can_const in ENUM_KEYS.items():149 if can_const is not undefined:150 to_del.append(k)151 while len(to_del):152 ENUM_KEYS.pop(to_del.pop())153 source['no_const'] = list( ENUM_KEYS.keys() )154 if len(used_class):155 print("\nmissing def in .N :")156 for uc in used_class:157 print(f"forcetype {uc}")158 print()159# Determine the path to the interrogatedb files160pandac_dir = os.path.dirname(pandac.__file__)161interrogate_add_search_directory('.')...

Full Screen

Full Screen

enumeration.py

Source:enumeration.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2 # Taken fron http://djangosnippets.org/snippets/1647/3# Author: Dmitri Patrakov <traditio@gmail.com>45class Enumeration(object):6 """7 A small helper class for more readable enumerations,8 and compatible with Django's choice convention.9 You may just pass the instance of this class as the choices10 argument of model/form fields.1112 Example:13 MY_ENUM = Enumeration([14 (100, 'MY_NAME', 'My verbose name'),15 (200, 'MY_AGE', 'My verbose age'),16 ])17 assert MY_ENUM.MY_AGE == 10018 assert MY_ENUM[1] == (200, 'My verbose age')19 """2021 def __init__(self, enum_list):22 self.enum_keys = [(item[0], item[1]) for item in enum_list]23 self.enum_list = [(item[0], item[2]) for item in enum_list]24 self.enum_dict = {}25 for item in enum_list:26 self.enum_dict[item[1]] = item[0]27 28 def __contains__(self, v):29 return (v in self.enum_list)3031 def __len__(self):32 return len(self.enum_list)3334 def __getitem__(self, v):35 if isinstance(v, basestring):36 return self.enum_dict[v]37 elif isinstance(v, int):38 return self.enum_list[v]3940 def __getattr__(self, name):41 return self.enum_dict[name]4243 def insert(self, pos, item):44 self.enum_keys.insert(pos, (item[0], item[1]))45 self.enum_list.insert(pos, (item[0], item[2]))46 self.enum_dict[item[1]] = item[0]47 48 def append(self, item):49 self.enum_keys.append((item[0], item[1]))50 self.enum_list.append((item[0], item[2]))51 self.enum_dict[item[1]] = item[0]5253 def get_string(self, v):54 string_dict = dict(self.enum_list)55 try:56 if isinstance(v, basestring):57 return string_dict[self.enum_dict[v]]58 elif isinstance(v, int):59 return string_dict[v]60 except KeyError:61 return None6263 def get_key(self, v):64 key_dict = dict(self.enum_keys)65 return key_dict.get(v)6667 def get_value(self, v):68 return self.enum_dict.get(v)6970 def __iter__(self):71 return self.enum_list.__iter__()72 73 def values(self): 74 return [item[0] for item in self.enum_list] 75 76 def keys(self): 77 return [item[1] for item in self.enum_keys] 7879 def has_key(self, key):80 return key in self.keys()8182 def has_value(self, value):83 return value in self.values()8485 def get_tuple(self):86 result = []87 for k,v in self.enum_keys:88 result.append((k, v, self.get_string(k),) )89 return tuple(result)9091 def clone(self):92 return Enumeration(self.get_tuple()) ...

Full Screen

Full Screen

helpers.py

Source:helpers.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2# Taken fron http://djangosnippets.org/snippets/1647/3# Author: Dmitri Patrakov <traditio@gmail.com>4class Enumeration(object):5 """6 A small helper class for more readable enumerations,7 and compatible with Django's choice convention.8 You may just pass the instance of this class as the choices9 argument of model/form fields.10 Example:11 MY_ENUM = Enumeration([12 (100, 'MY_NAME', 'My verbose name'),13 (200, 'MY_AGE', 'My verbose age'),14 ])15 assert MY_ENUM.MY_AGE == 10016 assert MY_ENUM[1] == (200, 'My verbose age')17 """18 def __init__(self, enum_list):19 self.enum_keys = [(item[0], item[1]) for item in enum_list]20 self.enum_list = [(item[0], item[2]) for item in enum_list]21 self.enum_dict = {}22 for item in enum_list:23 self.enum_dict[item[1]] = item[0]24 def __contains__(self, v):25 return (v in self.enum_list)26 def __len__(self):27 return len(self.enum_list)28 def __getitem__(self, v):29 if isinstance(v, basestring):30 return self.enum_dict[v]31 elif isinstance(v, int):32 return self.enum_list[v]33 def __getattr__(self, name):34 return self.enum_dict[name]35 def insert(self, pos, item):36 self.enum_keys.insert(pos, (item[0], item[1]))37 self.enum_list.insert(pos, (item[0], item[2]))38 self.enum_dict[item[1]] = item[0]39 def append(self, item):40 self.enum_keys.append((item[0], item[1]))41 self.enum_list.append((item[0], item[2]))42 self.enum_dict[item[1]] = item[0]43 def get_string(self, v):44 string_dict = dict(self.enum_list)45 try:46 if isinstance(v, basestring):47 return string_dict[self.enum_dict[v]]48 elif isinstance(v, int):49 return string_dict[v]50 except KeyError:51 return None52 def get_key(self, v):53 key_dict = dict(self.enum_keys)54 return key_dict.get(v)55 def get_value(self, v):56 return self.enum_dict.get(v)57 def __iter__(self):58 return self.enum_list.__iter__()59 def values(self):60 return [item[0] for item in self.enum_list]61 def keys(self):62 return [item[1] for item in self.enum_keys]63 def has_key(self, key):64 return key in self.keys()65 def has_value(self, value):66 return value in self.values()67 def get_tuple(self):68 result = []69 for k,v in self.enum_keys:70 result.append((k, v, self.get_string(k),) )71 return tuple(result)72 def clone(self):...

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 tox 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