コード例 #1
0
ファイル: test_registry.py プロジェクト: electroniceagle/aloe
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, (), {}))
コード例 #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, (), {}))
コード例 #3
0
ファイル: test_registry.py プロジェクト: electroniceagle/aloe
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: "")
コード例 #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: "")
コード例 #5
0
ファイル: test_registry.py プロジェクト: electroniceagle/aloe
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, (), {}))
コード例 #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, (), {}))
コード例 #7
0
ファイル: test_registry.py プロジェクト: kiawin/aloe
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)
コード例 #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)
コード例 #9
0
ファイル: test_registry.py プロジェクト: electroniceagle/aloe
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)
コード例 #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)