Best Python code snippet using avocado_python
utils.py
Source:utils.py
1from collections import namedtuple2class StackEntry(namedtuple("StackEntry", "addr,name,offset,is_python")):3 def __str__(self):4 if self.offset:5 offset = ' +{}'.format(self.offset)6 else:7 offset = ''8 if self.is_python:9 is_python = ' [PY]'10 else:11 is_python = ''12 return '[0x{:x}] {}{}{}'.format(13 self.addr,14 self.name,15 offset,16 is_python,17 )18def split(rawtrace):19 lines = rawtrace.splitlines()20 for ln in lines:21 if not ln:22 continue23 addr, more = ln.split(':', 1)24 where = more.rfind('+')25 if where < 0:26 fname = more27 offset = 028 else:29 fname, offset = more.rsplit('+')30 offset = int(offset, 16)31 entry = StackEntry(int(addr, 16), fname, offset, is_python=False)32 yield entry33_sure_python_names = {34 '_PyEval_EvalFrameDefault',35 '_PyEval_EvalCodeWithName',36 'PyObject_Call',37 '_PyObject_FastCallDict',38 '_PyObject_FastCallDict',39 'PyCFuncPtr_call',40}41_maybe_python_names = {42 'function_call',43 'fast_function',44 'call_function',45 'method_call',46 'slot_tp_call',47 'builtin_exec',48 'partial_call',49} | _sure_python_names50def is_python_stack_sure(entry):51 return entry.name in _sure_python_names52def is_python_stack_maybe(entry):53 return any([entry.name in _maybe_python_names,54 entry.name.startswith('Py'),55 entry.name.startswith('_Py')])56def simple_processing(rawtrace):57 for i, entry in enumerate(split(rawtrace)):58 if i == 0 and entry.name == '_bt_callback':59 continue60 elif i == 1 and entry.name == '_sigtramp':61 continue62 else:63 yield entry64def skip_python(entry_iter):65 last_is_py = False66 skipped = []67 def show_skipped():68 repl = '<skipped {} Python entries>'.format(len(skipped))69 first = skipped[0]70 del skipped[:]71 return entry._replace(72 addr=first.addr,73 name=repl,74 offset=0,75 is_python=True,76 )77 for entry in entry_iter:78 if skip_python:79 if last_is_py:80 if is_python_stack_maybe(entry):81 skipped.append(entry)82 continue83 else:84 if skipped:85 yield show_skipped()86 last_is_py = False87 yield entry88 elif is_python_stack_sure(entry):89 last_is_py = True90 entry = entry._replace(is_python=True)91 yield entry92 else:93 if skipped:...
execute.py
Source:execute.py
1#! /usr/bin/env python2#3# Copyright (C) 2012-2014 SeaGoatVision - http://seagoatvision.org4#5# This file is part of SeaGoatVision.6#7# SeaGoatVision is free software: you can redistribute it and/or modify8# it under the terms of the GNU General Public License as published by9# the Free Software Foundation, either version 3 of the License, or10# (at your option) any later version.11#12# This program is distributed in the hope that it will be useful,13# but WITHOUT ANY WARRANTY; without even the implied warranty of14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15# GNU General Public License for more details.16#17# You should have received a copy of the GNU General Public License18# along with this program. If not, see <http://www.gnu.org/licenses/>.19# These are necessary for the executed code.20import cv2 # @UnusedImport21from cv2 import cv # @UnusedImport22import numpy as np # @UnusedImport23import sys24from seagoatvision.server.core.filter import Filter25import scipy.weave as weave26class Exec(Filter):27 """Create and edit a filter on the fly for testing purposes"""28 def __init__(self):29 Filter.__init__(self)30 self.code = ""31 self.is_python = True32 self._ccode = None33 self._has_error = False34 def set_code(self, code, is_python):35 self._has_error = False36 self.is_python = is_python37 try:38 self.code = code39 if self.is_python:40 self._ccode = compile(code, '<string>', 'exec')41 except BaseException as e:42 sys.stderr.write(str(e) + '\n')43 self._has_error = True44 def exec_python(self, image):45 if self._ccode is not None:46 exec self._ccode47 return image48 def exec_cpp(self, numpy_array):49 weave.inline(50 """51 // Convert numpy array to C++ Mat object52 // The image data is accessed directly, there is no copy53 cv::Mat image(Nnumpy_array[0], Nnumpy_array[1], CV_8UC(3), \54 numpy_array);55 """ + self.code,56 arg_names=['numpy_array'],57 headers=['<opencv2/opencv.hpp>', '<opencv2/gpu/gpu.hpp>'],58 extra_objects=["`pkg-config --cflags --libs opencv`"])59 return numpy_array60 def configure(self):61 self._has_error = False62 self.set_code(self.code, self.is_python)63 def execute(self, image):64 if self._has_error:65 return image66 try:67 if self.is_python:68 image = self.exec_python(image)69 else:70 image = self.exec_cpp(image)71 except BaseException as e:72 sys.stderr.write(str(e) + '\n')73 self._has_error = True...
helper_commands.py
Source:helper_commands.py
1import sublime2import sublime_plugin3class AnfReplaceCommand(sublime_plugin.TextCommand):4 def run(self, edit, content):5 self.view.replace(edit, sublime.Region(0, self.view.size()), content)6class AdvancedNewFileCommand(sublime_plugin.WindowCommand):7 def run(self, is_python=False, initial_path=None,8 rename=False, rename_file=None):9 args = {}10 if rename:11 args["is_python"] = is_python12 args["initial_path"] = initial_path13 args["rename_file"] = rename_file14 self.window.run_command("advanced_new_file_move", args)15 else:16 args["is_python"] = is_python17 args["initial_path"] = initial_path18 self.window.run_command("advanced_new_file_new", args)19class AnfRemoveRegionContentAndRegionCommand(sublime_plugin.TextCommand):20 def run(self, edit, region_key):21 regions = self.view.get_regions(region_key)22 for region in regions:23 self.view.erase(edit, region)...
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!!