<commit_before>import unittest
import logging

from gitbranchhealth.manager import BranchManager
from gitbranchhealth.branchhealth import BranchHealthConfig
from gitbranchhealth.branch import Branch
from testutil import GitRepoTest

class ManagerTestSuite(GitRepoTest):
  def setUp(self):
    self.__mParent = super(ManagerTestSuite, self)
    self.__mParent.setUp()
    self.__mConfig = self.__mParent.getConfig()
    self.__mTempDir = self.__mParent.getTempDir()

  def tearDown(self):
    self.__mParent.tearDown()

  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_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.DEBUG)
    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.DEBUG)
    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.DEBUG)
    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 allTests():
  unittest.main()

if __name__ == '__main__':
  allTests()
<commit_msg>Issue #13: Add test coverage for manager.py.<commit_after>import unittest
import logging

from gitbranchhealth.manager import BranchManager
from gitbranchhealth.branchhealth import BranchHealthConfig
from gitbranchhealth.branch import Branch
from testutil import GitRepoTest

class ManagerTestSuite(GitRepoTest):
  def setUp(self):
    self.__mParent = super(ManagerTestSuite, self)
    self.__mParent.setUp()
    self.__mConfig = self.__mParent.getConfig()
    self.__mTempDir = self.__mParent.getTempDir()

  def tearDown(self):
    self.__mParent.tearDown()

  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_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_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.DEBUG)
    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.DEBUG)
    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.DEBUG)
    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_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_delete_all_old_branches(self):
    # TODO: A test needs to be written for deleteAllOldBranches(), as soon as it
    #       is rewritten to conform to the new branch-object style (it's currently
    #       using the old tuple style). See issue #
    pass

def allTests():
  unittest.main()

if __name__ == '__main__':
  allTests()

{'fraction_non_alphanumeric': 0.10263240363522406, 'fraction_numerical': 0.013632090253838922, 'mean_word_length': 2.8175837320574164, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5410403', 'n_tokens_mistral': 1840, 'n_tokens_neox': 1797, 'n_words': 398}