<commit_before># -*- coding: utf-8 -*-
"""Test bre lib."""
from __future__ import unicode_literals
import unittest
from backrefs import bre
import re
import sys
import pytest
import sre_constants

PY3 = (3, 0) <= sys.version_info < (4, 0)
PY36_PLUS = (3, 6) <= sys.version_info
PY37_PLUS = (3, 7) <= sys.version_info

if PY3:
    binary_type = bytes  # noqa
else:
    binary_type = str  # noqa


class TestSearchTemplate(unittest.TestCase):
    """Search template tests."""

    def test_infinite_loop_catch(self):
        """Test infinite loop catch."""

        with pytest.raises(bre.RecursionException):
            bre.compile_search(r'((?a)(?u))')

    def test_comments_with_scoped_verbose(self):
        """Test scoped verbose with comments (PY36+)."""

        if PY36_PLUS:
            pattern = bre.compile_search(
                r'''(?u)Test # \e(?#\e\)(?x:
                Test #\e(?#\e\)
                (Test # \e
                )Test #\e
                )Test # \e'''
            )

            self.assertEqual(
                pattern.pattern,
                r'''(?u)Test # \x1b(?#\e\)(?x:
                Test #\\e(?#\\e\)
                (Test # \\e
                )Test #\\e
                )Test # \x1b'''
            )

            self.assertTrue(pattern.match('Test # \x16TestTestTestTest # \x1b') is not None)

    def test_byte_string_named_chars(self):
        """Test byte string named char."""
<commit_msg>Add tests under appropriate version switch<commit_after># -*- coding: utf-8 -*-
"""Test bre lib."""
from __future__ import unicode_literals
import unittest
from backrefs import bre
import re
import sys
import pytest
import sre_constants

PY3 = (3, 0) <= sys.version_info < (4, 0)
PY36_PLUS = (3, 6) <= sys.version_info
PY37_PLUS = (3, 7) <= sys.version_info

if PY3:
    binary_type = bytes  # noqa
else:
    binary_type = str  # noqa


class TestSearchTemplate(unittest.TestCase):
    """Search template tests."""

    def test_infinite_loop_catch(self):
        """Test infinite loop catch."""

        if PY3:
            with pytest.raises(bre.RecursionException):
                bre.compile_search(r'((?a)(?u))')
        if PY36_PLUS:
            with pytest.raises(bre.RecursionException):
                bre.compile_search(r'(?-x:(?x))', re.VERBOSE)

    def test_comments_with_scoped_verbose(self):
        """Test scoped verbose with comments (PY36+)."""

        if PY36_PLUS:
            pattern = bre.compile_search(
                r'''(?u)Test # \e(?#\e\)(?x:
                Test #\e(?#\e\)
                (Test # \e
                )Test #\e
                )Test # \e'''
            )

            self.assertEqual(
                pattern.pattern,
                r'''(?u)Test # \x1b(?#\e\)(?x:
                Test #\\e(?#\\e\)
                (Test # \\e
                )Test #\\e
                )Test # \x1b'''
            )

            self.assertTrue(pattern.match('Test # \x16TestTestTestTest # \x1b') is not None)

    def test_byte_string_named_chars(self):
        """Test byte string named char."""

{'fraction_non_alphanumeric': 0.14513504718516107, 'fraction_numerical': 0.01659616010413277, 'mean_word_length': 1.8542246982358404, 'pattern_counts': {'":': 0, '<': 11, '<?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': '186028', 'n_tokens_mistral': 1057, 'n_tokens_neox': 985, 'n_words': 229}