How to use _report_issue method in Kiwi

Best Python code snippet using Kiwi_python

trobz_test.py

Source:trobz_test.py Github

copy

Full Screen

...64 'project_specific_sections',65 '[]'))66 self.ERP_SECTIONS = self.ERP_SECTIONS + \67 tuple(project_specific_sections)68 def _report_issue(self, message):69 self.feel_bad_factor += 170 self.result_dict[self.feel_bad_factor] = [71 self.feel_bad_factor, message]72 def _get_code_files(self, module_path, list_files):73 # TODO: Give the possibility to include custom section per module:74 # What I have in mind is to create a ir.config_parameter75 # key=bmq_module_name76 # value={$custom_config_1 :aaa,$custom_config_2:bbbb}77 code_files = {}78 for filename in list_files:79 if filename in self.IGNORED_FILES:80 continue81 path = os.path.join(module_path, filename)82 if os.path.isdir(path):83 if filename in self.TROBZ_MODULE_STRUCTURE_FOLDERS:84 self.feel_good_factor += 185 for filename2 in os.listdir(path):86 if filename2 in self.IGNORED_FILES:87 continue88 path2 = os.path.join(module_path, filename, filename2)89 if os.path.isdir(path2):90 if filename2 in self.ERP_SECTIONS:91 self.feel_good_factor += 192 else:93 self.feel_bad_factor += 194 key = '%s - section name' %\95 self.feel_bad_factor96 self.result_dict[key] = [key, 'The folder %s \97 has an unexpected name for a section, only one\98 of those should be present: "%s".' % (99 path2, ', '.join(self.ERP_SECTIONS))]100 for filename3 in os.listdir(path2):101 if filename3 in self.IGNORED_FILES:102 continue103 path3 = os.path.join(path2, filename3)104 if filename3[-4:] not in ['.pyc', '.~1~']:105 code_files[filename3] = {106 'type': filename, 'path': path3}107 else:108 if filename2[-4:] != '.pyc':109 code_files[filename2] = {110 'type': filename, 'path': path2}111 else:112 err_msg = 'The folder %s has an unexpected name, only one '113 'of those should be present: "%s"'\114 % (filename,115 ', '.join(self.TROBZ_MODULE_STRUCTURE_FOLDERS))116 self._report_issue(err_msg)117 elif filename not in ('__openerp__.py', '__init__.py',118 '__openerp__.pyc', '__init__.pyc'):119 self._report_issue(120 "The module root should contain only the __openerp__.py "121 "and __init__.py files, Found: %s" % (filename))122 return code_files123 def _check_file_names_and_content(self, code_files,124 all_installed_model_list):125 '''CHECK FILE NAMES AND CONTENT126 '''127 DATA_FILE_EXCEPTION = (128 'company.xml', '__init__.py', 'amount_to_text_en.py',129 'amount_to_text_vn.py', 'object_proxy.py')130 for filename in code_files:131 if code_files[filename]['type'] in ('data', 'data_test')\132 and filename not in DATA_FILE_EXCEPTION\133 and filename.find('.png') == -1:134 if filename[-9:] in ('_data.xml', '_data.csv') or\135 filename[:11] == 'post_object':136 self.feel_good_factor += 1137 else:138 self._report_issue('A data file name should end with '139 '_data.xml (exception: %s). Found: %s'140 % (', '.join(DATA_FILE_EXCEPTION),141 code_files[filename]['path']))142 elif code_files[filename]['type'] in ('menu'):143 if filename[-9:] == '_menu.xml':144 self.feel_good_factor += 1145 else:146 self._report_issue('A menu file name should end with '147 '_menu.xml. Found: %s' %148 (code_files[filename]['path']))149 include_section = False150 for section in self.ERP_SECTIONS:151 if filename.find(section) > -1:152 include_section = True153 break154 if include_section:155 self.feel_good_factor += 1156 else:157 self._report_issue('A menu file name should contain a '158 'section name (%s). Found: %s'159 % (', '.join(self.ERP_SECTIONS),160 code_files[filename]['path']))161 elif code_files[filename]['type'] in ('model'):162 model_name = filename[0:-3]163 model_dot_name = model_name.replace('_', '.')164 if model_dot_name in all_installed_model_list:165 self.feel_good_factor += 1166 model_file = open(code_files[filename]['path'], 'r')167 for line in model_file:168 if line.find('class ') > -1 and (line.find(169 'osv.osv') > -1 or line.find(170 'models.Model') > -1 or line.find(171 'models.TransientModel') > -1):172 # class trobz_maintenance_contract(osv.osv):173 class_name = line[6:line.find('(')].strip()174 if class_name == model_name:175 self.feel_good_factor += 1176 else:177 self._report_issue('class name (found: %s) and\178 file name (found: %s) should be the same.\179 Found: %s' % (class_name,180 model_name,181 code_files[filename]['path']))182 if line.find(' _name') > -1:183 if line.find('\''):184 line = line.replace('\'', '')185 if line.find('\"'):186 line = line.replace('\"', '')187 real_model_name = line[line.find('=') + 2:].strip()188 if real_model_name == model_dot_name:189 self.feel_good_factor += 1190 else:191 self._report_issue('model name (found: %s) and\192 file name (found: %s) should be the same.\193 Found: %s' % (real_model_name,194 model_dot_name,195 code_files[filename]['path']))196 elif filename not in DATA_FILE_EXCEPTION:197 self._report_issue(198 'A model file name should have a name of the form\199 model_name.py. No model found with the name\200 "%s"' % model_dot_name)201 elif code_files[filename]['type'] in ('view'):202 if filename[-9:] == '_view.xml':203 self.feel_good_factor += 1204 else:205 self._report_issue('A view file name should end with\206 _view.xml. Found: %s' % (code_files[filename]['path']))207 def _check_view_ids(self, cr, uid, module_name):208 '''CHECK VIEW IDS209 '''210 module_new_models = self.get_new_models_of_module(cr, uid, module_name)211 module_new_views = self.get_module_new_views(cr, module_name)212 view_dict = {}213 model_views = 0214 view_obj = self.registry['ir.ui.view']215 view_ids = view_obj.search(cr, uid, [(216 'model', 'in', module_new_models), ('type', 'in', ['tree',217 'form',218 'search'])])219 view_data = view_obj.browse(cr, uid, view_ids)220 for view in view_data:221 if view.model in view_dict:222 view_dict[view.model].append(223 {'type': view.type, 'name': view.name})224 else:225 view_dict[view.model] = []226 view_dict[view.model].append(227 {'type': view.type, 'name': view.name})228 model_views += 1229 for model in view_dict:230 # TODO: we should handle the models of type wizard in the future231 if model not in ('trobz.update.all.groups')\232 and model.find('wizard') == -1:233 model_name = model.replace('.', '_')234 if model_name in module_new_models:235 if len(view_dict[model]) >= 3:236 self.feel_good_factor += 1237 else:238 self._report_issue('You should have at least a\239 form/tree/search view for each model, missing views\240 for model %s' % model)241 has_default_search = False242 has_default_tree = False243 has_default_form = False244 default_search_view_name = '%s_%s_search' % (245 'view', model_name)246 default_tree_view_name = '%s_%s_tree' % (247 'view', model_name)248 default_form_view_name = '%s_%s_form' % (249 'view', model_name)250 for view in module_new_views:251 view_name = view['name']252 if view['model'] != model:253 continue254 if view_name == default_search_view_name:255 self.feel_good_factor += 1256 has_default_search = True257 elif view_name == default_tree_view_name:258 self.feel_good_factor += 1259 has_default_tree = True260 elif view_name == default_form_view_name:261 self.feel_good_factor += 1262 has_default_form = True263 elif view_name.find(default_search_view_name) > -1 \264 or view_name.find(default_tree_view_name) > -1 \265 or view_name.find(default_form_view_name) > -1:266 self.feel_good_factor += 1267 else:268 self._report_issue(269 'The view name "%s" does not respect Trobz\270 standard naming convention.' % view_name)271 if not has_default_search:272 self._report_issue(273 'You should have at least a search view with the\274 name: %s' % default_search_view_name)275 if not has_default_tree:276 self._report_issue(277 'You should have at least a tree view with the\278 name: %s' % default_tree_view_name)279 if not has_default_form:280 self._report_issue(281 'You should have at least a form view with the\282 name: %s' % default_form_view_name)283 def run_test_trobz(self, cr, uid, module_path):284 self.registry = RegistryManager.get(cr.dbname)285 self._set_project_sections(cr, uid)286 score = 1.0287 list_files = os.listdir(module_path)288 module_name = module_path.split('/')[-1]289 all_installed_model_list = self.get_all_installed_model_list(cr, uid)290 # evaluate the source code structure291 code_files = self._get_code_files(module_path, list_files)292 # make sure that293 # + there is only 1 class in a python file294 # +...

