Best Python code snippet using lisa_python
payload.py
Source:payload.py  
1def _get_default_data():2    return {3                'color': '#FFFFFF',4                'text': 'Not implemented'5    }6def _set_color_from_priority(priority):7    return {8        'trivial': '#205081',9        'minor': 'good',10        'major': 'warning',11        'critical': 'danger',12        'blocker': '#000000'13    }.get(priority, '#FFFFFF')14def _set_color_from_state(state):15    return {16        'SUCCESSFUL': 'good',17        'FAILED': 'danger'18    }.get(state, 'warning')19def _get_issue(data, action):20    resp = _get_default_data()21    resp = _set_author_infos(resp, data)22    template = '%s a %s %s [#%s: %s](%s) (%s)'23    issue = data.issue24    resp['text'] = template % (action, issue.priority, issue.type, issue.id,25                               issue.title, issue.links.html.href, issue.state)26    resp['color'] = _set_color_from_priority(issue.priority)27    return resp28def _get_pullrequest(data, action):29    resp = _get_default_data()30    resp = _set_author_infos(resp, data)31    pr = data.pullrequest32    pr_link = '[%s](%s)' % (pr.title, pr.links.html.href)33    pr_src_link = '%s/branch/%s' % (pr.source.repository.links.html.href,34                                    pr.source.branch.name)35    pr_dst_link = '%s/branch/%s' % (pr.destination.repository.links.html.href,36                                    pr.destination.branch.name)37    pr_src = '[%s:%s](%s)' % (pr.source.repository.full_name,38                              pr.source.branch.name,39                              pr_src_link)40    pr_dst = '[%s:%s](%s)' % (pr.destination.repository.full_name,41                              pr.destination.branch.name,42                              pr_dst_link)43    template = '%s pull request %s\nFrom %s to %s'44    resp['text'] = template % (action, pr_link, pr_src, pr_dst)45    return resp46def _set_author_infos(resp, data):47    if data.actor.display_name == 'Anonymous':48        resp['author_name'] = data.actor.display_name49        return resp50    resp['author_name'] = '%s (%s)' % (data.actor.display_name,51                                       data.actor.username)52    resp['author_icon'] = data.actor.links.avatar.href53    resp['author_link'] = data.actor.links.html.href54    return resp55def issue_comment_created(data):56    resp = _get_issue(data, 'Commented')57    return resp58def issue_created(data):59    resp = _get_issue(data, 'Opened')60    return resp61def issue_updated(data):62    resp = _get_issue(data, 'Updated')63    return resp64def repo_commit_comment_created(data):65    resp = _get_default_data()66    resp = _set_author_infos(resp, data)67    template = 'Commented commit %s at %s'68    commit_link = '[#%s](%s)' % (data.comment.commit.hash[:7],69                                 data.comment.links.html.href)70    repo_link = '[%s](%s)' % (data.repository.full_name,71                              data.repository.links.html.href)72    resp['text'] = template % (commit_link, repo_link)73    return resp74def repo_commit_status_created(data):75    resp = _get_default_data()76    resp = _set_author_infos(resp, data)77    ci_link = '[%s](%s)' % (data.commit_status.key, data.commit_status.url)78    resp['text'] = 'Launch CI build on %s' % ci_link79    return resp80def repo_commit_status_updated(data):81    resp = _get_default_data()82    resp = _set_author_infos(resp, data)83    ci_link = '[%s](%s)' % (data.commit_status.key, data.commit_status.url)84    resp['text'] = 'CI build on %s is finished' % ci_link85    resp['color'] = _set_color_from_state(data.commit_status.state)86    return resp87def repo_fork(data):88    resp = _get_default_data()89    resp = _set_author_infos(resp, data)90    template = 'Forked %s to %s'91    src_link = '[%s](%s)' % (data.repository.full_name,92                             data.repository.links.html.href)93    dst_link = '[%s](%s)' % (data.fork.full_name, data.fork.links.html.href)94    resp['text'] = template % (src_link, dst_link)95    return resp96def repo_push(data):97    resp = _get_default_data()98    resp = _set_author_infos(resp, data)99    changesets = len(data.push.changes[0].commits)100    repo_link = '[%s](%s)' % (data.repository.full_name,101                              data.repository.links.html.href)102    branch = data.push.changes[0].new.name103    commits = []104    for commit in data.push.changes[0].commits:105        text = '- [%s](%s): %s' % (commit.hash[:7],106                                   commit.links.html.href,107                                   commit.message.strip().replace('\n', ' - '))108        commits.append(text)109    template = 'Pushed %s changesets to %s at %s\n%s'110    resp['text'] = template % (changesets, branch,111                               repo_link, '\n'.join(commits))112    return resp113def repo_updated(data):114    resp = _get_default_data()115    resp = _set_author_infos(resp, data)116    repo_link = '[%s](%s)' % (data.repository.full_name,117                              data.repository.links.html.href)118    resp['text'] = 'Updated repo %s' % repo_link119    return resp120def pullrequest_approved(data):121    resp = _get_pullrequest(data, 'Approved')122    return resp123def pullrequest_created(data):124    resp = _get_pullrequest(data, 'Opened')125    return resp126def pullrequest_fulfilled(data):127    resp = _get_pullrequest(data, 'Merged')128    return resp...coco_annotation.py
Source:coco_annotation.py  
...8    return dt.strftime(formt)9class CocoAnnotationClass(object):10    def __init__(self, classes, supercategory=""):11        self.classes = classes12        self.data = self._get_default_data()13        self._init_var()14        for c,idx in self.map_classes_idx.items():15            self._add_category(c,idx,supercategory)16    def _init_var(self):17        self.map_classes_idx = {c: ix+1 for ix,c in enumerate(self.classes)}  # coco is 1-indexed18        self.map_idx_classes = {v:k for k,v in self.map_classes_idx.items()}19    def _get_default_data(self):20        default_d = {21            "info": {22                "year" : 2019, 23                "version" : "", 24                "description" : "", 25                "contributor" : "", 26                "url" : "", 27                "date_created" : convert_datetime_to_string()28            },29            "images": [],30            "annotations": [],31            "categories": [],32            "licenses": [33                {34                    "id" : 1, 35                    "name" : "", 36                    "url" : ""37                }38            ]39        }40        return default_d41    def set_classes(self, classes):42        self.classes = classes43    def clear(self):44        self.data = self._get_default_data()45    def _add_category(self, name, id=None, supercategory=""):46        cat_id = len(self.data["categories"]) + 1 if id is None else id47        cat_data = {48                    "id" : cat_id, 49                    "name" : name, 50                    "supercategory" : supercategory51                }52        self.data["categories"].append(cat_data)53    def add_annot(self, id, img_id, img_cls, seg_data, meta_data={}, is_crowd=0):54        """55        CAN NOW SUPPORT MULTIPLE SEG POLYGONS56        DEPRECATED: ONLY SUPPORTS seg polygons of len 1 i.e. cannot support multiple polygons that refer to the same id"""57        if isinstance(img_cls, str):58            if img_cls not in self.map_classes_idx:...report_bvr_sponsorship_gift.py
Source:report_bvr_sponsorship_gift.py  
...19    _name = 'report.report_compassion.bvr_gift_sponsorship'20    def _get_report(self):21        return self.env['report']._get_report_from_name(22            'report_compassion.bvr_gift_sponsorship')23    def _get_default_data(self):24        """25        If no data is given for the report, use default values.26        :return: default mandatory data for the bvr report.27        """28        return {29            'doc_ids': self._ids,30            'product_ids': self.env[31                'recurring.contract'].get_sponsorship_gift_products().ids32        }33    @api.multi34    def render_html(self, data=None):35        """36        Construct the data for printing Payment Slips.37        :param data: data collected from the print wizard.38        :return: html rendered report39        """40        report = self._get_report()41        final_data = self._get_default_data()42        if data:43            final_data.update(data)44        final_data.update({45            'doc_model': report.model,  # recurring.contract46            'docs': self.env[report.model].browse(final_data['doc_ids']),47            'products': self.env['product.product'].browse(48                final_data['product_ids'])49        })50        return self.env['report'].render(report.report_name, final_data)51class ThreeBvrGiftSponsorship(models.Model):52    _inherit = 'report.report_compassion.bvr_gift_sponsorship'53    _name = 'report.report_compassion.3bvr_gift_sponsorship'54    def _get_report(self):55        return self.env['report']._get_report_from_name(...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!!
