def show_workspace(self, name): """Show specific workspace.""" if not self.workspace.exists(name): raise ValueError("Workspace `%s` doesn't exists." % name) color = Color() workspaces = self.workspace.list() self.logger.info("<== %s workspace ==>" % color.colored(name, "green")) self.logger.info("\tPath: %s" % workspaces[name]["path"]) self.logger.info("\tNumber of repositories: %s" % color.colored( len(workspaces[name]["repositories"]), "yellow")) repo_colored = color.colored("Repositories", "blue") path_colored = color.colored("Path", "blue") trepositories = PrettyTable( [repo_colored, path_colored, color.colored("+", "blue")]) trepositories.align[repo_colored] = "l" trepositories.align[path_colored] = "l" for repo_name in workspaces[name]["repositories"]: fullname = "%s/%s" % (name, repo_name) fullpath = find_path(fullname, self.config)[fullname] try: repo = Repository(fullpath) repo_scm = repo.get_scm() except RepositoryAdapterNotFound: repo_scm = None trepositories.add_row( [color.colored(repo_name, "cyan"), fullpath, repo_scm]) self.logger.info(trepositories)
def test_find_path_workspace(self): """Test find_path for workspace.""" res = find_path("yoda", self.config) self.assertEqual(4, len(res)) self.assertIn("yoda/yoda", res) self.assertIn("yoda/other", res) self.assertIn("yoda/1337", res) self.assertIn("sliim/yoda", res)
def execute(self, args): path_list = find_path(args.name, self.config, True) if len(path_list) == 0: self.logger.error("No matches for `%s`" % args.name) return False for name, path in path_list.items(): return self.__jump(path)
def print_workspace(self, name): """Print workspace update.""" path_list = find_path(name, self.config) if len(path_list) == 0: self.logger.error("No matches for `%s`" % name) return False for name, path in path_list.items(): self.print_update(name, path)
def test_find_path_no_matches(self): """Test find_path when no matches found.""" self.assertEqual({}, find_path("foo/bar", self.config))
def test_find_path_workspace_and_repository(self): """Test find_path for workspace/repository.""" res = find_path("yoda/1337", self.config) self.assertEqual(1, len(res)) self.assertIn("yoda/1337", res)
def test_find_path_repository(self): """Test find_path for repository.""" res = find_path("other", self.config) self.assertEqual(1, len(res)) self.assertIn("yoda/other", res)
def test_find_path_workspace_only(self): """Test find_path for workspace only.""" res = find_path("sliim", self.config, True) self.assertEqual(1, len(res)) self.assertIn("sliim", res)
def test_find_path_no_workspace(self): """Test find_path when no workspace registered.""" self.config = Config(self.sandbox.path + "/fake-config") self.assertEqual({}, find_path( "yoda/yoda", self.config))