<commit_before>import unittest
import os
import sys
from contextlib import contextmanager
try:
	# Python 2
	import StringIO
except:
	# Python 3
	import io as StringIO
import checkpy
import checkpy.downloader as downloader
import checkpy.caches as caches
import checkpy.entities.exception as exception

@contextmanager
def capturedOutput():
    new_out, new_err = StringIO.StringIO(), StringIO.StringIO()
    old_out, old_err = sys.stdout, sys.stderr
    try:
        sys.stdout, sys.stderr = new_out, new_err
        yield sys.stdout, sys.stderr
    finally:
        sys.stdout, sys.stderr = old_out, old_err

class Base(unittest.TestCase):
    def tearDown(self):
        caches.clearAllCaches()

class BaseClean(unittest.TestCase):
    def setUp(self):
        downloader.clean()

    def tearDown(self):
        downloader.clean()
        caches.clearAllCaches()

class TestDownload(BaseClean):
    def setUp(self):
        super().setUp()
        self.fileName = "some.py"
        with open(self.fileName, "w") as f:
            f.write("print(\"foo\")")

    def tearDown(self):
        super().tearDown()
        os.remove(self.fileName)

    def test_spelledOutLink(self):
        downloader.download("https://github.com/jelleas/tests")
        testerResult = checkpy.test(self.fileName)
        self.assertTrue(testerResult.testResults[0].hasPassed)

    def test_incompleteLink(self):
        downloader.download("jelleas/tests")
        testerResult = checkpy.test(self.fileName)
        self.assertTrue(testerResult.testResults[0].hasPassed)

    def test_deadLink(self):
        with capturedOutput() as (out, err):
            downloader.download("jelleas/doesnotexist")
        self.assertTrue("DownloadError" in out.getvalue().strip())

class TestUpdate(BaseClean):
    def test_clean(self):
        downloader.update()
        with capturedOutput() as (out, err):
            downloader.list()
        self.assertEqual(out.getvalue().strip(), "")

    def test_oneDownloaded(self):
        downloader.download("jelleas/tests")
        with capturedOutput() as (out, err):
            downloader.update()
        self.assertEqual(\
            out.getvalue().split("\n")[0].strip(),
            "Finished downloading: https://github.com/jelleas/tests"
        )<commit_msg>TestList<commit_after>import unittest
import os
import sys
from contextlib import contextmanager
try:
	# Python 2
	import StringIO
except:
	# Python 3
	import io as StringIO
import checkpy
import checkpy.downloader as downloader
import checkpy.caches as caches
import checkpy.entities.exception as exception

@contextmanager
def capturedOutput():
    new_out, new_err = StringIO.StringIO(), StringIO.StringIO()
    old_out, old_err = sys.stdout, sys.stderr
    try:
        sys.stdout, sys.stderr = new_out, new_err
        yield sys.stdout, sys.stderr
    finally:
        sys.stdout, sys.stderr = old_out, old_err

class Base(unittest.TestCase):
    def tearDown(self):
        caches.clearAllCaches()

class BaseClean(unittest.TestCase):
    def setUp(self):
        downloader.clean()

    def tearDown(self):
        downloader.clean()
        caches.clearAllCaches()

class TestDownload(BaseClean):
    def setUp(self):
        super().setUp()
        self.fileName = "some.py"
        with open(self.fileName, "w") as f:
            f.write("print(\"foo\")")

    def tearDown(self):
        super().tearDown()
        os.remove(self.fileName)

    def test_spelledOutLink(self):
        downloader.download("https://github.com/jelleas/tests")
        testerResult = checkpy.test(self.fileName)
        self.assertTrue(testerResult.testResults[0].hasPassed)

    def test_incompleteLink(self):
        downloader.download("jelleas/tests")
        testerResult = checkpy.test(self.fileName)
        self.assertTrue(testerResult.testResults[0].hasPassed)

    def test_deadLink(self):
        with capturedOutput() as (out, err):
            downloader.download("jelleas/doesnotexist")
        self.assertTrue("DownloadError" in out.getvalue().strip())

class TestUpdate(BaseClean):
    def test_clean(self):
        downloader.update()
        with capturedOutput() as (out, err):
            downloader.list()
        self.assertEqual(out.getvalue().strip(), "")

    def test_oneDownloaded(self):
        downloader.download("jelleas/tests")
        with capturedOutput() as (out, err):
            downloader.update()
        self.assertEqual(\
            out.getvalue().split("\n")[0].strip(),
            "Finished downloading: https://github.com/jelleas/tests"
        )

class TestList(BaseClean):
    def test_clean(self):
        with capturedOutput() as (out, err):
            downloader.list()
        self.assertEqual(out.getvalue().strip(), "")

    def test_oneDownloaded(self):
        downloader.download("jelleas/tests")
        with capturedOutput() as (out, err):
            downloader.list()
        output = out.getvalue()
        self.assertTrue("tests" in output and "jelleas" in output)
{'fraction_non_alphanumeric': 0.11823447173956461, 'fraction_numerical': 0.0019972039145196726, 'mean_word_length': 2.8972762645914396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 43, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3094403', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1497, 'n_words': 309}