Ejemplo n.º 1
0
def test_replacing_step():
    """
    Test registering a different step with the same sentence.
    """

    def func1():
        """First function to register as a step."""
        pass

    def func2():
        """Second function to register as a step."""
        pass

    steps = StepDict()

    # This has to be more than re._MAXCACHE; currently 100 on Python 2.7 and
    # 512 on Python 3.5
    step_count = 1024

    sentence = "sentence {0}".format

    # Register some steps
    for num in range(step_count):
        steps.load(sentence(num), func1)

    # Register the same steps again
    for num in range(step_count):
        steps.load(sentence(num), func2)

    # func2 should have replaced func1 everywhere
    for num in range(step_count):
        assert_matches(steps, sentence(num), (func2, (), {}))
Ejemplo n.º 2
0
def test_replacing_step():
    """
    Test registering a different step with the same sentence.
    """

    def func1():
        """First function to register as a step."""
        pass

    def func2():
        """Second function to register as a step."""
        pass

    steps = StepDict()

    # This has to be more than re._MAXCACHE; currently 100 on Python 2.7 and
    # 512 on Python 3.5
    step_count = 1024

    sentence = "sentence {0}".format

    # Register some steps
    for num in range(step_count):
        steps.load(sentence(num), func1)

    # Register the same steps again
    for num in range(step_count):
        steps.load(sentence(num), func2)

    # func2 should have replaced func1 everywhere
    for num in range(step_count):
        assert_matches(steps, sentence(num), (func2, (), {}))
Ejemplo n.º 3
0
def test_StepDict_raise_StepLoadingError_if_first_argument_is_not_a_regex():
    """
    aloe.STEP_REGISTRY.load(step, func) should raise an error if step is
    not a regex
    """
    steps = StepDict()
    with assert_raises(StepLoadingError):
        steps.load("an invalid regex;)", lambda: "")
Ejemplo n.º 4
0
def test_StepDict_raise_StepLoadingError_if_first_argument_is_not_a_regex():
    """
    aloe.STEP_REGISTRY.load(step, func) should raise an error if step is
    not a regex
    """
    steps = StepDict()
    with assert_raises(StepLoadingError):
        steps.load("an invalid regex;)", lambda: "")
Ejemplo n.º 5
0
def test_StepDict_can_load_a_step_composed_of_a_regex_and_a_function():
    """
    aloe.STEP_REGISTRY.load(step, func) append item(step, func) to
    STEP_REGISTRY
    """
    steps = StepDict()

    def func():  # pylint:disable=missing-docstring
        return ""

    step = "a step to test"
    steps.load(step, func)

    assert_matches(steps, step, (func, (), {}))
Ejemplo n.º 6
0
def test_StepDict_can_load_a_step_composed_of_a_regex_and_a_function():
    """
    aloe.STEP_REGISTRY.load(step, func) append item(step, func) to
    STEP_REGISTRY
    """
    steps = StepDict()

    def func():  # pylint:disable=missing-docstring
        return ""

    step = "a step to test"
    steps.load(step, func)

    assert_matches(steps, step, (func, (), {}))
Ejemplo n.º 7
0
def test_StepDict_can_load_a_step_composed_of_a_regex_and_a_function():
    """
    aloe.STEP_REGISTRY.load(step, func) append item(step, func) to
    STEP_REGISTRY
    """
    steps = StepDict()

    def func():  # pylint:disable=missing-docstring
        return ""

    step = "a step to test"
    steps.load(step, func)

    step = re.compile(step, re.I | re.U)
    assert_in(step, steps)
    assert_equal(steps[step], func)
Ejemplo n.º 8
0
def test_StepDict_can_load_a_step_composed_of_a_regex_and_a_function():
    """
    aloe.STEP_REGISTRY.load(step, func) append item(step, func) to
    STEP_REGISTRY
    """
    steps = StepDict()

    def func():  # pylint:disable=missing-docstring
        return ""

    step = "a step to test"
    steps.load(step, func)

    step = re.compile(step, re.I | re.U)
    assert_in(step, steps)
    assert_equal(steps[step], func)
Ejemplo n.º 9
0
def test_StepDict_load_a_step_return_the_given_function():
    """
    aloe.STEP_REGISTRY.load(step, func) returns func
    """
    steps = StepDict()

    def func():  # pylint:disable=missing-docstring
        return ""

    assert_equal(steps.load("another step", func), func)
Ejemplo n.º 10
0
def test_StepDict_load_a_step_return_the_given_function():
    """
    aloe.STEP_REGISTRY.load(step, func) returns func
    """
    steps = StepDict()

    def func():  # pylint:disable=missing-docstring
        return ""

    assert_equal(steps.load("another step", func), func)