<commit_before>import os
import shutil
import sys
import time
from selenium import webdriver
from seleniumbase.config import settings
from seleniumbase.core.style_sheet import style
from seleniumbase.fixtures import page_actions

LATEST_REPORT_DIR = settings.LATEST_REPORT_DIR
ARCHIVE_DIR = settings.REPORT_ARCHIVE_DIR
HTML_REPORT = settings.HTML_REPORT
RESULTS_TABLE = settings.RESULTS_TABLE


def get_timestamp():
    return str(int(time.time() * 1000))


def process_successes(test, test_count):
    return(
        '"%s","%s","%s","%s","%s","%s","%s","%s","%s"' % (
            test_count,
            "Passed!",
            "*",
            "*",
            "*",
            test.browser,
            get_timestamp()[:-3],
            test.id(),
            "*"))


def process_failures(test, test_count, browser_type):
    bad_page_image = "failure_%s.jpg" % test_count
    bad_page_data = "failure_%s.txt" % test_count
    page_actions.save_screenshot(
        test.driver, bad_page_image, folder=LATEST_REPORT_DIR)
    page_actions.save_test_failure_data(
        test.driver, bad_page_data, browser_type, folder=LATEST_REPORT_DIR)
    exc_info = '(Unknown Failure)'
    exception = sys.exc_info()[1]
    if exception:
        if hasattr(exception, 'msg'):
            exc_info = exception.msg
        elif hasattr(exception, 'message'):
            exc_info = exception.message
        else:
            pass
    return(
        '"%s","%s","%s","%s","%s","%s","%s","%s","%s"' % (
            test_count,
            "FAILED!",
            bad_page_data,
            bad_page_image,
            test.driver.current_url,
            test.browser,
            get_timestamp()[:-3],
            test.id(),
            exc_info))


def clear_out_old_report_logs(archive_past_runs=True, get_log_folder=False):
        abs_path = os.path.abspath('.')
        file_path = abs_path + "/%s" % LATEST_REPORT_DIR
        if not os.path.exists(file_path):
            os.makedirs(file_path)

        if archive_past_runs:
            archive_timestamp = int(time.time())
            if not os.path.exists("%s/../%s/" % (file_path, ARCHIVE_DIR)):
                os.makedirs("%s/../%s/" % (file_path, ARCHIVE_DIR))
            archive_dir = "%s/../%s/report_%s" % (
                file_path, ARCHIVE_DIR, archive_timestamp)
            shutil.move(file_path, archive_dir)
            os.makedirs(file_path)
            if get_log_folder:
                return archive_dir
        else:
            # Just delete bad pages to make room for the latest run.
            filelist = [f for f in os.listdir(
                "./%s" % LATEST_REPORT_DIR) if f.startswith("failure_") or (
                f == HTML_REPORT) or (f.startswith("automation_failure")) or (
                f == RESULTS_TABLE)]
            for f in filelist:
                os.remove("%s/%s" % (file_path, f))


def add_bad_page_log_file(page_results_list):
    abs_path = os.path.abspath('.')
    file_path = abs_path + "/%s" % LATEST_REPORT_DIR
    log_file = "%s/%s" % (file_path, RESULTS_TABLE)
    f = open(log_file, 'w')
    h_p1 = '''"Num","Result","Failure Info","Screenshot",'''
    h_p2 = '''"URL","Browser","Epoch Time",'''
    h_p3 = '''"Test Case Address","Additional Info"\n'''
    page_header = h_p1 + h_p2 + h_p3
    f.write(page_header)
    for line in page_results_list:
        f.write("%s\n" % line)
    f.close()
<commit_msg>"Failure Info" becomes "Stacktrace" in the CSV Report<commit_after>import os
import shutil
import sys
import time
from selenium import webdriver
from seleniumbase.config import settings
from seleniumbase.core.style_sheet import style
from seleniumbase.fixtures import page_actions

LATEST_REPORT_DIR = settings.LATEST_REPORT_DIR
ARCHIVE_DIR = settings.REPORT_ARCHIVE_DIR
HTML_REPORT = settings.HTML_REPORT
RESULTS_TABLE = settings.RESULTS_TABLE


def get_timestamp():
    return str(int(time.time() * 1000))


def process_successes(test, test_count):
    return(
        '"%s","%s","%s","%s","%s","%s","%s","%s","%s"' % (
            test_count,
            "Passed!",
            "*",
            "*",
            "*",
            test.browser,
            get_timestamp()[:-3],
            test.id(),
            "*"))


def process_failures(test, test_count, browser_type):
    bad_page_image = "failure_%s.jpg" % test_count
    bad_page_data = "failure_%s.txt" % test_count
    page_actions.save_screenshot(
        test.driver, bad_page_image, folder=LATEST_REPORT_DIR)
    page_actions.save_test_failure_data(
        test.driver, bad_page_data, browser_type, folder=LATEST_REPORT_DIR)
    exc_info = '(Unknown Failure)'
    exception = sys.exc_info()[1]
    if exception:
        if hasattr(exception, 'msg'):
            exc_info = exception.msg
        elif hasattr(exception, 'message'):
            exc_info = exception.message
        else:
            pass
    return(
        '"%s","%s","%s","%s","%s","%s","%s","%s","%s"' % (
            test_count,
            "FAILED!",
            bad_page_data,
            bad_page_image,
            test.driver.current_url,
            test.browser,
            get_timestamp()[:-3],
            test.id(),
            exc_info))


def clear_out_old_report_logs(archive_past_runs=True, get_log_folder=False):
        abs_path = os.path.abspath('.')
        file_path = abs_path + "/%s" % LATEST_REPORT_DIR
        if not os.path.exists(file_path):
            os.makedirs(file_path)

        if archive_past_runs:
            archive_timestamp = int(time.time())
            if not os.path.exists("%s/../%s/" % (file_path, ARCHIVE_DIR)):
                os.makedirs("%s/../%s/" % (file_path, ARCHIVE_DIR))
            archive_dir = "%s/../%s/report_%s" % (
                file_path, ARCHIVE_DIR, archive_timestamp)
            shutil.move(file_path, archive_dir)
            os.makedirs(file_path)
            if get_log_folder:
                return archive_dir
        else:
            # Just delete bad pages to make room for the latest run.
            filelist = [f for f in os.listdir(
                "./%s" % LATEST_REPORT_DIR) if f.startswith("failure_") or (
                f == HTML_REPORT) or (f.startswith("automation_failure")) or (
                f == RESULTS_TABLE)]
            for f in filelist:
                os.remove("%s/%s" % (file_path, f))


def add_bad_page_log_file(page_results_list):
    abs_path = os.path.abspath('.')
    file_path = abs_path + "/%s" % LATEST_REPORT_DIR
    log_file = "%s/%s" % (file_path, RESULTS_TABLE)
    f = open(log_file, 'w')
    h_p1 = '''"Num","Result","Stacktrace","Screenshot",'''
    h_p2 = '''"URL","Browser","Epoch Time",'''
    h_p3 = '''"Test Case Address","Additional Info"\n'''
    page_header = h_p1 + h_p2 + h_p3
    f.write(page_header)
    for line in page_results_list:
        f.write("%s\n" % line)
    f.close()

{'fraction_non_alphanumeric': 0.13848396501457727, 'fraction_numerical': 0.0037900874635568515, 'mean_word_length': 2.3615874571288584, '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': '6593961', 'n_tokens_mistral': 2339, 'n_tokens_neox': 2279, 'n_words': 422}