<commit_before>
from unittest import expectedFailure

from .. utils import TranspileTestCase, UnaryOperationTestCase, BinaryOperationTestCase, InplaceOperationTestCase


class StrTests(TranspileTestCase):
    def test_setattr(self):
        self.assertCodeExecution("""
            x = "Hello, world"
            try:
                x.attr = 42
            except AttributeError as err:
                print(err)
            """)

    def test_iscase(self):
        self.assertCodeExecution("""
            for s in ['hello, World!', 'HELLO, WORLD.', 'ello? world', '']:<commit_msg>Added extended test cases for Str.subscr_slice<commit_after>
from unittest import expectedFailure

from .. utils import TranspileTestCase, UnaryOperationTestCase, BinaryOperationTestCase, InplaceOperationTestCase
from .. utils import adjust


class SubscrSliceTest(TranspileTestCase):
    def test_subscr_str_extended(self):
        str_samples = [
                        '""',
                        '"3"',
                        '"This is another string"',
                        '"Mÿ hôvèrçràft îß fûłl öf éêlś"',
                        '"One arg: %s"',
                        '"Three args: %s | %s | %s"',
                    ]
        slice_samples = [
                        'slice(0)',
                        'slice(5)',
                        'slice(-1)',
                        'slice(-7)',
                        'slice(2, 7)',
                        'slice(-1, 2)',
                        'slice(2, -7)',
                        'slice(-2, -7)',
                        'slice(0, 0)',
                        'slice(-10, 0)',
                        'slice(0, -10)',
                        'slice(2, 7, 2)',
                        'slice(7, 2, -1)',
                        'slice(7, 2, 10)',
                        'slice(2, 7, 0)'
                    ]

        data = []
        for x in str_samples:
            for y in slice_samples:
                data.append((x, y))

        self.assertCodeExecution(
            '##################################################\n'.join(
                adjust("""
                    try:
                        print('>>> x = %(x)s')
                        print('>>> y = %(y)s')
                        print('>>> x[y]')
                        x = %(x)s
                        y = %(y)s
                        print(x[y])
                    except Exception as e:
                        print(type(e), ':', e)
                    print()
                    """ % {
                        'x': x,
                        'y': y
                    }
                )
                for x, y in data
            ),
            "Error running test_subscr_str_extended",
            run_in_function=False,
        )


class StrTests(TranspileTestCase):
    def test_setattr(self):
        self.assertCodeExecution("""
            x = "Hello, world"
            try:
                x.attr = 42
            except AttributeError as err:
                print(err)
            """)

    def test_iscase(self):
        self.assertCodeExecution("""
            for s in ['hello, World!', 'HELLO, WORLD.', 'ello? world', '']:
{'fraction_non_alphanumeric': 0.13241292751804204, 'fraction_numerical': 0.011923438970818953, 'mean_word_length': 1.0795825179386824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '4525225', 'n_tokens_mistral': 869, 'n_tokens_neox': 803, 'n_words': 192}