<commit_before>import unittest
import os
import shutil
import getpass
import sys

import pacha

from time           import strftime

from guachi         import ConfigMapper
from mock           import MockSys
from pacha          import rebuild, host 
from pacha.hg       import hg_push_update


class TestRebuild(unittest.TestCase):
    username = getpass.getuser()

    def setUp(self):
        """Will setup just once for all tests"""
        if os.path.isdir('/tmp/remote_pacha'):
            shutil.rmtree('/tmp/remote_pacha')
        if os.path.isdir('/tmp/localhost'):
            shutil.rmtree('/tmp/localhost')
        if os.path.isdir('/tmp/test_pacha'):
            shutil.rmtree('/tmp/test_pacha')
        if os.path.isdir('/tmp/%s' % host.hostname()):
            shutil.rmtree('/tmp/%s' % host.hostname())
        if os.path.isdir('/tmp/pacha_test'):
            shutil.rmtree('/tmp/pacha_test')
        os.mkdir('/tmp/test_pacha')
        config = open('/tmp/test_pacha/pacha.conf', 'w')
        config.write('[DEFAULT]\n')
        config.write('pacha.ssh.user = %s\n' % self.username)
        config.write('pacha.host = %s\n' % host.hostname())
        config.write('pacha.hosts.path = /tmp/remote_pacha/hosts\n')
        config.close()
        # static mappings for file locations 
        pacha.DB_DIR = '/tmp/pacha_test'
        pacha.DB_FILE ='/tmp/pacha_test/pacha_test.db' 
        pacha.permissions.DB_FILE ='/tmp/pacha_test/pacha_test.db' 
        pacha.hg.DB_FILE ='/tmp/pacha_test/pacha_test.db' 
        pacha.database.DB_FILE = '/tmp/pacha_test/pacha_test.db'
        pacha.database.DB_DIR = '/tmp/pacha_test'
        pacha.daemon.PID_DIR = '/tmp/pacha_test'

        # write a config file 
        os.makedirs('/tmp/pacha_test')
        conf = open('/tmp/pacha_test/pacha.conf', 'w')
        conf.write('[DEFAULT]\n')
        conf.write('pacha.ssh.user = %s\n' % self.username)
        conf.write('pacha.host = %s\n' % host.hostname())
        conf.write('pacha.hosts.path = /tmp/remote_pacha/hosts\n')
        conf.close()
        



    def tearDown(self):
        """Will run last at the end of all tests"""
        if os.path.isdir('/tmp/remote_pacha'):
            shutil.rmtree('/tmp/remote_pacha')
        if os.path.isdir('/tmp/localhost'):
            shutil.rmtree('/tmp/localhost')
        if os.path.isdir('/tmp/test_pacha'):
            shutil.rmtree('/tmp/test_pacha')
        if os.path.isdir('/tmp/pacha_test'):
            shutil.rmtree('/tmp/pacha_test')

        try:
            shutil.rmtree('/tmp/test_pacha')
            shutil.rmtree('/tmp/remote_pacha')
            shutil.rmtree('/tmp/localhost')
            shutil.rmtree('/tmp/single_dir')
        except OSError:
            pass # nevermind if you could not delete this guy


    def test_retrieve_files_single(self):
        """Gets a single directory from a remote host"""
        os.makedirs('/tmp/remote_pacha/localhost/another_dir')
        os.makedirs('/tmp/remote_pacha/localhost/single_dir')
        remote_file = open('/tmp/remote_pacha/localhost/single_dir/remote.txt', 'w')
        remote_file.write("remote file")
        remote_file.close()
        self.assertTrue(os.path.isfile('/tmp/remote_pacha/localhost/single_dir/remote.txt'))
        server = "%s@%s" % (self.username, host.hostname()) 
        run = rebuild.Rebuild(server=server,
                        hostname='localhost', <commit_msg>added a dir removal that was missing from setUp<commit_after>import unittest
import os
import shutil
import getpass
import sys

import pacha

from time           import strftime

from guachi         import ConfigMapper
from mock           import MockSys
from pacha          import rebuild, host 
from pacha.hg       import hg_push_update


class TestRebuild(unittest.TestCase):
    username = getpass.getuser()

    def setUp(self):
        """Will setup just once for all tests"""
        if os.path.isdir('/tmp/remote_pacha'):
            shutil.rmtree('/tmp/remote_pacha')
        if os.path.isdir('/tmp/localhost'):
            shutil.rmtree('/tmp/localhost')
        if os.path.isdir('/tmp/test_pacha'):
            shutil.rmtree('/tmp/test_pacha')
        if os.path.isdir('/tmp/%s' % host.hostname()):
            shutil.rmtree('/tmp/%s' % host.hostname())
        if os.path.isdir('/tmp/pacha_bucket'):
            shutil.rmtree('/tmp/pacha_bucket')
        if os.path.isdir('/tmp/pacha_test'):
            shutil.rmtree('/tmp/pacha_test')
        os.mkdir('/tmp/test_pacha')
        config = open('/tmp/test_pacha/pacha.conf', 'w')
        config.write('[DEFAULT]\n')
        config.write('pacha.ssh.user = %s\n' % self.username)
        config.write('pacha.host = %s\n' % host.hostname())
        config.write('pacha.hosts.path = /tmp/remote_pacha/hosts\n')
        config.close()
        # static mappings for file locations 
        pacha.DB_DIR = '/tmp/pacha_test'
        pacha.DB_FILE ='/tmp/pacha_test/pacha_test.db' 
        pacha.permissions.DB_FILE ='/tmp/pacha_test/pacha_test.db' 
        pacha.hg.DB_FILE ='/tmp/pacha_test/pacha_test.db' 
        pacha.database.DB_FILE = '/tmp/pacha_test/pacha_test.db'
        pacha.database.DB_DIR = '/tmp/pacha_test'
        pacha.daemon.PID_DIR = '/tmp/pacha_test'

        # write a config file 
        os.makedirs('/tmp/pacha_test')
        conf = open('/tmp/pacha_test/pacha.conf', 'w')
        conf.write('[DEFAULT]\n')
        conf.write('pacha.ssh.user = %s\n' % self.username)
        conf.write('pacha.host = %s\n' % host.hostname())
        conf.write('pacha.hosts.path = /tmp/remote_pacha/hosts\n')
        conf.close()
        



    def tearDown(self):
        """Will run last at the end of all tests"""
        if os.path.isdir('/tmp/remote_pacha'):
            shutil.rmtree('/tmp/remote_pacha')
        if os.path.isdir('/tmp/localhost'):
            shutil.rmtree('/tmp/localhost')
        if os.path.isdir('/tmp/test_pacha'):
            shutil.rmtree('/tmp/test_pacha')
        if os.path.isdir('/tmp/pacha_test'):
            shutil.rmtree('/tmp/pacha_test')
        if os.path.isdir('/tmp/pacha_bucket'):
            shutil.rmtree('/tmp/pacha_bucket')

        try:
            shutil.rmtree('/tmp/test_pacha')
            shutil.rmtree('/tmp/remote_pacha')
            shutil.rmtree('/tmp/localhost')
            shutil.rmtree('/tmp/single_dir')
        except OSError:
            pass # nevermind if you could not delete this guy


    def test_retrieve_files_single(self):
        """Gets a single directory from a remote host"""
        os.makedirs('/tmp/remote_pacha/localhost/another_dir')
        os.makedirs('/tmp/remote_pacha/localhost/single_dir')
        remote_file = open('/tmp/remote_pacha/localhost/single_dir/remote.txt', 'w')
        remote_file.write("remote file")
        remote_file.close()
        self.assertTrue(os.path.isfile('/tmp/remote_pacha/localhost/single_dir/remote.txt'))
        server = "%s@%s" % (self.username, host.hostname()) 
        run = rebuild.Rebuild(server=server,
                        hostname='localhost', 
{'fraction_non_alphanumeric': 0.14447592067988668, 'fraction_numerical': 0.0, 'mean_word_length': 2.282659228265923, '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': '2855854', 'n_tokens_mistral': 2465, 'n_tokens_neox': 2296, 'n_words': 372}