Best Python code snippet using slash
monitor.py
Source:monitor.py  
...228                self.ip = self.ipython_shell.get_ipython()229            self._mglobals = glbs230            return glbs231    232    def get_current_namespace(self):233        """Return current namespace, i.e. globals() if not debugging,234        or a dictionary containing both locals() and globals() 235        for current frame when debugging"""236        ns = {}237        glbs = self.mglobals()238239        if self.pdb_frame is None:240            ns.update(glbs)241        else:242            ns.update(glbs)243            ns.update(self.pdb_locals)244        245        # Add magics to ns so we can show help about them on the Object246        # Inspector247        if self.ip:248            line_magics = self.ip.magics_manager.magics['line']249            cell_magics = self.ip.magics_manager.magics['cell']250            ns.update(line_magics)251            ns.update(cell_magics)252        253        return ns254    255    def get_reference_namespace(self, name):256        """Return namespace where reference name is defined,257        eventually returns the globals() if reference has not yet been defined"""258        glbs = self.mglobals()259        if self.pdb_frame is None:260            return glbs261        else:262            lcls = self.pdb_locals263            if name in lcls:264                return lcls265            else:266                return glbs267    268    def get_globals_keys(self):269        """Return globals() keys or globals() and locals() keys if debugging"""270        ns = self.get_current_namespace()271        return ns.keys()272    273    def isdefined(self, obj, force_import=False):274        """Return True if object is defined in current namespace"""275        ns = self.get_current_namespace()276        return isdefined(obj, force_import=force_import, namespace=ns)277278    def toggle_inputhook_flag(self, state):279        """Toggle the input hook flag280        281        The only purpose of this flag is to unblock the PyOS_InputHook282        callback when text is available in stdin (see sitecustomize.py)"""283        self.inputhook_flag = state284        285    def set_timeout(self, timeout):286        """Set monitor timeout (in milliseconds!)"""287        self.timeout = float(timeout)/1000.288        289    def set_auto_refresh(self, state):290        """Enable/disable namespace browser auto refresh feature"""291        self.auto_refresh = state292        293    def enable_refresh_after_eval(self):294        self.refresh_after_eval = True295        296    #------ Notifications297    def refresh(self):298        """Refresh variable explorer in ExternalPythonShell"""299        communicate(self.n_request, dict(command="refresh"))300        301    def refresh_from_inputhook(self):302        """Refresh variable explorer from the PyOS_InputHook.303        See sitecustomize.py"""304        # Refreshing variable explorer, except on first input hook call305        # (otherwise, on slow machines, this may freeze Spyder)306        if self.first_inputhook_call:307            self.first_inputhook_call = False308        else:309            self.refresh()310        311    def register_pdb_session(self, pdb_obj):312        self.pdb_obj = pdb_obj313314    def notify_pdb_step(self, fname, lineno):315        """Notify the ExternalPythonShell regarding pdb current frame"""316        communicate(self.n_request,317                    dict(command="pdb_step", data=(fname, lineno)))318319    def set_spyder_breakpoints(self):320        """Set all Spyder breakpoints in active pdb session"""321        if not self.pdb_obj:322            return323        self.pdb_obj.set_spyder_breakpoints()    324    325    def notify_open_file(self, fname, lineno=1):326        """Open file in Spyder's editor"""327        communicate(self.n_request,328                    dict(command="open_file", data=(fname, lineno)))329        330    #------ Code completion / Calltips331    def _eval(self, text):332        """333        Evaluate text and return (obj, valid)334        where *obj* is the object represented by *text*335        and *valid* is True if object evaluation did not raise any exception336        """337        assert isinstance(text, (str, unicode))338        ns = self.get_current_namespace()339        try:340            return eval(text, ns), True341        except:342            return None, False343            344    def get_dir(self, objtxt):345        """Return dir(object)"""346        obj, valid = self._eval(objtxt)347        if valid:348            return getobjdir(obj)349                350    def iscallable(self, objtxt):351        """Is object callable?"""352        obj, valid = self._eval(objtxt)353        if valid:354            return callable(obj)355    356    def get_arglist(self, objtxt):357        """Get func/method argument list"""358        obj, valid = self._eval(objtxt)359        if valid:360            return getargtxt(obj)361    362    def get__doc__(self, objtxt):363        """Get object __doc__"""364        obj, valid = self._eval(objtxt)365        if valid:366            return obj.__doc__367    368    def get_doc(self, objtxt):369        """Get object documentation"""370        obj, valid = self._eval(objtxt)371        if valid:372            return getdoc(obj)373    374    def get_source(self, objtxt):375        """Get object source"""376        obj, valid = self._eval(objtxt)377        if valid:378            return getsource(obj)379            380    def getmodcomplist(self, name, path):381        """Return module completion list for object named *name*"""382        return module_completion(name, path)383                384    #------ Other385    def is_array(self, name):386        """Return True if object is an instance of class numpy.ndarray"""387        ns = self.get_current_namespace()388        try:389            import numpy390            return isinstance(ns[name], numpy.ndarray)391        except ImportError:392            return False393394    def is_image(self, name):395        """Return True if object is an instance of class PIL.Image.Image"""396        ns = self.get_current_namespace()397        try:398            from spyderlib.pil_patch import Image399            return isinstance(ns[name], Image.Image)400        except ImportError:401            return False402403    def getcwd(self):404        """Return current working directory"""405        return os.getcwdu()406    407    def setcwd(self, dirname):408        """Set current working directory"""409        try:410            dirname = dirname.decode('utf-8')411        except (UnicodeError, TypeError):412            pass413        return os.chdir(dirname)414            415    def getenv(self):416        """Return os.environ"""417        return os.environ.copy()418        419    def setenv(self):420        """Set os.environ"""421        env = read_packet(self.i_request)422        os.environ = env423424    def getsyspath(self):425        """Return sys.path[:]"""426        import sys427        return sys.path[:]        428        429    def setlocal(self, name, value):430        """431        Set local reference value432        Not used right now - could be useful in the future433        """434        self._mlocals[name] = value435        436    def set_remote_view_settings(self):437        """438        Set the namespace remote view settings439        (see the namespace browser widget)440        """441        self.remote_view_settings = read_packet(self.i_request)442        self.enable_refresh_after_eval()443        444    def update_remote_view(self):445        """446        Return remote view of globals()447        """448        settings = self.remote_view_settings449        if settings:450            ns = self.get_current_namespace()451            more_excluded_names = ['In', 'Out'] if self.ipython_shell else None452            remote_view = make_remote_view(ns, settings, more_excluded_names)453            communicate(self.n_request,454                        dict(command="remote_view", data=remote_view))455        456    def saveglobals(self):457        """Save globals() into filename"""458        ns = self.get_current_namespace()459        from spyderlib.utils.iofuncs import iofunctions460        settings = read_packet(self.i_request)461        filename = read_packet(self.i_request)462        more_excluded_names = ['In', 'Out'] if self.ipython_shell else None463        data = get_remote_data(ns, settings, mode='picklable',464                               more_excluded_names=more_excluded_names).copy()465        return iofunctions.save(data, filename)466        467    def loadglobals(self):468        """Load globals() from filename"""469        glbs = self.mglobals()470        from spyderlib.utils.iofuncs import iofunctions471        filename = read_packet(self.i_request)472        ext = read_packet(self.i_request)473        load_func = iofunctions.load_funcs[ext]474        data, error_message = load_func(filename)475        if error_message:476            return error_message477        for key in data.keys():478            new_key = fix_reference_name(key, blacklist=glbs.keys())479            if new_key != key:480                data[new_key] = data.pop(key)481        try:482            glbs.update(data)483        except Exception, error:484            return str(error)485        self.refresh_after_eval = True486        487    def getglobal(self, name):488        """489        Get global reference value490        """491        ns = self.get_current_namespace()492        return ns[name]493        494    def setglobal(self, name):495        """496        Set global reference value497        """498        ns = self.get_reference_namespace(name)499        ns[name] = read_packet(self.i_request)500        self.refresh_after_eval = True501        502    def delglobal(self, name):503        """504        Del global reference505        """
...forward_call.py
Source:forward_call.py  
...34        self._name_stack.clear()35        self._forward_stack.clear()36        self.calls.clear()37        self.visit(self._tree)38    def get_current_namespace(self):39        """Get the namespace when visit the AST node"""40        namespace = '.'.join(self._name_stack)41        return namespace42    @classmethod43    def get_call_name(cls, node):44        """Get functional call name."""45        if not isinstance(node, ast.Call):46            return None47        return pasta.dump(node.func)48    def visit_ClassDef(self, node):49        """Callback function when visit AST tree"""50        self._name_stack.append(node.name)51        self.generic_visit(node)52        self._name_stack.pop()53    def visit_FunctionDef(self, node):54        """Callback function when visit AST tree"""55        namespace = self.get_current_namespace()56        if namespace:57            func_name = f'{namespace}.{node.name}'58        else:59            func_name = node.name60        func_name = f'{self.get_current_namespace()}.{node.name}'61        is_in_chain = func_name in self.calls or node.name == 'forward'62        if is_in_chain:63            self._forward_stack.append(func_name)64        if node.name == 'forward':65            self.calls.update({func_name: node})66        self._function_list.update({func_name: node})67        self.generic_visit(node)68        if is_in_chain:69            self._forward_stack.pop()70    def visit_Call(self, node):71        """Callback function when visit AST tree"""72        for arg in node.args:73            self.visit(arg)74        for keyword in node.keywords:75            self.visit(keyword.value)76        func_name = self.get_call_name(node)77        if isinstance(node.func, ast.Name):78            if func_name not in ['super', 'str', 'repr']:79                if self._forward_stack:80                    self.calls.update({func_name: self._function_list.get(func_name)})81                self.visit(node.func)82        else:83            if self._forward_stack:84                if func_name.startswith('self.'):85                    whole_name = f'{self.get_current_namespace()}.{func_name.split(".")[-1]}'86                    self.calls.update({whole_name: self._function_list.get(whole_name)})87                else:88                    self.calls.update({func_name: self._function_list.get(func_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!!
