<commit_before>from __future__ import print_function
import test_regression as tst

import subprocess
from collections import defaultdict

def determ_analysis(niter = 1000, fname = "report"):
    """
    Calls nosetests for a number of iterations and reports findings of
    nondeterminism to a file.
    """
    tbl_freq = defaultdict(int)
    col_freq = defaultdict(lambda: defaultdict(int))
    
    # collect
    for i in range(niter):
        rtn = subprocess.Popen(["nosetests", "-s"], stdout=subprocess.PIPE, 
                               stderr=subprocess.PIPE)
        out, err = rtn.communicate()
        for line in out.split("\n"):
            line = line.strip()
            if "table is different" in line.strip():
                tbl_name = line.split()[0]
                tbl_freq[tbl_name] += 1 
            if "Column" in line.strip():
                col_freq[tbl_name][line.split()[1]] += 1
    # normalize
    for tbl, dic in col_freq.iteritems():
        for col, freq in dic.iteritems():
            dic[col] = "{0:.2f}".format(float(freq) / tbl_freq[tbl])
    for k, v in tbl_freq.iteritems():
        tbl_freq[k] = "{0:.2f}".format(float(v) / n)
    
    # report<commit_msg>added a note about nosetests<commit_after>from __future__ import print_function
import test_regression as tst

import subprocess
from collections import defaultdict

def determ_analysis(niter = 1000, fname = "report"):
    """
    Calls nosetests for a number of iterations and reports findings of
    nondeterminism to a file.

    Note that the tests that nosetest will call must be configured to test the
    supposed deterministic cases.
    """
    tbl_freq = defaultdict(int)
    col_freq = defaultdict(lambda: defaultdict(int))
    
    # collect
    for i in range(niter):
        rtn = subprocess.Popen(["nosetests", "-s"], stdout=subprocess.PIPE, 
                               stderr=subprocess.PIPE)
        out, err = rtn.communicate()
        for line in out.split("\n"):
            line = line.strip()
            if "table is different" in line.strip():
                tbl_name = line.split()[0]
                tbl_freq[tbl_name] += 1 
            if "Column" in line.strip():
                col_freq[tbl_name][line.split()[1]] += 1
    # normalize
    for tbl, dic in col_freq.iteritems():
        for col, freq in dic.iteritems():
            dic[col] = "{0:.2f}".format(float(freq) / tbl_freq[tbl])
    for k, v in tbl_freq.iteritems():
        tbl_freq[k] = "{0:.2f}".format(float(v) / n)
    
    # report
{'fraction_non_alphanumeric': 0.11646269245953415, 'fraction_numerical': 0.0094749309119621, 'mean_word_length': 2.316753926701571, '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': '3991182', 'n_tokens_mistral': 819, 'n_tokens_neox': 775, 'n_words': 214}