<commit_before>#!/usr/bin/env python3

import sys
import os
import shutil
import unittest

import git_test_fixture
import mvtools_test_fixture

import git_visitor_pull

class GitVisitorPullTest(unittest.TestCase):

    def makeFilename(self):
        self.internal_counter += 1
        filename = "testfile_%s.txt" % self.internal_counter
        return filename

    def makeContent(self):
        self.internal_counter += 1
        content = "rubbish_content_%s" % self.internal_counter
        return content

    def setUp(self):
        v, r = self.delegate_setUp()
        if not v:
            self.tearDown()
            self.fail(r)

    def delegate_setUp(self):

        self.internal_counter = 0

        v, r = mvtools_test_fixture.makeAndGetTestFolder("git_visitor_pull_test_base")
        if not v:
            return v, r
        self.test_base_dir = r[0] # base test folder. shared amongst other test cases
        self.test_dir = r[1] # test folder, specific for each test case (i.e. one level above self.test_base_dir)

        # test repos paths
        self.first_repo = os.path.join(self.test_dir, "first")
        self.second_repo = os.path.join(self.test_dir, "second")
        self.third_repo = os.path.join(self.test_dir, "third")

        # creates test repos
        v, r = git_test_fixture.git_initRepo(self.test_dir, "third", True)
        if not v:
            return v, r

        # clone third into second
        v, r = git_test_fixture.git_cloneRepo(self.third_repo, self.second_repo, "origin")
        if not v:
            return v, r

        # commit something onto second
        self.file1 = self.makeFilename()
        self.second_file1 = os.path.join(self.second_repo, self.file1)
        v, r = git_test_fixture.git_createAndCommit(self.second_repo, self.file1, self.makeContent(), "commit_msg")
        if not v:
            return v, r

        # clone second into first
        v, r = git_test_fixture.git_cloneRepo(self.second_repo, self.first_repo, "origin")
        if not v:
            return v, r

        return True, ""

    def tearDown(self):
        shutil.rmtree(self.test_base_dir)

    def testVisitorPull(self):

        # create fourth  and fifth repos - clones of second
        fourth_repo = os.path.join(self.test_dir, "fourth")
        v, r = git_test_fixture.git_cloneRepo(self.second_repo, fourth_repo, "origin")
        if not v:
            self.fail(r)

        fifth_repo = os.path.join(self.test_dir, "fifth")
        v, r = git_test_fixture.git_cloneRepo(self.second_repo, fifth_repo, "origin")
        if not v:
            self.fail(r)

        # commit something else onto second
        file2 = self.makeFilename()
        fourth_file2 = os.path.join(fourth_repo, file2)
        fifth_file2 = os.path.join(fifth_repo, file2)
        v, r = git_test_fixture.git_createAndCommit(self.second_repo, file2, self.makeContent(), "commit_msg")
        if not v:
            return v, r

        # call visitor_pull on first and fourth
        repos = [fourth_repo, fifth_repo]
        opts = {"xor-remotename": "origin"}

        r = git_visitor_pull.visitor_pull(repos, opts)<commit_msg>cosmetic correction on a comment<commit_after>#!/usr/bin/env python3

import sys
import os
import shutil
import unittest

import git_test_fixture
import mvtools_test_fixture

import git_visitor_pull

class GitVisitorPullTest(unittest.TestCase):

    def makeFilename(self):
        self.internal_counter += 1
        filename = "testfile_%s.txt" % self.internal_counter
        return filename

    def makeContent(self):
        self.internal_counter += 1
        content = "rubbish_content_%s" % self.internal_counter
        return content

    def setUp(self):
        v, r = self.delegate_setUp()
        if not v:
            self.tearDown()
            self.fail(r)

    def delegate_setUp(self):

        self.internal_counter = 0

        v, r = mvtools_test_fixture.makeAndGetTestFolder("git_visitor_pull_test_base")
        if not v:
            return v, r
        self.test_base_dir = r[0] # base test folder. shared amongst other test cases
        self.test_dir = r[1] # test folder, specific for each test case (i.e. one level above self.test_base_dir)

        # test repos paths
        self.first_repo = os.path.join(self.test_dir, "first")
        self.second_repo = os.path.join(self.test_dir, "second")
        self.third_repo = os.path.join(self.test_dir, "third")

        # creates test repos
        v, r = git_test_fixture.git_initRepo(self.test_dir, "third", True)
        if not v:
            return v, r

        # clone third into second
        v, r = git_test_fixture.git_cloneRepo(self.third_repo, self.second_repo, "origin")
        if not v:
            return v, r

        # commit something onto second
        self.file1 = self.makeFilename()
        self.second_file1 = os.path.join(self.second_repo, self.file1)
        v, r = git_test_fixture.git_createAndCommit(self.second_repo, self.file1, self.makeContent(), "commit_msg")
        if not v:
            return v, r

        # clone second into first
        v, r = git_test_fixture.git_cloneRepo(self.second_repo, self.first_repo, "origin")
        if not v:
            return v, r

        return True, ""

    def tearDown(self):
        shutil.rmtree(self.test_base_dir)

    def testVisitorPull(self):

        # create fourth and fifth repos - clones of second
        fourth_repo = os.path.join(self.test_dir, "fourth")
        v, r = git_test_fixture.git_cloneRepo(self.second_repo, fourth_repo, "origin")
        if not v:
            self.fail(r)

        fifth_repo = os.path.join(self.test_dir, "fifth")
        v, r = git_test_fixture.git_cloneRepo(self.second_repo, fifth_repo, "origin")
        if not v:
            self.fail(r)

        # commit something else onto second
        file2 = self.makeFilename()
        fourth_file2 = os.path.join(fourth_repo, file2)
        fifth_file2 = os.path.join(fifth_repo, file2)
        v, r = git_test_fixture.git_createAndCommit(self.second_repo, file2, self.makeContent(), "commit_msg")
        if not v:
            return v, r

        # call visitor_pull on first and fourth
        repos = [fourth_repo, fifth_repo]
        opts = {"xor-remotename": "origin"}

        r = git_visitor_pull.visitor_pull(repos, opts)
{'fraction_non_alphanumeric': 0.0946969696969697, 'fraction_numerical': 0.005050505050505051, 'mean_word_length': 2.418015102481122, 'pattern_counts': {'":': 2, '<': 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': '643507', 'n_tokens_mistral': 2067, 'n_tokens_neox': 2012, 'n_words': 481}