Best Python code snippet using tempest_python
workspace.py
Source:workspace.py  
...63    @lockutils.synchronized('workspaces', external=True)64    def rename_workspace(self, old_name, new_name):65        self._populate()66        self._name_exists(old_name)67        self._workspace_name_exists(new_name)68        self.workspaces[new_name] = self.workspaces.pop(old_name)69        self._write_file()70    @lockutils.synchronized('workspaces', external=True)71    def move_workspace(self, name, path):72        self._populate()73        path = os.path.abspath(os.path.expanduser(path))74        self._name_exists(name)75        self._validate_path(path)76        self.workspaces[name] = path77        self._write_file()78    def _name_exists(self, name):79        if name not in self.workspaces:80            print("A workspace was not found with name: {0}".format(name))81            sys.exit(1)82    @lockutils.synchronized('workspaces', external=True)83    def remove_workspace(self, name):84        self._populate()85        self._name_exists(name)86        self.workspaces.pop(name)87        self._write_file()88    @lockutils.synchronized('workspaces', external=True)89    def list_workspaces(self):90        self._populate()91        self._validate_workspaces()92        return self.workspaces93    def _workspace_name_exists(self, name):94        if name in self.workspaces:95            print("A workspace already exists with name: {0}.".format(96                name))97            sys.exit(1)98    def _validate_path(self, path):99        if not os.path.exists(path):100            print("Path does not exist.")101            sys.exit(1)102    @lockutils.synchronized('workspaces', external=True)103    def register_new_workspace(self, name, path, init=False):104        """Adds the new workspace and writes out the new workspace config"""105        self._populate()106        path = os.path.abspath(os.path.expanduser(path))107        # This only happens when register is called from outside of init108        if not init:109            self._validate_path(path)110        self._workspace_name_exists(name)111        self.workspaces[name] = path112        self._write_file()113    def _validate_workspaces(self):114        if self.workspaces is not None:115            self.workspaces = {n: p for n, p in self.workspaces.items()116                               if os.path.exists(p)}117            self._write_file()118    def _write_file(self):119        with open(self.path, 'w') as f:120            f.write(yaml.dump(self.workspaces))121    def _populate(self):122        if not os.path.isfile(self.path):123            return124        with open(self.path, 'r') as f:...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!!
