Best Python code snippet using tappy_python
test_denial_reasons.py
Source:test_denial_reasons.py
...91 querystring = urlencode(params)92 response = client.get(f'{url}?{querystring}')93 assert response.status_code == 40494@pytest.mark.django_db95def test_delete_denial_reason(client, valid_user_1):96 user = create_moderator_test_user(valid_user_1)97 client.force_login(user)98 reason = PostDenialReason(description='test', moderator=user)99 reason.save()100 assert user.post_denial_reasons.count() == 1101 url = reverse('moderation:denial-reason-delete', kwargs={'id': reason.id})102 response = client.get(url)103 assert response.status_code == 200104 assertTemplateUsed(response, 'moderation/denial_reason_delete.html')105 response = client.post(url)106 assert response.status_code == 302107 assert response.url == reverse('moderation:denial-reason-list')108 assert user.post_denial_reasons.count() == 0109@pytest.mark.django_db110def test_delete_invalid_reason(client, valid_user_1):111 user = create_moderator_test_user(valid_user_1)112 client.force_login(user)113 url = reverse('moderation:denial-reason-delete', kwargs={'id': 0})114 response = client.get(url)115 assert response.status_code == 404116 response = client.post(url)117 assert response.status_code == 404118def perform_modify_reason_another_user(client, url_name, user_data_1, user_data_2):119 user1 = create_moderator_test_user(user_data_1)120 user2 = create_moderator_test_user(user_data_2)121 client.force_login(user1)122 reason = PostDenialReason(description='test', moderator=user2)123 reason.save()124 assert user2.post_denial_reasons.count() == 1125 url = reverse(url_name, kwargs={'id': reason.id})126 response = client.get(url)127 assert response.status_code == 404128 response = client.post(url)129 assert response.status_code == 404130 assert user2.post_denial_reasons.count() == 1131@pytest.mark.django_db132def test_delete_reason_another_user(client, valid_user_1, valid_user_2):133 perform_modify_reason_another_user(134 client, 'moderation:denial-reason-delete', valid_user_1, valid_user_2)135def perform_modify_reason_no_user(client, url_name, user_data):136 user = create_moderator_test_user(user_data)137 client.force_login(user)138 reason = PostDenialReason(description='test')139 reason.save()140 assert PostDenialReason.objects.count() == 1141 url = reverse(url_name, kwargs={'id': reason.id})142 response = client.get(url)143 assert response.status_code == 404144 response = client.post(url)145 assert response.status_code == 404146 assert PostDenialReason.objects.count() == 1147@pytest.mark.django_db148def test_delete_reason_no_user(client, valid_user_1):149 perform_modify_reason_no_user(150 client, 'moderation:denial-reason-delete', valid_user_1)151def perform_successful_create_reason(client, user_data, reason_data):152 user = create_moderator_test_user(user_data)153 client.force_login(user)154 url = reverse('moderation:denial-reason-create')155 response = client.get(url)156 assert response.status_code == 200157 assertTemplateUsed('moderation/denial_reason_create.html')158 response = client.post(url, reason_data)159 assert response.status_code == 302160 assert response.url == reverse('moderation:denial-reason-list')161 assert user.post_denial_reasons.count() == 1162 assert user.post_denial_reasons.first(163 ).description == reason_data['description']164@pytest.mark.django_db165def test_successful_create_reason(client, valid_user_1, valid_denial_reason_1):166 perform_successful_create_reason(167 client, valid_user_1, {'description': valid_denial_reason_1})168@pytest.mark.django_db169def test_create_repeated_reason_another_user(client, valid_user_1, valid_user_2, valid_denial_reason_1):170 user = create_moderator_test_user(valid_user_2)171 reason = PostDenialReason(172 description=valid_denial_reason_1, moderator=user)173 reason.save()174 assert user.post_denial_reasons.count() == 1175 assert user.post_denial_reasons.first().description == valid_denial_reason_1176 perform_successful_create_reason(177 client, valid_user_1, {'description': valid_denial_reason_1})178def perform_failed_create_reason(client, user_data, reason_data):179 user = create_moderator_test_user(user_data)180 client.force_login(user)181 url = reverse('moderation:denial-reason-create')182 response = client.post(url, reason_data)183 assert response.status_code == 302184 assert response.url == url185 assert user.post_denial_reasons.count() == 0186@pytest.mark.django_db187def test_create_reason_description_missing(client, valid_user_1):188 perform_failed_create_reason(client, valid_user_1, {})189@pytest.mark.django_db190def test_create_reason_short_description(client, valid_user_1, short_denial_reason):191 reason_data = {192 'description': short_denial_reason193 }194 perform_failed_create_reason(client, valid_user_1, reason_data)195@pytest.mark.django_db196def test_create_reason_long_description(client, valid_user_1, long_denial_reason):197 reason_data = {198 'description': long_denial_reason199 }200 perform_failed_create_reason(client, valid_user_1, reason_data)201def perform_repeated_reason(client, url_name, url_args, user, reason_data, existing_reason, initial_count=1):202 assert reason_data['description'].lower(203 ) == existing_reason.description.lower()204 assert user.post_denial_reasons.count() == initial_count205 url = reverse(url_name, kwargs=url_args)206 response = client.post(url, reason_data)207 assert response.status_code == 302208 assert response.url == url209 assert user.post_denial_reasons.count() == initial_count210@pytest.mark.django_db211def test_create_repeated_reason(client, valid_user_1, valid_denial_reason_1, repeated_denial_reason):212 user = create_moderator_test_user(valid_user_1)213 client.force_login(user)214 reason = PostDenialReason(215 description=valid_denial_reason_1, moderator=user)216 reason.save()217 reason_data = {218 'description': repeated_denial_reason219 }220 perform_repeated_reason(221 client, 'moderation:denial-reason-create', {}, user, reason_data, reason)222@pytest.mark.django_db223def test_create_repeated_generic_reason(client, valid_user_1, valid_denial_reason_1, repeated_denial_reason):224 user = create_moderator_test_user(valid_user_1)225 client.force_login(user)226 reason = PostDenialReason(description=valid_denial_reason_1)227 reason.save()228 reason_data = {229 'description': repeated_denial_reason230 }231 perform_repeated_reason(232 client, 'moderation:denial-reason-create', {}, user, reason_data, reason, 0)233def perform_successful_edit_reason(client, user_data, reason_description, reason_data):234 user = create_moderator_test_user(user_data)235 client.force_login(user)236 reason = PostDenialReason(description=reason_description, moderator=user)237 reason.save()238 assert user.post_denial_reasons.count() == 1239 assert user.post_denial_reasons.first() == reason240 url = reverse('moderation:denial-reason-edit', kwargs={'id': reason.id})241 response = client.get(url)242 assert response.status_code == 200243 assertTemplateUsed('moderation/denial_reason_create.html')244 response = client.post(url, reason_data)245 assert response.status_code == 302246 assert response.url == reverse('moderation:denial-reason-list')247 assert user.post_denial_reasons.count() == 1248 assert user.post_denial_reasons.first(249 ).description == reason_data['description']250@pytest.mark.django_db251def test_successful_edit_reason(client, valid_user_1, valid_denial_reason_1, valid_denial_reason_2):252 reason_data = {253 'description': valid_denial_reason_2254 }255 perform_successful_edit_reason(256 client, valid_user_1, valid_denial_reason_1, reason_data)257@pytest.mark.django_db258def test_repeated_same_reason(client, valid_user_1, valid_denial_reason_1, repeated_denial_reason):259 reason_data = {260 'description': repeated_denial_reason261 }262 perform_successful_edit_reason(263 client, valid_user_1, valid_denial_reason_1, reason_data)264@pytest.mark.django_db265def test_successful_edit_reason_another_user(client, valid_user_1, valid_user_2,266 valid_denial_reason_1, valid_denial_reason_2):267 user = create_moderator_test_user(valid_user_2)268 reason = PostDenialReason(269 description=valid_denial_reason_2, moderator=user)270 reason.save()271 assert user.post_denial_reasons.count() == 1272 assert user.post_denial_reasons.first() == reason273 reason_data = {274 'description': valid_denial_reason_2275 }276 perform_successful_edit_reason(277 client, valid_user_1, valid_denial_reason_1, reason_data)278def perform_failed_edit_reason(client, user_data, reason_description, reason_data):279 user = create_moderator_test_user(user_data)280 client.force_login(user)281 reason = PostDenialReason(description=reason_description, moderator=user)282 reason.save()283 assert user.post_denial_reasons.count() == 1284 assert user.post_denial_reasons.first() == reason285 url = reverse('moderation:denial-reason-edit', kwargs={'id': reason.id})286 response = client.post(url, reason_data)287 assert response.status_code == 302288 assert response.url == url289 assert user.post_denial_reasons.count() == 1290 assert user.post_denial_reasons.first().description == reason_description291@pytest.mark.django_db292def test_edit_reason_missing_description(client, valid_user_1, valid_denial_reason_1):293 perform_failed_edit_reason(client, valid_user_1, valid_denial_reason_1, {})294@pytest.mark.django_db295def test_edit_reason_short_description(client, valid_user_1, valid_denial_reason_1, short_denial_reason):296 reason_data = {297 'description': short_denial_reason298 }299 perform_failed_edit_reason(300 client, valid_user_1, valid_denial_reason_1, reason_data)301@pytest.mark.django_db302def test_edit_reason_long_description(client, valid_user_1, valid_denial_reason_1, long_denial_reason):303 reason_data = {304 'description': long_denial_reason305 }306 perform_failed_edit_reason(307 client, valid_user_1, valid_denial_reason_1, reason_data)308@pytest.mark.django_db309def test_edit_repeated_reason(client, valid_user_1, valid_denial_reason_1,310 valid_denial_reason_2, repeated_denial_reason):311 user = create_moderator_test_user(valid_user_1)312 client.force_login(user)313 reason1 = PostDenialReason(314 description=valid_denial_reason_1, moderator=user)315 reason1.save()316 reason2 = PostDenialReason(317 description=valid_denial_reason_2, moderator=user)318 reason2.save()319 reason_data = {320 'description': repeated_denial_reason321 }322 perform_repeated_reason(client, 'moderation:denial-reason-edit',323 {'id': reason2.id}, user, reason_data, reason1, 2)324@pytest.mark.django_db325def test_edit_repeated_generic_reason(client, valid_user_1, valid_denial_reason_1,326 valid_denial_reason_2, repeated_denial_reason):327 user = create_moderator_test_user(valid_user_1)328 client.force_login(user)329 reason1 = PostDenialReason(description=valid_denial_reason_1)330 reason1.save()331 reason2 = PostDenialReason(332 description=valid_denial_reason_2, moderator=user)333 reason2.save()334 reason_data = {335 'description': repeated_denial_reason336 }337 perform_repeated_reason(client, 'moderation:denial-reason-edit',338 {'id': reason2.id}, user, reason_data, reason1)339@pytest.mark.django_db340def test_edit_reason_another_user(client, valid_user_1, valid_user_2):341 perform_modify_reason_another_user(342 client, 'moderation:denial-reason-edit', valid_user_1, valid_user_2)343@pytest.mark.django_db344def test_edit_reason_no_user(client, valid_user_1):345 perform_modify_reason_no_user(...
mailerdaemon.py
Source:mailerdaemon.py
1#!/usr/bin/env python2"""mailerdaemon - classes to parse mailer-daemon messages"""3import rfc8224import calendar5import re6import os7import sys8Unparseable = 'mailerdaemon.Unparseable'9class ErrorMessage(rfc822.Message):10 def __init__(self, fp):11 rfc822.Message.__init__(self, fp)12 self.sub = ''13 def is_warning(self):14 sub = self.getheader('Subject')15 if not sub:16 return 017 sub = sub.lower()18 if sub.startswith('waiting mail'): return 119 if 'warning' in sub: return 120 self.sub = sub21 return 022 def get_errors(self):23 for p in EMPARSERS:24 self.rewindbody()25 try:26 return p(self.fp, self.sub)27 except Unparseable:28 pass29 raise Unparseable30# List of re's or tuples of re's.31# If a re, it should contain at least a group (?P<email>...) which32# should refer to the email address. The re can also contain a group33# (?P<reason>...) which should refer to the reason (error message).34# If no reason is present, the emparse_list_reason list is used to35# find a reason.36# If a tuple, the tuple should contain 2 re's. The first re finds a37# location, the second re is repeated one or more times to find38# multiple email addresses. The second re is matched (not searched)39# where the previous match ended.40# The re's are compiled using the re module.41emparse_list_list = [42 'error: (?P<reason>unresolvable): (?P<email>.+)',43 ('----- The following addresses had permanent fatal errors -----\n',44 '(?P<email>[^ \n].*)\n( .*\n)?'),45 'remote execution.*\n.*rmail (?P<email>.+)',46 ('The following recipients did not receive your message:\n\n',47 ' +(?P<email>.*)\n(The following recipients did not receive your message:\n\n)?'),48 '------- Failure Reasons --------\n\n(?P<reason>.*)\n(?P<email>.*)',49 '^<(?P<email>.*)>:\n(?P<reason>.*)',50 '^(?P<reason>User mailbox exceeds allowed size): (?P<email>.+)',51 '^5\\d{2} <(?P<email>[^\n>]+)>\\.\\.\\. (?P<reason>.+)',52 '^Original-Recipient: rfc822;(?P<email>.*)',53 '^did not reach the following recipient\\(s\\):\n\n(?P<email>.*) on .*\n +(?P<reason>.*)',54 '^ <(?P<email>[^\n>]+)> \\.\\.\\. (?P<reason>.*)',55 '^Report on your message to: (?P<email>.*)\nReason: (?P<reason>.*)',56 '^Your message was not delivered to +(?P<email>.*)\n +for the following reason:\n +(?P<reason>.*)',57 '^ was not +(?P<email>[^ \n].*?) *\n.*\n.*\n.*\n because:.*\n +(?P<reason>[^ \n].*?) *\n',58 ]59# compile the re's in the list and store them in-place.60for i in range(len(emparse_list_list)):61 x = emparse_list_list[i]62 if type(x) is type(''):63 x = re.compile(x, re.MULTILINE)64 else:65 xl = []66 for x in x:67 xl.append(re.compile(x, re.MULTILINE))68 x = tuple(xl)69 del xl70 emparse_list_list[i] = x71 del x72del i73# list of re's used to find reasons (error messages).74# if a string, "<>" is replaced by a copy of the email address.75# The expressions are searched for in order. After the first match,76# no more expressions are searched for. So, order is important.77emparse_list_reason = [78 r'^5\d{2} <>\.\.\. (?P<reason>.*)',79 '<>\.\.\. (?P<reason>.*)',80 re.compile(r'^<<< 5\d{2} (?P<reason>.*)', re.MULTILINE),81 re.compile('===== stderr was =====\nrmail: (?P<reason>.*)'),82 re.compile('^Diagnostic-Code: (?P<reason>.*)', re.MULTILINE),83 ]84emparse_list_from = re.compile('^From:', re.IGNORECASE|re.MULTILINE)85def emparse_list(fp, sub):86 data = fp.read()87 res = emparse_list_from.search(data)88 if res is None:89 from_index = len(data)90 else:91 from_index = res.start(0)92 errors = []93 emails = []94 reason = None95 for regexp in emparse_list_list:96 if type(regexp) is type(()):97 res = regexp[0].search(data, 0, from_index)98 if res is not None:99 try:100 reason = res.group('reason')101 except IndexError:102 pass103 while 1:104 res = regexp[1].match(data, res.end(0), from_index)105 if res is None:106 break107 emails.append(res.group('email'))108 break109 else:110 res = regexp.search(data, 0, from_index)111 if res is not None:112 emails.append(res.group('email'))113 try:114 reason = res.group('reason')115 except IndexError:116 pass117 break118 if not emails:119 raise Unparseable120 if not reason:121 reason = sub122 if reason[:15] == 'returned mail: ':123 reason = reason[15:]124 for regexp in emparse_list_reason:125 if type(regexp) is type(''):126 for i in range(len(emails)-1,-1,-1):127 email = emails[i]128 exp = re.compile(re.escape(email).join(regexp.split('<>')), re.MULTILINE)129 res = exp.search(data)130 if res is not None:131 errors.append(' '.join((email.strip()+': '+res.group('reason')).split()))132 del emails[i]133 continue134 res = regexp.search(data)135 if res is not None:136 reason = res.group('reason')137 break138 for email in emails:139 errors.append(' '.join((email.strip()+': '+reason).split()))140 return errors141EMPARSERS = [emparse_list, ]142def sort_numeric(a, b):143 a = int(a)144 b = int(b)145 if a < b: return -1146 elif a > b: return 1147 else: return 0148def parsedir(dir, modify):149 os.chdir(dir)150 pat = re.compile('^[0-9]*$')151 errordict = {}152 errorfirst = {}153 errorlast = {}154 nok = nwarn = nbad = 0155 # find all numeric file names and sort them156 files = filter(lambda fn, pat=pat: pat.match(fn) is not None, os.listdir('.'))157 files.sort(sort_numeric)158 for fn in files:159 # Lets try to parse the file.160 fp = open(fn)161 m = ErrorMessage(fp)162 sender = m.getaddr('From')163 print '%s\t%-40s\t'%(fn, sender[1]),164 if m.is_warning():165 fp.close()166 print 'warning only'167 nwarn = nwarn + 1168 if modify:169 os.rename(fn, ','+fn)170## os.unlink(fn)171 continue172 try:173 errors = m.get_errors()174 except Unparseable:175 print '** Not parseable'176 nbad = nbad + 1177 fp.close()178 continue179 print len(errors), 'errors'180 # Remember them181 for e in errors:182 try:183 mm, dd = m.getdate('date')[1:1+2]184 date = '%s %02d' % (calendar.month_abbr[mm], dd)185 except:186 date = '??????'187 if not errordict.has_key(e):188 errordict[e] = 1189 errorfirst[e] = '%s (%s)' % (fn, date)190 else:191 errordict[e] = errordict[e] + 1192 errorlast[e] = '%s (%s)' % (fn, date)193 fp.close()194 nok = nok + 1195 if modify:196 os.rename(fn, ','+fn)197## os.unlink(fn)198 print '--------------'199 print nok, 'files parsed,',nwarn,'files warning-only,',200 print nbad,'files unparseable'201 print '--------------'202 list = []203 for e in errordict.keys():204 list.append((errordict[e], errorfirst[e], errorlast[e], e))205 list.sort()206 for num, first, last, e in list:207 print '%d %s - %s\t%s' % (num, first, last, e)208def main():209 modify = 0210 if len(sys.argv) > 1 and sys.argv[1] == '-d':211 modify = 1212 del sys.argv[1]213 if len(sys.argv) > 1:214 for folder in sys.argv[1:]:215 parsedir(folder, modify)216 else:217 parsedir('/ufs/jack/Mail/errorsinbox', modify)218if __name__ == '__main__' or sys.argv[0] == __name__:...
FlagPostModal.js
Source:FlagPostModal.js
...36 <div className="Form Form--centered">37 <div className="Form-group">38 <div>39 <label className="checkbox">40 <input type="radio" name="reason" checked={this.reason() === 'off_topic'} value="off_topic" onclick={withAttr('value', this.reason)}/>41 <strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_off_topic_label')}</strong>42 {app.translator.trans('flarum-flags.forum.flag_post.reason_off_topic_text')}43 {this.reason() === 'off_topic' ? (44 <textarea className="FormControl" placeholder={app.translator.trans('flarum-flags.forum.flag_post.reason_details_placeholder')} value={this.reasonDetail()} oninput={withAttr('value', this.reasonDetail)}></textarea>45 ) : ''}46 </label>47 <label className="checkbox">48 <input type="radio" name="reason" checked={this.reason() === 'inappropriate'} value="inappropriate" onclick={withAttr('value', this.reason)}/>49 <strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_inappropriate_label')}</strong>50 {app.translator.trans('flarum-flags.forum.flag_post.reason_inappropriate_text', {51 a: guidelinesUrl ? <a href={guidelinesUrl} target="_blank"/> : undefined52 })}53 {this.reason() === 'inappropriate' ? (54 <textarea className="FormControl" placeholder={app.translator.trans('flarum-flags.forum.flag_post.reason_details_placeholder')} value={this.reasonDetail()} oninput={withAttr('value', this.reasonDetail)}></textarea>55 ) : ''}56 </label>57 <label className="checkbox">58 <input type="radio" name="reason" checked={this.reason() === 'spam'} value="spam" onclick={withAttr('value', this.reason)}/>59 <strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_spam_label')}</strong>60 {app.translator.trans('flarum-flags.forum.flag_post.reason_spam_text')}61 {this.reason() === 'spam' ? (62 <textarea className="FormControl" placeholder={app.translator.trans('flarum-flags.forum.flag_post.reason_details_placeholder')} value={this.reasonDetail()} oninput={withAttr('value', this.reasonDetail)}></textarea>63 ) : ''}64 </label>65 <label className="checkbox">66 <input type="radio" name="reason" checked={this.reason() === 'other'} value="other" onclick={withAttr('value', this.reason)}/>67 <strong>{app.translator.trans('flarum-flags.forum.flag_post.reason_other_label')}</strong>68 {this.reason() === 'other' ? (69 <textarea className="FormControl" value={this.reasonDetail()} oninput={withAttr('value', this.reasonDetail)}></textarea>70 ) : ''}71 </label>72 </div>73 </div>74 <div className="Form-group">75 <Button76 className="Button Button--primary Button--block"77 type="submit"78 loading={this.loading}79 disabled={!this.reason()}>80 {app.translator.trans('flarum-flags.forum.flag_post.submit_button')}81 </Button>82 </div>83 </div>84 </div>85 );86 }87 onsubmit(e) {88 e.preventDefault();89 this.loading = true;90 app.store.createRecord('flags').save({91 reason: this.reason() === 'other' ? null : this.reason(),92 reasonDetail: this.reasonDetail(),93 relationships: {94 user: app.session.user,95 post: this.attrs.post96 }97 }, {errorHandler: this.onerror.bind(this)})98 .then(() => this.success = true)99 .catch(() => {})100 .then(this.loaded.bind(this));101 }...
trace-maps-processor.py
Source:trace-maps-processor.py
1#!/usr/bin/env python2# Copyright 2014 the V8 project authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5import sys6action = sys.argv[1]7if action in ["help", "-h", "--help"] or len(sys.argv) != 3:8 print("Usage: %s <action> <inputfile>, where action can be: \n"9 "help Print this message\n"10 "plain Print ASCII tree to stdout\n"11 "dot Print dot file to stdout\n"12 "count Count most frequent transition reasons\n" % sys.argv[0])13 sys.exit(0)14filename = sys.argv[2]15maps = {}16root_maps = []17transitions = {}18annotations = {}19class Map(object):20 def __init__(self, pointer, origin):21 self.pointer = pointer22 self.origin = origin23 def __str__(self):24 return "%s (%s)" % (self.pointer, self.origin)25class Transition(object):26 def __init__(self, from_map, to_map, reason):27 self.from_map = from_map28 self.to_map = to_map29 self.reason = reason30def RegisterNewMap(raw_map):31 if raw_map in annotations:32 annotations[raw_map] += 133 else:34 annotations[raw_map] = 035 return AnnotateExistingMap(raw_map)36def AnnotateExistingMap(raw_map):37 return "%s_%d" % (raw_map, annotations[raw_map])38def AddMap(pointer, origin):39 pointer = RegisterNewMap(pointer)40 maps[pointer] = Map(pointer, origin)41 return pointer42def AddTransition(from_map, to_map, reason):43 from_map = AnnotateExistingMap(from_map)44 to_map = AnnotateExistingMap(to_map)45 if from_map not in transitions:46 transitions[from_map] = {}47 targets = transitions[from_map]48 if to_map in targets:49 # Some events get printed twice, that's OK. In some cases, ignore the50 # second output...51 old_reason = targets[to_map].reason52 if old_reason.startswith("ReplaceDescriptors"):53 return54 # ...and in others use it for additional detail.55 if reason in []:56 targets[to_map].reason = reason57 return58 # Unexpected duplicate events? Warn.59 print("// warning: already have a transition from %s to %s, reason: %s" %60 (from_map, to_map, targets[to_map].reason))61 return62 targets[to_map] = Transition(from_map, to_map, reason)63with open(filename, "r") as f:64 last_to_map = ""65 for line in f:66 if not line.startswith("[TraceMaps: "): continue67 words = line.split(" ")68 event = words[1]69 if event == "InitialMap":70 assert words[2] == "map="71 assert words[4] == "SFI="72 new_map = AddMap(words[3], "SFI#%s" % words[5])73 root_maps.append(new_map)74 continue75 if words[2] == "from=" and words[4] == "to=":76 from_map = words[3]77 to_map = words[5]78 if from_map not in annotations:79 print("// warning: unknown from_map %s" % from_map)80 new_map = AddMap(from_map, "<unknown>")81 root_maps.append(new_map)82 if to_map != last_to_map:83 AddMap(to_map, "<transition> (%s)" % event)84 last_to_map = to_map85 if event in ["Transition", "NoTransition"]:86 assert words[6] == "name=", line87 reason = "%s: %s" % (event, words[7])88 elif event in ["Normalize", "ReplaceDescriptors", "SlowToFast"]:89 assert words[6] == "reason=", line90 reason = "%s: %s" % (event, words[7])91 if words[8].strip() != "]":92 reason = "%s_%s" % (reason, words[8])93 else:94 reason = event95 AddTransition(from_map, to_map, reason)96 continue97def PlainPrint(m, indent, label):98 print("%s%s (%s)" % (indent, m, label))99 if m in transitions:100 for t in transitions[m]:101 PlainPrint(t, indent + " ", transitions[m][t].reason)102def CountTransitions(m):103 if m not in transitions: return 0104 return len(transitions[m])105def DotPrint(m, label):106 print("m%s [label=\"%s\"]" % (m[2:], label))107 if m in transitions:108 for t in transitions[m]:109 # GraphViz doesn't like node labels looking like numbers, so use110 # "m..." instead of "0x...".111 print("m%s -> m%s" % (m[2:], t[2:]))112 reason = transitions[m][t].reason113 reason = reason.replace("\\", "BACKSLASH")114 reason = reason.replace("\"", "\\\"")115 DotPrint(t, reason)116if action == "plain":117 root_maps = sorted(root_maps, key=CountTransitions, reverse=True)118 for m in root_maps:119 PlainPrint(m, "", maps[m].origin)120elif action == "dot":121 print("digraph g {")122 for m in root_maps:123 DotPrint(m, maps[m].origin)124 print("}")125elif action == "count":126 reasons = {}127 for s in transitions:128 for t in transitions[s]:129 reason = transitions[s][t].reason130 if reason not in reasons:131 reasons[reason] = 1132 else:133 reasons[reason] += 1134 reasons_list = []135 for r in reasons:136 reasons_list.append("%8d %s" % (reasons[r], r))137 reasons_list.sort(reverse=True)138 for r in reasons_list[:20]:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!