<commit_before>import sys
if '/opt/pacha/lib' not in sys.path:
    sys.path.append('/opt/pacha/lib')
import unittest
from subprocess import Popen, PIPE
import os
import shutil
import upgrade

class TestUpgrade(unittest.TestCase):

    def tearDown(self):
        """Remove some croft"""
        try:
            shutil.rmtree('/tmp/pacha')
        except OSError:
            pass # maybe file was not downloaded

    def test_get(self):
        """Download a Pacha tar.gz file"""
        up = upgrade.Upgrade()
        link = up.download_link()
        tar_file = '/tmp/%s' % up.url_filename(link)
        up.get()
        expected = os.path.isfile(tar_file)
        self.assertTrue(expected)

    
    def test_is_number_true(self):
        """Pass a number and return True"""
        up = upgrade.Upgrade()
        number = '1'
        expected = up.is_number(number)
        self.assertTrue(expected)

    def test_is_number_false(self):
        """Pass a string and return False"""
        up = upgrade.Upgrade()
        string = "foo"
        expected = up.is_number(string)
        self.assertFalse(expected)

    def test_url_filename(self):
        """Pass a full url and return the filename"""
        url = 'http://pacha.googlecode.com/files/pacha-0.0.3.tar.gz'
        up = upgrade.Upgrade(url)
        actual = up.url_filename(url)
        expected = 'pacha-0.0.3.tar.gz'
        self.assertEqual(actual, expected)

    def test_url_check_true(self):
        """Validate a working url by returning True"""
        url = 'http://www.google.com'
        up = upgrade.Upgrade(url)
        expected = up.url_check()
        self.assertTrue(expected)

    def test_url_check_false(self):
        """Return False for a non working URL"""
        url = 'http://a_non_working_url.return.false'
        up = upgrade.Upgrade(url)
        expected = up.url_check()
        self.assertFalse(expected)

    def test_current_version(self):
        """Verify the current Pacha version"""
        up = upgrade.Upgrade()
        command = "pacha --version"
        get_version = Popen(command, shell=True, stdout=PIPE)
        # this return is a mouthful...
        expected = get_version.stdout.readlines()[0].split('\n')[0]
        actual = up.current_version()
        self.assertEqual(actual, expected)

    def test_download_link_list(self):
        """Open a url and get a list"""
        url = 'http://code.google.com/p/pacha'
        up = upgrade.Upgrade(url)
        actual = type(up.download_link()) is list
        self.assertTrue(actual)

    def test_download_link(self):
        """Pass an html file object and return a valid download link"""
        up = upgrade.Upgrade('/tmp/index.html')
        html = open('/tmp/index.html', 'w')
        html.write("""<a href="http://pacha.googlecode.com/files/pacha-0.0.3.tar.gz">pacha-0.0.3.tar.gz</a>""")
        html.close()
        expected = 'http://pacha.googlecode.com/files/pacha-0.0.3.tar.gz'
        actual = up.download_link()[0]
        self.assertEqual(actual, expected)


if __name__ == '__main__':<commit_msg>finally a passing test for .repos<commit_after>import sys
if '../' not in sys.path:
    sys.path.append('../')
import unittest
from subprocess import Popen, PIPE
import os
import shutil
import upgrade

class TestUpgrade(unittest.TestCase):

    def tearDown(self):
        """Remove some croft"""
        try:
            shutil.rmtree('/tmp/pacha')
            shutil.rmtree('/tmp/upgrade')
            os.remove('/tmp/pacha')
        except OSError:
            pass # maybe file was not downloaded

    def test_get(self):
        """Download a Pacha tar.gz file"""
        up = upgrade.Upgrade()
        link = up.download_link()
        tar_file = '/tmp/%s' % up.url_filename(link)
        up.get()
        expected = os.path.isfile(tar_file)
        self.assertTrue(expected)

    
    def test_is_number_true(self):
        """Pass a number and return True"""
        up = upgrade.Upgrade()
        number = '1'
        expected = up.is_number(number)
        self.assertTrue(expected)

    def test_is_number_false(self):
        """Pass a string and return False"""
        up = upgrade.Upgrade()
        string = "foo"
        expected = up.is_number(string)
        self.assertFalse(expected)

    def test_url_filename(self):
        """Pass a full url and return the filename"""
        url = 'http://pacha.googlecode.com/files/pacha-0.0.3.tar.gz'
        up = upgrade.Upgrade(url)
        actual = up.url_filename(url)
        expected = 'pacha-0.0.3.tar.gz'
        self.assertEqual(actual, expected)

    def test_url_check_true(self):
        """Validate a working url by returning True"""
        url = 'http://www.google.com'
        up = upgrade.Upgrade(url)
        expected = up.url_check()
        self.assertTrue(expected)

#    def test_url_check_false(self):
#        """Return False for a non working URL"""
#        url = 'http://a_non_working_url.return.false'
#        up = upgrade.Upgrade(url)
#        expected = up.url_check()
#        self.assertFalse(expected)

    def test_current_version(self):
        """Verify the current Pacha version"""
        up = upgrade.Upgrade()
        command = "pacha --version"
        get_version = Popen(command, shell=True, stdout=PIPE)
        # this return is a mouthful...
        expected = get_version.stdout.readlines()[0].split('\n')[0]
        actual = up.current_version()
        self.assertEqual(actual, expected)

    def test_download_link_list(self):
        """Open a url and get a list"""
        url = 'http://code.google.com/p/pacha'
        up = upgrade.Upgrade(url)
        actual = type(up.download_link()) is list
        self.assertTrue(actual)

    def test_download_link(self):
        """Pass an html file object and return a valid download link"""
        up = upgrade.Upgrade('/tmp/index.html')
        html = open('/tmp/index.html', 'w')
        html.write("""<a href="http://pacha.googlecode.com/files/pacha-0.0.3.tar.gz">pacha-0.0.3.tar.gz</a>""")
        html.close()
        expected = 'http://pacha.googlecode.com/files/pacha-0.0.3.tar.gz'
        actual = up.download_link()[0]
        self.assertEqual(actual, expected)

    def test_repos_check_true(self):
        """Return True if there is a .repos file"""
        open('/tmp/.repos', 'w')
        up = upgrade.Upgrade(repo_file = '/tmp/.repos')
        actual = up.repos_check()
        self.assertTrue(actual)


if __name__ == '__main__':
{'fraction_non_alphanumeric': 0.13498069498069498, 'fraction_numerical': 0.005868725868725869, 'mean_word_length': 2.3398659102630224, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7534944', 'n_tokens_mistral': 2054, 'n_tokens_neox': 2006, 'n_words': 449}