How to use check_similar_and_add_error_message method in Kiwi

Best Python code snippet using Kiwi_python

similar_string.py

Source:similar_string.py Github

copy

Full Screen

...63 return64 if not isinstance(node.args[0], astroid.nodes.Const):65 return66 translation_string = node.args[0].value67 self.check_similar_and_add_error_message(node, translation_string)68 # check if similar string found and add it to error_messages69 def check_similar_and_add_error_message(70 self, node, translation_string, **error_message71 ):72 if translation_string in self._dict_of_strings:73 return74 similar_string, similarity = self.check_similar_string(translation_string)75 if similar_string:76 if isinstance(node, str):77 error_message["node"] = astroid.Module(node, file=node, doc=None)78 else:79 error_message["node"] = node80 error_message["args"] = (81 translation_string,82 similarity * 100,83 similar_string,84 )85 self.error_messages.append(error_message)86 return87 self._dict_of_strings[translation_string] = True88 # checks each line and find trans or blocktrans tags89 def parse_translation_string(self, filename, lines):90 startline = 091 startcol = 092 blocktrans_string = ""93 for lineno, line in enumerate(lines):94 # if pylint disable comment is found ignore and continue with next line95 if re.search(r"<!--\s*pylint\s*:\s*disable\s*-->", line):96 continue97 # if blocktrans starting tag is found98 match_blocktrans_in_line = re.search(r"{% blocktrans[^%}]*%}(.+)", line)99 if match_blocktrans_in_line:100 startline = lineno101 startcol = match_blocktrans_in_line.start(1)102 blocktrans_string = match_blocktrans_in_line.group(1)103 # if line after blocktrans is found104 elif blocktrans_string != "":105 blocktrans_string += line106 # if blocktrans ending tag is found107 endblocktrans_line = re.search(108 r"((.|\n|)*){% endblocktrans %}", blocktrans_string109 )110 if endblocktrans_line:111 blocktrans_string = endblocktrans_line.group(1)112 self.check_similar_and_add_error_message(113 filename,114 blocktrans_string,115 line=startline + 1,116 col_offset=startcol,117 )118 blocktrans_string = ""119 # if trans tag is found120 # Note: trans tag could be more than one in same121 # line, hence re.finditer rather than re.search)122 match_in_line = re.finditer(r'{% trans "([\w ]+)" %}', line)123 for match in match_in_line:124 translation_string = match.group(1)125 self.check_similar_and_add_error_message(126 filename,127 translation_string,128 line=lineno + 1,129 col_offset=match.start(1),130 )131 def close(self):132 for filepath in self.all_template_files:133 with open(filepath, "r", encoding="utf-8") as file:134 self.parse_translation_string(filepath, file.readlines())135 for error_message in self.error_messages:...

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