<commit_before># -*- coding: utf-8 -*-
# Copyright 2017 - 2021 <NAME>, All Rights Reserved

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

"""
Test module for enlighten._util
"""

from textwrap import dedent

import blessed

from enlighten._util import format_time, Lookahead, HTMLConverter

from tests import TestCase, MockTTY


class TestFormatTime(TestCase):
    """
    Test cases for :py:func:`_format_time`
    """

    def test_seconds(self):
        """Verify seconds formatting"""

        self.assertEqual(format_time(0), '00:00')
        self.assertEqual(format_time(6), '00:06')
        self.assertEqual(format_time(42), '00:42')

    def test_minutes(self):
        """Verify minutes formatting"""

        self.assertEqual(format_time(60), '01:00')
        self.assertEqual(format_time(128), '02:08')
        self.assertEqual(format_time(1684), '28:04')

    def test_hours(self):
        """Verify hours formatting"""

        self.assertEqual(format_time(3600), '1h 00:00')
        self.assertEqual(format_time(43980), '12h 13:00')
        self.assertEqual(format_time(43998), '12h 13:18')

    def test_days(self):
        """Verify days formatting"""

        self.assertEqual(format_time(86400), '1d 0h 00:00')
        self.assertEqual(format_time(1447597), '16d 18h 06:37')


class TestLookahead(TestCase):
    """
    Test cases for Lookahead
    """

    def test_iteration(self):
        """Verify normal iteration"""

        wrapped = Lookahead(iter(range(10)))

        self.assertEqual([next(wrapped) for _ in range(10)], list(range(10)))

    def test_lookahead(self):
        """Verify lookahead() behavior"""

        wrapped = Lookahead(iter(range(10)))

        self.assertEqual(wrapped.lookahead(0), 0)
        self.assertEqual(wrapped.lookahead(4), 4)
        self.assertEqual(wrapped.lookahead(2, 4), [2, 3])
        self.assertEqual(wrapped.lookahead(8, 12), [8, 9])

    def test_lookahead_iteration(self):
        """lookahead() output changes as iteration proceeds"""

        wrapped = Lookahead(iter(range(10)))

        self.assertEqual(next(wrapped), 0)
        self.assertEqual(wrapped.lookahead(0), 1)
        self.assertEqual(next(wrapped), 1)
        self.assertEqual(wrapped.lookahead(4), 6)
        self.assertEqual(next(wrapped), 2)
        self.assertEqual(wrapped.lookahead(2, 4), [5, 6])
        self.assertEqual(next(wrapped), 3)
        self.assertEqual(wrapped.lookahead(8, 12), [])


class TestHTMLConverter(TestCase):
    """
    Test cases for HTMLConverter
    """

    # pylint: disable=protected-access

    @classmethod
    def setUpClass(cls):
        cls.tty = MockTTY()
        cls.term = blessed.Terminal(
            stream=cls.tty.stdout, kind='xterm-256color', force_styling=True
        )
        cls.term.number_of_colors = 1 << 24

    @classmethod
    def tearDownClass(cls):
        cls.tty.close()<commit_msg>Remove terminal kind in tests<commit_after># -*- coding: utf-8 -*-
# Copyright 2017 - 2022 <NAME>, All Rights Reserved

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

"""
Test module for enlighten._util
"""

from textwrap import dedent

import blessed

from enlighten._util import format_time, Lookahead, HTMLConverter

from tests import TestCase, MockTTY


class TestFormatTime(TestCase):
    """
    Test cases for :py:func:`_format_time`
    """

    def test_seconds(self):
        """Verify seconds formatting"""

        self.assertEqual(format_time(0), '00:00')
        self.assertEqual(format_time(6), '00:06')
        self.assertEqual(format_time(42), '00:42')

    def test_minutes(self):
        """Verify minutes formatting"""

        self.assertEqual(format_time(60), '01:00')
        self.assertEqual(format_time(128), '02:08')
        self.assertEqual(format_time(1684), '28:04')

    def test_hours(self):
        """Verify hours formatting"""

        self.assertEqual(format_time(3600), '1h 00:00')
        self.assertEqual(format_time(43980), '12h 13:00')
        self.assertEqual(format_time(43998), '12h 13:18')

    def test_days(self):
        """Verify days formatting"""

        self.assertEqual(format_time(86400), '1d 0h 00:00')
        self.assertEqual(format_time(1447597), '16d 18h 06:37')


class TestLookahead(TestCase):
    """
    Test cases for Lookahead
    """

    def test_iteration(self):
        """Verify normal iteration"""

        wrapped = Lookahead(iter(range(10)))

        self.assertEqual([next(wrapped) for _ in range(10)], list(range(10)))

    def test_lookahead(self):
        """Verify lookahead() behavior"""

        wrapped = Lookahead(iter(range(10)))

        self.assertEqual(wrapped.lookahead(0), 0)
        self.assertEqual(wrapped.lookahead(4), 4)
        self.assertEqual(wrapped.lookahead(2, 4), [2, 3])
        self.assertEqual(wrapped.lookahead(8, 12), [8, 9])

    def test_lookahead_iteration(self):
        """lookahead() output changes as iteration proceeds"""

        wrapped = Lookahead(iter(range(10)))

        self.assertEqual(next(wrapped), 0)
        self.assertEqual(wrapped.lookahead(0), 1)
        self.assertEqual(next(wrapped), 1)
        self.assertEqual(wrapped.lookahead(4), 6)
        self.assertEqual(next(wrapped), 2)
        self.assertEqual(wrapped.lookahead(2, 4), [5, 6])
        self.assertEqual(next(wrapped), 3)
        self.assertEqual(wrapped.lookahead(8, 12), [])


class TestHTMLConverter(TestCase):
    """
    Test cases for HTMLConverter
    """

    # pylint: disable=protected-access

    @classmethod
    def setUpClass(cls):
        cls.tty = MockTTY()
        cls.term = blessed.Terminal(
            stream=cls.tty.stdout, force_styling=True
        )
        cls.term.number_of_colors = 1 << 24

    @classmethod
    def tearDownClass(cls):
        cls.tty.close()
{'fraction_non_alphanumeric': 0.13527764046795188, 'fraction_numerical': 0.04926676552974131, 'mean_word_length': 3.109681787406906, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5857267', 'n_tokens_mistral': 2119, 'n_tokens_neox': 1851, 'n_words': 422}