def test_mark_branch_health(self): options = self.__mParent.getConfig() manager = BranchManager(options) branches = manager.getLocalBranches() for someBranch in branches: someBranch.markHealth() self.assertEquals(Branch.OLD, someBranch.getHealth()) # Now, create a new branch so we can test if it returns the value # Branch.HEALTHY repo = options.getRepo() repo.create_head('aNewBranch') repo.heads.aNewBranch.checkout() # Create a new file so we have a new commit fh = open( os.path.join(self.__mParent.getTempDir(), "testrepo/myNewFile"), "w") fh.write("TEST123") fh.close() index = repo.index index.add(['myNewFile']) index.commit("A new commit") newBranch = Branch('refs/heads/aNewBranch', options) newBranch.markHealth() self.assertEquals(Branch.HEALTHY, newBranch.getHealth())
def test_get_prefix(self): conf = self.__mConfig manager = BranchManager(conf) pref1 = manager.getPrefix(conf.getRepo().heads) pref2 = manager.getPrefix(conf.getRepo().remotes.origin.refs[0]) self.assertEquals('refs/heads/', pref1) self.assertEquals('refs/remotes/', pref2)
def test_mark_branch_health(self): options = self.__mParent.getConfig() manager = BranchManager(options) branches = manager.getLocalBranches() for someBranch in branches: someBranch.markHealth() self.assertEquals(Branch.OLD, someBranch.getHealth()) # Now, create a new branch so we can test if it returns the value # Branch.HEALTHY repo = options.getRepo() repo.create_head('aNewBranch') repo.heads.aNewBranch.checkout() # Create a new file so we have a new commit fh = open(os.path.join(self.__mParent.getTempDir(), "testrepo/myNewFile"), "w") fh.write("TEST123") fh.close() index = repo.index index.add(['myNewFile']) index.commit("A new commit") newBranch = Branch('refs/heads/aNewBranch', options) newBranch.markHealth() self.assertEquals(Branch.HEALTHY, newBranch.getHealth())
def test_get_local_branches(self): manager = BranchManager(self.__mConfig) branches = manager.getLocalBranches() branchNames = manager.getLocalBranchNames() names = [] for branch in branches: names.append(branch.getName()) self.assertEquals(branchNames, names)
def test_branch_sorting(self): options = self.__mParent.getConfig() manager = BranchManager(options) branches = [ x.getName() for x in sorted(manager.getLocalBranches(), branchDateComparator) ] expectedBranches = ['bug-14', 'bug-44', 'bug-27', 'bug-143', 'master'] self.assertEqual(expectedBranches, branches)
def test_get_branch_map(self): # Set 'days' to 1 so that all branches should be old # Initially test local branches conf = self.__mConfig config = BranchHealthConfig(conf.getRepoPath(), conf.getRemoteName(), 1, aLogLevel=logging.ERROR) manager = BranchManager(config) branchMap = manager.getBranchMap() expectedBranches = ['bug-14', 'bug-44', 'bug-27', 'bug-143'] actualBranches = [] for someBranch in branchMap: self.assertEquals(Branch.OLD, someBranch.getHealth()) actualBranches.append(someBranch.getName()) self.assertEquals(expectedBranches, actualBranches) # Now perform the same stuff, but on origin as a remote config = BranchHealthConfig(conf.getRepoPath(), 'origin', 1, aLogLevel=logging.ERROR) manager = BranchManager(config) actualBranches = [] for someBranch in branchMap: self.assertEquals(Branch.OLD, someBranch.getHealth()) actualBranches.append(someBranch.getName()) self.assertEquals(expectedBranches, actualBranches) # Finally, check the same thing, but using "all" option: config = BranchHealthConfig(conf.getRepoPath(), 'all', 1, aLogLevel=logging.ERROR) manager = BranchManager(config) branchMap = manager.getBranchMap() expectedBranches = ['bug-14', 'bug-14', 'bug-44', 'bug-44', 'bug-27', 'bug-27', 'bug-143', 'bug-143'] actualBranches = [] for someBranch in branchMap: self.assertEquals(Branch.OLD, someBranch.getHealth()) actualBranches.append(someBranch.getName()) self.assertEquals(expectedBranches, actualBranches)
def test_delete_all_old_local_branches(self): manager = BranchManager(self.__mConfig) self.assertTrue(len(manager.getLocalBranches()) != 1) branchesToDelete = manager.getLocalBranches() manager.deleteAllOldBranches(branchesToDelete) # Master should be the only branch remaining self.assertTrue(len(manager.getLocalBranches()) == 1)
def test_get_branch_map(self): # Set 'days' to 1 so that all branches should be old # Initially test local branches conf = self.__mConfig config = BranchHealthConfig(conf.getRepoPath(), conf.getRemoteName(), 1, aLogLevel=logging.ERROR) manager = BranchManager(config) branchMap = manager.getBranchMap() expectedBranches = ['bug-14', 'bug-44', 'bug-27', 'bug-143'] actualBranches = [] for someBranch in branchMap: self.assertEquals(Branch.OLD, someBranch.getHealth()) actualBranches.append(someBranch.getName()) self.assertEquals(expectedBranches, actualBranches) # Now perform the same stuff, but on origin as a remote config = BranchHealthConfig(conf.getRepoPath(), 'origin', 1, aLogLevel=logging.ERROR) manager = BranchManager(config) actualBranches = [] for someBranch in branchMap: self.assertEquals(Branch.OLD, someBranch.getHealth()) actualBranches.append(someBranch.getName()) self.assertEquals(expectedBranches, actualBranches) # Finally, check the same thing, but using "all" option: config = BranchHealthConfig(conf.getRepoPath(), 'all', 1, aLogLevel=logging.ERROR) manager = BranchManager(config) branchMap = manager.getBranchMap() expectedBranches = [ 'bug-14', 'bug-14', 'bug-44', 'bug-44', 'bug-27', 'bug-27', 'bug-143', 'bug-143' ] actualBranches = [] for someBranch in branchMap: self.assertEquals(Branch.OLD, someBranch.getHealth()) actualBranches.append(someBranch.getName()) self.assertEquals(expectedBranches, actualBranches)
def test_delete_all_old_remote_branches(self): config = BranchHealthConfig(self.__mConfig.getRepoPath(), 'origin', 1) manager = BranchManager(config) self.assertTrue(len(manager.getLocalBranches()) != 1) self.assertTrue(len(config.getRepo().remotes.origin.refs) != 2) branchMap = manager.getBranchMap() branchesToDelete = [x for x in branchMap] manager.deleteAllOldBranches(branchesToDelete) # Master should be the only branch remaining self.assertTrue(len(manager.getLocalBranches()) == 1) # Master and HEAD should be remaining self.assertTrue(len(config.getRepo().remotes.origin.refs) == 2)
def test_manager_construction(self): manager = BranchManager(self.__mConfig) localBranches = manager.getLocalBranchNames() expectedBranches = ['bug-14', 'bug-143', 'bug-27', 'bug-44', 'master'] self.assertEquals(expectedBranches, localBranches)
def test_branch_sorting(self): options = self.__mParent.getConfig() manager = BranchManager(options) branches = [x.getName() for x in sorted(manager.getLocalBranches(), branchDateComparator)] expectedBranches = ['bug-14', 'bug-44', 'bug-27', 'bug-143', 'master'] self.assertEqual(expectedBranches, branches)