Full Screen

Full Screen

pathlesstaken.py

Source:pathlesstaken.py Github

copy

Full Screen

...40 self.detect_microsoft_reserved_names(string)41 self.detect_spaces_at_end_of_names(string, folders)42 self.detect_period_at_end_of_name(string, folders)43 return self.report44 def _report_issue(self, string, message, value, folders=False):45 """Helper function to build the report to return to the caller."""46 text = "File"47 if folders:48 text = "Directory"49 if not value:50 self.report = "{}{}: '{}' {}\n".format(self.report, text, string, message)51 return52 self.report = "{}{}: '{}' {} '{}'\n".format(53 self.report, text, string, message, value54 )55 @staticmethod56 def _unicodename(char):57 """Return a Unicode name for the character we want to return58 information about.59 """60 try:61 name = names.Lookup().name(char)62 return "%s: %s" % (name, char)63 except TypeError:64 if char >= 0 and char <= 31:65 return "<control character>"66 return "non-specified error"67 def detect_non_ascii_characters(self, string, folders=False):68 """Detect characters outside of an ASCII range. These are more69 difficult to preserve in today's systems, even still, though it is70 getting easier.71 """72 match = any(ord(char) > 128 for char in string)73 if match:74 for char in string:75 if ord(char) <= 128:76 continue77 self._report_issue(78 string=string,79 message="{}:".format(self.STRINGS.FNAME_CHECK_ASCII),80 value="{}, {}".format(hex(ord(char)), self._unicodename(char)),81 folders=folders,82 )83 if not self.verbose:84 break85 def detect_non_recommended_characters(self, string, folders=False):86 """Detect characters that are not particularly recommended. These87 characters for example a forward slash '/' often have other meanings88 in computer systems and can be interpreted incorrectly if not handled89 properly.90 """91 charlist = ["<", ">", '"', "?", "*", "|", "]", "["]92 if not folders:93 charlist = charlist + [":", "/", "\\"]94 for char in string:95 if char in charlist:96 self._report_issue(97 string=string,98 message="{}:".format(self.STRINGS.FNAME_CHECK_NOT_RECOMMENDED),99 value=("{}, {}".format(hex(ord(char)), self._unicodename(char))),100 folders=folders,101 )102 if not self.verbose:103 break104 def detect_non_printable_characters(self, string, folders=False):105 """Detect control characters below 0x20 in the ASCII table that cannot106 be printed. Examples include ESC (escape) or BS (backspace).107 """108 for char in range(0x20):109 if chr(char) in string:110 self._report_issue(111 string=string,112 message="{}:".format(self.STRINGS.FNAME_CHECK_NON_PRINT),113 value="{}, {}".format(hex(char), self._unicodename(char)),114 folders=folders,115 )116 if not self.verbose:117 break118 def detect_microsoft_reserved_names(self, string):119 """Detect names that are considered difficult on Microsoft file120 systems. There is a special history to these characters which can be121 read about on this link below:122 * http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx123 """124 microsoft_reserved_names = [125 "CON",126 "PRN",127 "AUX",128 "NUL",129 "COM1",130 "COM2",131 "COM3",132 "COM4",133 "COM5",134 "COM6",135 "COM7",136 "COM8",137 "COM9",138 "LPT1",139 "LPT2",140 "LPT3",141 "LPT4",142 "LPT5",143 "LPT6",144 "LPT7",145 "LPT8",146 "LPT9",147 ]148 for reserved in microsoft_reserved_names:149 if reserved in string[0 : len(reserved)]:150 problem = True151 # If the reserved name is followed by an extension that's still152 # a bad idea.153 try:154 if string[len(reserved)] == ".":155 problem = True156 except IndexError:157 # This is an exact reserved name match.158 problem = True159 if problem:160 self._report_issue(161 string=string,162 message=self.STRINGS.FNAME_CHECK_RESERVED,163 value=reserved,164 )165 def detect_spaces_at_end_of_names(self, string, folders=False):166 """Detect spaces at the end of a string. These spaces if ignored can167 lead to incorrectly matching strings, e.g. 'this ' is different to168 'this'.169 """170 if string.endswith(" "):171 self._report_issue(172 string=string,173 message=self.STRINGS.FNAME_CHECK_SPACE,174 value=None,175 folders=folders,176 )177 def detect_period_at_end_of_name(self, string, folders=False):178 """Detect a full-stop at the end of a name. This might indicate a179 missing file extension."""180 if string.endswith("."):181 self._report_issue(182 string=string,183 message=self.STRINGS.FNAME_CHECK_PERIOD,184 value=None,185 folders=folders,186 )187 def _detect_invalid_characters_test(self):188 """Function to help with testing until there are unit tests."""189 test_strings = [190 "COM4",191 "COM4.txt",192 ".com4",193 "abcCOM4text",194 "AUX",195 "aux",...

Full Screen

Full Screen

add_header_redefinition.py

Source:add_header_redefinition.py Github

copy

Full Screen

...37 if not parent_headers:38 continue39 diff = (parent_headers - actual_headers) & self.interesting_headers40 if len(diff):41 self._report_issue(directive, parent, diff)42 break43 def _report_issue(self, current, parent, diff):44 directives = []45 # Add headers from parent level46 directives.extend(parent.find('add_header'))47 # Add headers from current level48 directives.extend(current.find('add_header'))49 reason = 'Parent headers "{headers}" was dropped in current level'.format(headers='", "'.join(diff))50 self.add_issue(directive=directives, reason=reason)51def get_headers(directive):52 headers = directive.find('add_header')53 if not headers:54 return set()...

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