Best Python code snippet using tempest_python
workspace.py
Source:workspace.py  
...65    @lockutils.synchronized('workspaces', external=True)66    def rename_workspace(self, old_name, new_name):67        self._populate()68        self._name_exists(old_name)69        self._invalid_name_check(new_name)70        self._workspace_name_exists(new_name)71        self.workspaces[new_name] = self.workspaces.pop(old_name)72        self._write_file()73    @lockutils.synchronized('workspaces', external=True)74    def move_workspace(self, name, path):75        self._populate()76        path = os.path.abspath(os.path.expanduser(path)) if path else path77        self._name_exists(name)78        self._validate_path(path)79        self.workspaces[name] = path80        self._write_file()81    def _name_exists(self, name):82        if name not in self.workspaces:83            print("A workspace was not found with name: {0}".format(name))84            sys.exit(1)85    @lockutils.synchronized('workspaces', external=True)86    def remove_workspace_entry(self, name):87        self._populate()88        self._name_exists(name)89        workspace_path = self.workspaces.pop(name)90        self._write_file()91        return workspace_path92    @lockutils.synchronized('workspaces', external=True)93    def remove_workspace_directory(self, workspace_path):94        self._validate_path(workspace_path)95        shutil.rmtree(workspace_path)96    @lockutils.synchronized('workspaces', external=True)97    def list_workspaces(self):98        self._populate()99        self._validate_workspaces()100        return self.workspaces101    def _workspace_name_exists(self, name):102        if name in self.workspaces:103            print("A workspace already exists with name: {0}.".format(104                name))105            sys.exit(1)106    def _invalid_name_check(self, name):107        if not name:108            print("None or empty name is specified."109                  " Please specify correct name for workspace.")110            sys.exit(1)111    def _validate_path(self, path):112        if not path:113            print("None or empty path is specified for workspace."114                  " Please specify correct workspace path.")115            sys.exit(1)116        if not os.path.exists(path):117            print("Path does not exist.")118            sys.exit(1)119    @lockutils.synchronized('workspaces', external=True)120    def register_new_workspace(self, name, path, init=False):121        """Adds the new workspace and writes out the new workspace config"""122        self._populate()123        path = os.path.abspath(os.path.expanduser(path)) if path else path124        # This only happens when register is called from outside of init125        if not init:126            self._validate_path(path)127        self._invalid_name_check(name)128        self._workspace_name_exists(name)129        self.workspaces[name] = path130        self._write_file()131    def _validate_workspaces(self):132        if self.workspaces is not None:133            self.workspaces = {n: p for n, p in self.workspaces.items()134                               if os.path.exists(p)}135            self._write_file()136    def _write_file(self):137        with open(self.path, 'w') as f:138            f.write(yaml.dump(self.workspaces))139    def _populate(self):140        if not os.path.isfile(self.path):141            return...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!!
