<commit_before># -*- coding: utf-8 -*-
from lettuce import *

from armstrong.utils.backends.base import GenericBackend, MultipleBackendProxy
from armstrong.utils import backends
from armstrong.utils.backends import base
from django.conf import settings
import fudge
import random
import sys

@before.each_scenario
def setup_scenario(scenario):
    world.backend = None
    world.exception = None
    world.result = None
    world.attr = None
    world.proxy = None
    world.expected_return = None
    world.provided_args = None
    world.provided_kwargs = None
    world.backend_name = "%s.SimpleBackend" % SimpleBackend.__module__
    world.original_settings = settings
    world.backend_class = SimpleBackend


@after.each_scenario
def teardown_scenario(scenario):
    settings = world.original_settings


class NullBackend(object):
    def handle(self, *args, **kwargs):
        return backends.DID_NOT_HANDLE


class BaseBackend(object):
    message = "I'm a base backend"
    arguments = None
    kwarguments = None

    def __init__(self, *args, **kwargs):
        if len(args) > 0:
            self.arguments = args
        if len(kwargs) > 0:
            self.kwarguments = kwargs

    def handle(self, *args, **kwargs):
        return self.message    


class SimpleBackend(BaseBackend):
    message = "I'm a simple backend"


class SecondBackend(BaseBackend):
    message = "I am the second backend"


@step(u'I have a single backend configured')
def configure_single_backend(step):
    settings.testable_backends = world.backend_name


@step(u'I have a string configured for the backend')
def given_i_have_a_string_configured_for_the_backend(step):
    world.backend_name = "%s.SimpleBackend" % SimpleBackend.__module__
    world.expected_backend = SimpleBackend
    settings.testable_backends = world.backend_name


@step(u'I have a list configured for the backend')
def configure_list_of_backends(step):
    world.backend_name = ["%s.SimpleBackend" % SimpleBackend.__module__,
                          "%s.SecondBackend" % SecondBackend.__module__, ]
    settings.testable_backends = world.backend_name


@step(u'I create a new backend with the setting used')
def create_backend(step):
    world.backend = GenericBackend("testable_backends")


@step(u'I call "(.*)" on that backend')
def backend_call(step, method):
    assert hasattr(world.backend, method)
    try:
        world.result = getattr(world.backend, method)()
    except Exception, e:
        world.exception = e

@step(u'When I call "(.*)" with args on the backend')
def when_i_call_group1_with_args_on_the_backend(step, method):
    assert hasattr(world.backend, method)
    world.provided_args = ("Hello world", random.randint(100, 200))
    try:
        world.result = getattr(world.backend, method)(*world.provided_args)
    except Exception, e:
        world.exception = e
    
@step(u'When I call "(.*)" with kwargs on the backend')
def when_i_call_group1_with_kwargs_on_the_backend(step, method):
    assert hasattr(world.backend, method)
    world.provided_kwargs = {
            "msg": "Hello world",
            "random": random.randint(100, 200),
    }
    try:
        world.result = getattr(world.backend, method)(**world.provided_kwargs)
    except Exception, e:
        world.exception = e

@step(u'I should have a copy of the originally configured backend')
def expect_single_backend(step):
    assert world.result.__class__ == SimpleBackend


@step(u'I should have a copy of MultipleBackends')
def expect_multiple_backends(step):<commit_msg>loosen and restrict the step pattern<commit_after># -*- coding: utf-8 -*-
from lettuce import *

from armstrong.utils.backends.base import GenericBackend, MultipleBackendProxy
from armstrong.utils import backends
from armstrong.utils.backends import base
from django.conf import settings
import fudge
import random
import sys

@before.each_scenario
def setup_scenario(scenario):
    world.backend = None
    world.exception = None
    world.result = None
    world.attr = None
    world.proxy = None
    world.expected_return = None
    world.provided_args = None
    world.provided_kwargs = None
    world.backend_name = "%s.SimpleBackend" % SimpleBackend.__module__
    world.original_settings = settings
    world.backend_class = SimpleBackend


@after.each_scenario
def teardown_scenario(scenario):
    settings = world.original_settings


class NullBackend(object):
    def handle(self, *args, **kwargs):
        return backends.DID_NOT_HANDLE


class BaseBackend(object):
    message = "I'm a base backend"
    arguments = None
    kwarguments = None

    def __init__(self, *args, **kwargs):
        if len(args) > 0:
            self.arguments = args
        if len(kwargs) > 0:
            self.kwarguments = kwargs

    def handle(self, *args, **kwargs):
        return self.message    


class SimpleBackend(BaseBackend):
    message = "I'm a simple backend"


class SecondBackend(BaseBackend):
    message = "I am the second backend"


@step(u'I have a single backend configured')
def configure_single_backend(step):
    settings.testable_backends = world.backend_name


@step(u'I have a string configured for the backend')
def given_i_have_a_string_configured_for_the_backend(step):
    world.backend_name = "%s.SimpleBackend" % SimpleBackend.__module__
    world.expected_backend = SimpleBackend
    settings.testable_backends = world.backend_name


@step(u'I have a list configured for the backend')
def configure_list_of_backends(step):
    world.backend_name = ["%s.SimpleBackend" % SimpleBackend.__module__,
                          "%s.SecondBackend" % SecondBackend.__module__, ]
    settings.testable_backends = world.backend_name


@step(u'I create a new backend with the setting used')
def create_backend(step):
    world.backend = GenericBackend("testable_backends")


@step(u'I call "(.*)" on that backend')
def backend_call(step, method):
    assert hasattr(world.backend, method)
    try:
        world.result = getattr(world.backend, method)()
    except Exception, e:
        world.exception = e

@step(u'I call "(.*)" with args on the backend$')
def when_i_call_group1_with_args_on_the_backend(step, method):
    assert hasattr(world.backend, method)
    world.provided_args = ("Hello world", random.randint(100, 200))
    try:
        world.result = getattr(world.backend, method)(*world.provided_args)
    except Exception, e:
        world.exception = e
    
@step(u'I call "(.*)" with kwargs on the backend$')
def when_i_call_group1_with_kwargs_on_the_backend(step, method):
    assert hasattr(world.backend, method)
    world.provided_kwargs = {
            "msg": "Hello world",
            "random": random.randint(100, 200),
    }
    try:
        world.result = getattr(world.backend, method)(**world.provided_kwargs)
    except Exception, e:
        world.exception = e

@step(u'I should have a copy of the originally configured backend')
def expect_single_backend(step):
    assert world.result.__class__ == SimpleBackend


@step(u'I should have a copy of MultipleBackends')
def expect_multiple_backends(step):
{'fraction_non_alphanumeric': 0.09874453378473691, 'fraction_numerical': 0.004796163069544364, 'mean_word_length': 3.75201072386059, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 7, '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': '1203025', 'n_tokens_mistral': 2149, 'n_tokens_neox': 2122, 'n_words': 548}