<commit_before>import glob
import os

from fabric.api import task, local
from fabric.context_managers import lcd


class Test(object):
    def __init__(self, func, deps=[], needs_pypy=True, needs_rubyspec=False):
        self.func = func
        self.deps = deps
        self.needs_pypy = needs_pypy
        self.needs_rubyspec = needs_rubyspec

    def install_deps(self):
        local("pip install --use-mirrors {}".format(" ".join(self.deps)))

    def download_pypy(self):
        local("wget https://bitbucket.org/pypy/pypy/get/default.tar.bz2 -O `pwd`/../pypy.tar.bz2")
        local("bunzip2 `pwd`/../pypy.tar.bz2")
        local("tar -xf `pwd`/../pypy.tar -C `pwd`/../")
        [path_name] = glob.glob("../pypy-pypy*")
        path_name = os.path.abspath(path_name)
        with open("pypy_marker", "w") as f:
            f.write(path_name)

    def download_mspec(self):
        with lcd(".."):
            local("git clone --depth=100 --quiet https://github.com/rubyspec/mspec")

    def download_rubyspec(self):
        with lcd(".."):
            local("git clone --depth=100 --quiet https://github.com/rubyspec/rubyspec")

    def run_tests(self):
        env = {}
        if self.needs_pypy:
            with open("pypy_marker") as f:
                env["pypy_path"] = f.read()
        self.func(env)


@task
def install_requirements():
    t = TEST_TYPES[os.environ["TEST_TYPE"]]
    if t.deps:
        t.install_deps()
    if t.needs_pypy:
        t.download_pypy()
    if t.needs_rubyspec:
        t.download_mspec()
        t.download_rubyspec()


@task
def run_tests():
    t = TEST_TYPES[os.environ["TEST_TYPE"]]
    t.run_tests()


def run_own_tests(env):
    local("PYTHONPATH=$PYTHONPATH:{pypy_path} py.test".format(**env))


def run_rubyspec_untranslated(env):
    run_specs("bin/topaz_untranslated.py", prefix="PYTHONPATH=$PYTHONPATH:{pypy_path} ".format(**env))


def run_translate_tests(env):
    local("PYTHONPATH={pypy_path}:$PYTHONPATH python {pypy_path}/pypy/translator/goal/translate.py --batch -Ojit targetrupypy.py".format(**env))
    run_specs("`pwd`/topaz-c")


def run_specs(binary, prefix=""):
    # TODO: this list is temporary until we have all the machinery necessary to
    # run the full rubyspec directory (including the tagging feature)
    rubyspec_tests = [
        "language/and_spec.rb",
        "language/array_spec.rb",
        "language/match_spec.rb",
        "language/not_spec.rb",
        "language/numbers_spec.rb",
        "language/order_spec.rb",
        "language/splat_spec.rb",
        "language/undef_spec.rb",
        "language/unless_spec.rb",<commit_msg>another spec we can run<commit_after>import glob
import os

from fabric.api import task, local
from fabric.context_managers import lcd


class Test(object):
    def __init__(self, func, deps=[], needs_pypy=True, needs_rubyspec=False):
        self.func = func
        self.deps = deps
        self.needs_pypy = needs_pypy
        self.needs_rubyspec = needs_rubyspec

    def install_deps(self):
        local("pip install --use-mirrors {}".format(" ".join(self.deps)))

    def download_pypy(self):
        local("wget https://bitbucket.org/pypy/pypy/get/default.tar.bz2 -O `pwd`/../pypy.tar.bz2")
        local("bunzip2 `pwd`/../pypy.tar.bz2")
        local("tar -xf `pwd`/../pypy.tar -C `pwd`/../")
        [path_name] = glob.glob("../pypy-pypy*")
        path_name = os.path.abspath(path_name)
        with open("pypy_marker", "w") as f:
            f.write(path_name)

    def download_mspec(self):
        with lcd(".."):
            local("git clone --depth=100 --quiet https://github.com/rubyspec/mspec")

    def download_rubyspec(self):
        with lcd(".."):
            local("git clone --depth=100 --quiet https://github.com/rubyspec/rubyspec")

    def run_tests(self):
        env = {}
        if self.needs_pypy:
            with open("pypy_marker") as f:
                env["pypy_path"] = f.read()
        self.func(env)


@task
def install_requirements():
    t = TEST_TYPES[os.environ["TEST_TYPE"]]
    if t.deps:
        t.install_deps()
    if t.needs_pypy:
        t.download_pypy()
    if t.needs_rubyspec:
        t.download_mspec()
        t.download_rubyspec()


@task
def run_tests():
    t = TEST_TYPES[os.environ["TEST_TYPE"]]
    t.run_tests()


def run_own_tests(env):
    local("PYTHONPATH=$PYTHONPATH:{pypy_path} py.test".format(**env))


def run_rubyspec_untranslated(env):
    run_specs("bin/topaz_untranslated.py", prefix="PYTHONPATH=$PYTHONPATH:{pypy_path} ".format(**env))


def run_translate_tests(env):
    local("PYTHONPATH={pypy_path}:$PYTHONPATH python {pypy_path}/pypy/translator/goal/translate.py --batch -Ojit targetrupypy.py".format(**env))
    run_specs("`pwd`/topaz-c")


def run_specs(binary, prefix=""):
    # TODO: this list is temporary until we have all the machinery necessary to
    # run the full rubyspec directory (including the tagging feature)
    rubyspec_tests = [
        "language/and_spec.rb",
        "language/array_spec.rb",
        "language/match_spec.rb",
        "language/module_spec.rb",
        "language/not_spec.rb",
        "language/numbers_spec.rb",
        "language/order_spec.rb",
        "language/splat_spec.rb",
        "language/undef_spec.rb",
        "language/unless_spec.rb",
{'fraction_non_alphanumeric': 0.1486869450217268, 'fraction_numerical': 0.003778575477045154, 'mean_word_length': 2.7814285714285716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5477477', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1903, 'n_words': 330}