<commit_before>#! /usr/bin/env python

import os
import sys
from glob import glob
from optparse import OptionParser
from difflib import unified_diff

def test1(in_file):
    w = Writer()
    w.write("Testing the file: %s" % in_file)
    r = os.system('js -f builtins.js -f %s' % in_file)
    w.check(r)

def test2(in_file):
    w = Writer()
    w.write("Testing the file: %s" % in_file)
    r = os.system("python %s" % (in_file))
    w.check(r)

def test3(in_file, known_to_fail=False):
    w = Writer()
    w.write("%s [4]: " % in_file)
    r = os.system("python %s > /tmp/py.out" % (in_file))
    w.write(".")
    if r == 0:
        r = os.system("python py2js.py --include-builtins %s > /tmp/js.src 2> /tmp/py2js.err" % (in_file))
        w.write(".")
        if r == 0:
            r = os.system("js -f /tmp/js.src > /tmp/js.out 2> /tmp/js.err")
            w.write(".")
            if r == 0:
                r = os.system("diff /tmp/js.out /tmp/py.out > /tmp/js.diff")
                w.write(".")
    w.check(r, known_to_fail)

def main():
    parser = OptionParser(usage="%prog [options] filename",
        description="py2js tests.")
    parser.add_option("-a", "--run-all",
            action="store_true", dest="run_all",
            default=False, help="run all tests (including the known-to-fail)")
    options, args = parser.parse_args()
    if len(args) == 1:
        test3(args[0])
    else:
        test1("tests/test_builtins.js")
        files = glob("tests/test_*.py")
        for file in files:
            test2(file)
        files = glob("tests/basic/*.py") + glob("tests/functions/*.py")
        known_to_fail = [
                "tests/basic/vars.py",
                "tests/basic/nestedclass.py",
                "tests/basic/super.py",
                "tests/basic/kwargs.py",
                "tests/basic/float2int.py",
                "tests/basic/oo_inherit.py",
                "tests/basic/listcomp2.py",
                "tests/basic/del_dict.py",
                "tests/basic/del_local.py",
                "tests/basic/oo_diamond.py",
                "tests/basic/sumcomp.py",
                "tests/basic/del_array.py",
                "tests/basic/valueerror.py",
                "tests/basic/oo.py",
                "tests/basic/lambda.py",
                "tests/basic/try.py",
                "tests/basic/assign_slice.py",
                "tests/basic/vargs.py",
                "tests/basic/oo_static_inherit.py",
                "tests/basic/del_attr.py",
                "tests/basic/del_global.py",
                "tests/basic/del_slice.py",
                "tests/basic/generator.py",
                "tests/basic/raise.py",
                "tests/basic/docstring.py",

                "tests/functions/int.py",
                "tests/functions/sort_cmp.py",
                "tests/functions/ne.py",
                "tests/functions/aug.py",
                "tests/functions/isinstance.py",
                "tests/functions/floatdiv.py",
                "tests/functions/sort23.py",
                ]
        files.sort()
        for file in files:
            if options.run_all:
                test3(file, file in known_to_fail)<commit_msg>enabling passing tests<commit_after>#! /usr/bin/env python

import os
import sys
from glob import glob
from optparse import OptionParser
from difflib import unified_diff

def test1(in_file):
    w = Writer()
    w.write("Testing the file: %s" % in_file)
    r = os.system('js -f builtins.js -f %s' % in_file)
    w.check(r)

def test2(in_file):
    w = Writer()
    w.write("Testing the file: %s" % in_file)
    r = os.system("python %s" % (in_file))
    w.check(r)

def test3(in_file, known_to_fail=False):
    w = Writer()
    w.write("%s [4]: " % in_file)
    r = os.system("python %s > /tmp/py.out" % (in_file))
    w.write(".")
    if r == 0:
        r = os.system("python py2js.py --include-builtins %s > /tmp/js.src 2> /tmp/py2js.err" % (in_file))
        w.write(".")
        if r == 0:
            r = os.system("js -f /tmp/js.src > /tmp/js.out 2> /tmp/js.err")
            w.write(".")
            if r == 0:
                r = os.system("diff /tmp/js.out /tmp/py.out > /tmp/js.diff")
                w.write(".")
    w.check(r, known_to_fail)

def main():
    parser = OptionParser(usage="%prog [options] filename",
        description="py2js tests.")
    parser.add_option("-a", "--run-all",
            action="store_true", dest="run_all",
            default=False, help="run all tests (including the known-to-fail)")
    options, args = parser.parse_args()
    if len(args) == 1:
        test3(args[0])
    else:
        test1("tests/test_builtins.js")
        files = glob("tests/test_*.py")
        for file in files:
            test2(file)
        files = glob("tests/basic/*.py") + glob("tests/functions/*.py")
        known_to_fail = [
                "tests/basic/vars.py",
                "tests/basic/nestedclass.py",
                "tests/basic/super.py",
                "tests/basic/kwargs.py",
                "tests/basic/float2int.py",
                "tests/basic/oo_inherit.py",
                "tests/basic/listcomp2.py",
                "tests/basic/del_dict.py",
                "tests/basic/del_local.py",
                "tests/basic/oo_diamond.py",
                "tests/basic/sumcomp.py",
                "tests/basic/del_array.py",
                "tests/basic/valueerror.py",
                "tests/basic/oo.py",
                "tests/basic/lambda.py",
                "tests/basic/try.py",
                "tests/basic/assign_slice.py",
                "tests/basic/vargs.py",
                "tests/basic/oo_static_inherit.py",
                "tests/basic/del_attr.py",
                "tests/basic/del_global.py",
                "tests/basic/del_slice.py",
                "tests/basic/generator.py",
                "tests/basic/raise.py",
                "tests/basic/docstring.py",

                "tests/functions/sort_cmp.py",
                "tests/functions/ne.py",
                "tests/functions/aug.py",
                "tests/functions/isinstance.py",
                "tests/functions/floatdiv.py",
                "tests/functions/sort23.py",
                ]
        files.sort()
        for file in files:
            if options.run_all:
                test3(file, file in known_to_fail)
{'fraction_non_alphanumeric': 0.1532397918965789, 'fraction_numerical': 0.006936780703137317, 'mean_word_length': 1.6053388090349077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2520444', 'n_tokens_mistral': 2134, 'n_tokens_neox': 2039, 'n_words': 362}