<commit_before>"""Tests for the utils functions and classes."""

import axelrod
import unittest

from hypothesis import given
from hypothesis.strategies import floats, text

import logging
from testfixtures import Comparison as C, compare
import sys

class TestTimedMessage(unittest.TestCase):

    @given(start_time=floats(min_value=0, allow_nan=False,
                             allow_infinity=False),
           message=text())
    def test_time_message(self, start_time, message):
        timed_message = axelrod.utils.timed_message(message, start_time)
        self.assertEqual(timed_message[:len(message)], message)

    def test_time_message_example(self):
        message = "Full tournament"
        start_time = 0
        timed_message = axelrod.utils.timed_message(message, start_time)
        self.assertEqual(timed_message[:len(message)], message)
        self.assertGreaterEqual(float(timed_message[len(message)+4:-1]), 0)



class TestSetupLogging(unittest.TestCase):

    def test_basic_configuration_console(self):
        logger = logging.getLogger("axelrod")
        levels = {"CRITICAL": 50,
                  "ERROR": 40,
                  "WARNING": 30,
                  "INFO": 20,
                  "DEBUG": 10,
                  "NOTSET": 0}
        for level in levels:
            axelrod.utils.setup_logging(logging_destination='console',
                                        verbosity=level)
            compare(logger.level, levels[level])

        # Removing this as it doesn't seem to work on travis.
        #compare([
            #C('logging.StreamHandler',
              #stream=sys.stderr,
              #formatter=C('logging.Formatter',
                          #_fmt='%(message)s',
                          #strict=False),
              #level=logging.NOTSET,
              #strict=False)
            #], logger.handlers)<commit_msg>Removing code that does not work on travis.<commit_after>"""Tests for the utils functions and classes."""

import axelrod
import unittest

from hypothesis import given
from hypothesis.strategies import floats, text

import logging
from testfixtures import Comparison as C, compare
import sys

class TestTimedMessage(unittest.TestCase):

    @given(start_time=floats(min_value=0, allow_nan=False,
                             allow_infinity=False),
           message=text())
    def test_time_message(self, start_time, message):
        timed_message = axelrod.utils.timed_message(message, start_time)
        self.assertEqual(timed_message[:len(message)], message)

    def test_time_message_example(self):
        message = "Full tournament"
        start_time = 0
        timed_message = axelrod.utils.timed_message(message, start_time)
        self.assertEqual(timed_message[:len(message)], message)
        self.assertGreaterEqual(float(timed_message[len(message)+4:-1]), 0)



class TestSetupLogging(unittest.TestCase):

    def test_basic_configuration_console(self):
        logger = logging.getLogger("axelrod")
        levels = {"CRITICAL": 50,
                  "ERROR": 40,
                  "WARNING": 30,
                  "INFO": 20,
                  "DEBUG": 10,
                  "NOTSET": 0}
        for level in levels:
            axelrod.utils.setup_logging(logging_destination='console',
                                        verbosity=level)
            compare(logger.level, levels[level])
{'fraction_non_alphanumeric': 0.09781968179139658, 'fraction_numerical': 0.009428403064230996, 'mean_word_length': 2.3916083916083917, 'pattern_counts': {'":': 12, '<': 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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3495444', 'n_tokens_mistral': 964, 'n_tokens_neox': 896, 'n_words': 199}