<commit_before># Automated tests for the `vcs-repo-mgr' package.
#
# Author: <NAME> <<EMAIL>>
# Last Change: May 10, 2014
# URL: https://github.com/xolox/python-vcs-repo-mgr

# Standard library modules.
import logging
import os
import shutil
import tempfile
import unittest

# External dependencies.
import coloredlogs

# The module we're testing.
from vcs_repo_mgr import GitRepo, HgRepo

class VcsRepoMgrTestCase(unittest.TestCase):

    def setUp(self):
        coloredlogs.install()
        coloredlogs.set_level(logging.DEBUG)
        self.git_directory = tempfile.mkdtemp()
        self.hg_directory = tempfile.mkdtemp()
        self.export_directory = tempfile.mkdtemp()

    def tearDown(self):
        shutil.rmtree(self.git_directory)
        shutil.rmtree(self.hg_directory)
        shutil.rmtree(self.export_directory)

    def test_git_repo(self):
        self.repo_test_helper(repo=GitRepo(local=self.git_directory,
                                           remote='https://github.com/xolox/python-verboselogs.git'),
                              main_branch='master')

    def test_hg_repo(self):
        self.repo_test_helper(repo=HgRepo(local=self.hg_directory,
                                          remote='https://bitbucket.org/ianb/virtualenv'),
                              main_branch='trunk')

    def repo_test_helper(self, repo, main_branch):

        # Test repository.exists on a non existing repository.
        self.assertEqual(repo.exists, False)

        # Test repository.create().
        repo.create()

        # Test repository.exists on an existing repository.
        self.assertEqual(repo.exists, True)

        # Test repository.update().
        repo.update()

        # Test repository.__repr__().
        self.assertTrue(isinstance(repr(repo), str))

        # Test repository branches.
        self.assertEqual(len(repo.branches), 1)
        self.assertTrue(main_branch in repo.branches)

        # Test repository export.
        repo.export(self.export_directory)
        num_files = 0
        for root, dirs, files in os.walk(self.export_directory):
            num_files += len(files)
        self.assertTrue(num_files > 0)
        shutil.rmtree(self.export_directory)

        # Test repository.find_revision_number().
        revision_number = repo.find_revision_number(main_branch)
        self.assertEqual(type(revision_number), int)
        self.assertTrue(revision_number > 0)

        # Test repository.find_revision_id().
        revision_id = repo.find_revision_id(main_branch)<commit_msg>Bug fix for last commit<commit_after># Automated tests for the `vcs-repo-mgr' package.
#
# Author: <NAME> <<EMAIL>>
# Last Change: May 10, 2014
# URL: https://github.com/xolox/python-vcs-repo-mgr

# Standard library modules.
import logging
import os
import shutil
import tempfile
import unittest

# External dependencies.
import coloredlogs

# The module we're testing.
from vcs_repo_mgr import GitRepo, HgRepo

class VcsRepoMgrTestCase(unittest.TestCase):

    def setUp(self):
        coloredlogs.install()
        coloredlogs.set_level(logging.DEBUG)
        self.git_directory = tempfile.mkdtemp()
        self.hg_directory = tempfile.mkdtemp()
        self.export_directory = tempfile.mkdtemp()

    def tearDown(self):
        shutil.rmtree(self.git_directory)
        shutil.rmtree(self.hg_directory)
        shutil.rmtree(self.export_directory)

    def test_git_repo(self):
        self.repo_test_helper(repo=GitRepo(local=self.git_directory,
                                           remote='https://github.com/xolox/python-verboselogs.git'),
                              main_branch='master')

    def test_hg_repo(self):
        self.repo_test_helper(repo=HgRepo(local=self.hg_directory,
                                          remote='https://bitbucket.org/ianb/virtualenv'),
                              main_branch='trunk')

    def repo_test_helper(self, repo, main_branch):

        # Test repository.exists on a non existing repository.
        self.assertEqual(repo.exists, False)

        # Test repository.create().
        repo.create()

        # Test repository.exists on an existing repository.
        self.assertEqual(repo.exists, True)

        # Test repository.update().
        repo.update()

        # Test repository.__repr__().
        self.assertTrue(isinstance(repr(repo), str))

        # Test repository branches.
        self.assertEqual(len(repo.branches), 1)
        self.assertTrue(main_branch in repo.branches)

        # Test repository export.
        repo.export(self.export_directory, main_branch)
        num_files = 0
        for root, dirs, files in os.walk(self.export_directory):
            num_files += len(files)
        self.assertTrue(num_files > 0)
        shutil.rmtree(self.export_directory)

        # Test repository.find_revision_number().
        revision_number = repo.find_revision_number(main_branch)
        self.assertEqual(type(revision_number), int)
        self.assertTrue(revision_number > 0)

        # Test repository.find_revision_id().
        revision_id = repo.find_revision_id(main_branch)
{'fraction_non_alphanumeric': 0.09892682926829269, 'fraction_numerical': 0.003902439024390244, 'mean_word_length': 2.5400552486187844, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '316341', 'n_tokens_mistral': 1514, 'n_tokens_neox': 1475, 'n_words': 280}