<commit_before># Copyright (c) 2015 Intracom S.A. Telecom Solutions. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v1.0 which accompanies this distribution,
# and is available at http://www.eclipse.org/legal/epl-v10.html

"""Unittest Module for util/file.py."""

import itertools
import os
import shutil
import subprocess
import unittest
import util.file_ops as f


class FileTestFileExist(unittest.TestCase):
    """Contains methods for testing methods within file.py
    Methods checked: testing file.py: file_exists, is_file_exe, make_file_exe
    check_files_exist, check_files_executable
    """
    def createfile(self):
        pass

    @classmethod
    def setUpClass(cls):
        """Creates a batch of files stored under fillist (filelist =
        namlist x extlist). Created files are stored under self.virtualfolder
        which is removed in tearDown()
        """
        cls.virtualfolder = "testfolder"

        if os.path.exists(cls.virtualfolder):
            shutil.rmtree(cls.virtualfolder)

        namlist = ['foo1', 'foo2', 'foo3', 'foo4', 'foo5', 'foo6', 'foo7',
                       'foo8', 'foo9']
        extlist = ['.txt', '.mp3', '.mp4', '.avi', '.sh', '.png', '.jpg']
        fillist = []

        # Define the test folder list.
        cls.tstlist = ['foo1.txt', 'foo1.mp3', 'foo1.avi', 'foo2.txt',
                       'foo2.txt', 'foo2.txt' ]
        cls.chmode = [0o777, 0o777, 777]

        for res in itertools.product(namlist, extlist):
            joinedname = ''.join(res)
            fillist.append(joinedname)

        subprocess.check_output(["mkdir", cls.virtualfolder])

        for i in range(0, len(fillist)):
            subprocess.check_output(["touch", fillist[i]])
            mvcommand = 'mv' + ' ' + fillist[i] + ' ' + cls.virtualfolder
            subprocess.check_output(mvcommand, shell=True)

        index = 3
        cls.filepath = []
        while index !=0:
            name = './' + cls.virtualfolder + '/' + 'foo'+ str(index) + '.txt'
            cls.filepath.append(name)
            index -= 1

    def test01_file_exists(self):
        """Checks if foo1.txt exists within self.virtualfolder folder
        """
        self.assertTrue(f.file_exists(self.filepath[0]))

    def test02_file_exists(self):
        """Checks if foo2.txt exists within the self.virtualfolder folder
        """
        self.assertTrue(f.file_exists(self.filepath[1]))

    def test03_file_exists(self):
        """Checks if foo3.txt exist within the self.virtualfolder.
        """
        self.assertTrue(f.file_exists(self.filepath[2]))

    def test04_is_file_exe(self):
        """Checks if foo1.txt within the self.virtualfolder is exe
        """
        os.chmod(self.filepath[0], self.chmode[0])
        self.assertTrue(f.is_file_exe(self.filepath[0]))


    def test05_check_files_exist(self):
        """Checks file existence within the virtualfolder
        """
        # Change to the virtualfolder directory and test the tstlist if files
        # exist with the virtualfolder<commit_msg>Reduce length of setUpClass() in file_test<commit_after># Copyright (c) 2015 Intracom S.A. Telecom Solutions. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v1.0 which accompanies this distribution,
# and is available at http://www.eclipse.org/legal/epl-v10.html

"""Unittest Module for util/file.py."""

import itertools
import os
import shutil
import subprocess
import unittest
import util.file_ops as f


class FileTestFileExist(unittest.TestCase):
    """Contains methods for testing methods within file.py
    Methods checked: testing file.py: file_exists, is_file_exe, make_file_exe
    check_files_exist, check_files_executable
    """
    def createfile(self):
        pass

    @classmethod
    def setUpClass(cls):
        """Creates a batch of files stored under fillist (filelist =
        namlist x extlist). Created files are stored under self.virtualfolder
        """
        cls.virtualfolder = "testfolder"

        if os.path.exists(cls.virtualfolder):
            shutil.rmtree(cls.virtualfolder)
        subprocess.check_output(["mkdir", cls.virtualfolder])
        namlist = ['foo1', 'foo2', 'foo3', 'foo4', 'foo5', 'foo6', 'foo7']
        extlist = ['.txt', '.mp3', '.mp4', '.avi', '.sh', '.png', '.jpg']
        fillist = []
        # Define the test folder list.
        cls.tstlist = ['foo1.txt', 'foo1.mp3', 'foo1.avi', 'foo2.txt']
        cls.chmode = [0o777, 0o777, 777]

        for res in itertools.product(namlist, extlist):
            joinedname = ''.join(res)
            fillist.append(joinedname)

        for i in range(0, len(fillist)):
            subprocess.check_output(["touch", fillist[i]])
            mvcommand = 'mv' + ' ' + fillist[i] + ' ' + cls.virtualfolder
            subprocess.check_output(mvcommand, shell=True)

        index = 3
        cls.filepath = []
        while index !=0:
            name = './' + cls.virtualfolder + '/' + 'foo'+ str(index) + '.txt'
            cls.filepath.append(name)
            index -= 1

    def test01_file_exists(self):
        """Checks if foo1.txt exists within self.virtualfolder folder
        """
        self.assertTrue(f.file_exists(self.filepath[0]))

    def test02_file_exists(self):
        """Checks if foo2.txt exists within the self.virtualfolder folder
        """
        self.assertTrue(f.file_exists(self.filepath[1]))

    def test03_file_exists(self):
        """Checks if foo3.txt exist within the self.virtualfolder.
        """
        self.assertTrue(f.file_exists(self.filepath[2]))

    def test04_is_file_exe(self):
        """Checks if foo1.txt within the self.virtualfolder is exe
        """
        os.chmod(self.filepath[0], self.chmode[0])
        self.assertTrue(f.is_file_exe(self.filepath[0]))

    def test05_check_files_exist(self):
        """Checks file existence within the virtualfolder
        """
        # Change to the virtualfolder directory and test the tstlist if files
        # exist with the virtualfolder
{'fraction_non_alphanumeric': 0.12008415601229973, 'fraction_numerical': 0.019096941252629875, 'mean_word_length': 2.6310223266745005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2105822', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1861, 'n_words': 489}