<commit_before>__author__ = 'roy'

import os
import logging
from logging import FileHandler
import time

from nose.plugins.base import Plugin


logs_run_dir = time.strftime("%Y%m%d-%H%M%S")


class LogPerTest(Plugin):
    """
    This plugin create a log file per each tests run by nose.

    Usage examples:
      > nosetests --with-logpertest
    """

    name = 'logpertest'

    def options(self, parser, env=os.environ):
        super(LogPerTest, self).options(parser, env=env)

    def configure(self, options, conf):
        super(LogPerTest, self).configure(options, conf)
        if not self.enabled:
            return

        self.logs_run_dir = logs_run_dir
        if not os.path.exists(self.logs_run_dir):
            os.makedirs(self.logs_run_dir)

    def beforeTest(self, test):
        log = logging.getLogger()

        # check or create the directory of the current test context exist
        dir_path = os.path.join(self.logs_run_dir, str(test.context))
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)

        # add a file handler to write to the the test log file
        test.log_handler = FileHandler(os.path.join(dir_path, str(test)))
        log.addHandler(test.log_handler)

    def afterTest(self, test):
        log = logging.getLogger()
        log.removeHandler(test.log_handler)
<commit_msg>updated the docstring in LogPerTest<commit_after>__author__ = 'roy'

import os
import logging
from logging import FileHandler
import time

from nose.plugins.base import Plugin


logs_run_dir = time.strftime("%Y%m%d-%H%M%S")


class LogPerTest(Plugin):
    """
    This plugin creates a file per each test run by nose
    and store the logs in it.

    Usage examples:
      > nosetests --with-logpertest
    """

    name = 'logpertest'

    def options(self, parser, env=os.environ):
        super(LogPerTest, self).options(parser, env=env)

    def configure(self, options, conf):
        super(LogPerTest, self).configure(options, conf)
        if not self.enabled:
            return

        self.logs_run_dir = logs_run_dir
        if not os.path.exists(self.logs_run_dir):
            os.makedirs(self.logs_run_dir)

    def beforeTest(self, test):
        log = logging.getLogger()

        # check or create the directory of the current test context exist
        dir_path = os.path.join(self.logs_run_dir, str(test.context))
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)

        # add a file handler to write to the the test log file
        test.log_handler = FileHandler(os.path.join(dir_path, str(test)))
        log.addHandler(test.log_handler)

    def afterTest(self, test):
        log = logging.getLogger()
        log.removeHandler(test.log_handler)

{'fraction_non_alphanumeric': 0.09814612868047982, 'fraction_numerical': 0.0, 'mean_word_length': 2.759562841530055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2987356', 'n_tokens_mistral': 869, 'n_tokens_neox': 842, 'n_words': 223}