当前位置: 首页>>代码示例>>Python>>正文


Python registry.StepDict类代码示例

本文整理汇总了Python中aloe.registry.StepDict的典型用法代码示例。如果您正苦于以下问题:Python StepDict类的具体用法?Python StepDict怎么用?Python StepDict使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了StepDict类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_replacing_step

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, (), {}))
开发者ID:electroniceagle,项目名称:aloe,代码行数:32,代码来源:test_registry.py

示例2: test_StepDict_can_exclude_methods_when_load_steps

def test_StepDict_can_exclude_methods_when_load_steps():
    """
    aloe.STEP_REGISTRY.load_steps(obj) don't load exluded attr in
    STEP_REGISTRY
    """
    steps = StepDict()

    class LotsOfSteps(object):
        """A class defining some steps."""
        exclude = ["step_1"]

        def step_1(self):  # pylint:disable=missing-docstring
            pass

        def step_2(self):
            """Doing something"""
            pass

    step_list = LotsOfSteps()
    steps.load_steps(step_list)

    expected_sentence1 = re.compile("Step 1", re.I | re.U)
    expected_sentence2 = re.compile("Doing something", re.I | re.U)
    assert_not_in(expected_sentence1, steps)
    assert_in(expected_sentence2, steps)
开发者ID:kiawin,项目名称:aloe,代码行数:25,代码来源:test_registry.py

示例3: test_unload_reload

def test_unload_reload():
    """
    Test unloading and then reloading the step.
    """

    def step():  # pylint:disable=missing-docstring
        pass

    steps = StepDict()

    # Load
    steps.step(r'My step (\d)')(step)

    assert_matches(steps, "My step 1", (step, ('1',), {}))

    # Members added to step by registering it
    # pylint:disable=no-member

    # Unload
    step.unregister()

    assert_no_match(steps, "My step 1")

    # Should be a no-op
    step.unregister()

    assert_no_match(steps, "My step 1")

    # Reload
    steps.step(step.sentence)(step)

    assert_matches(steps, "My step 1", (step, ('1',), {}))
开发者ID:electroniceagle,项目名称:aloe,代码行数:32,代码来源:test_registry.py

示例4: test_StepDict_can_load_steps_from_an_object

def test_StepDict_can_load_steps_from_an_object():
    """
    aloe.STEP_REGISTRY.load_steps(obj) append all obj methods to
    STEP_REGISTRY
    """
    steps = StepDict()

    class LotsOfSteps(object):
        """A class defining some steps."""

        def step_1(self):  # pylint:disable=missing-docstring
            pass

        def step_2(self):
            """Doing something"""
            pass

    step_list = LotsOfSteps()
    steps.load_steps(step_list)

    expected_sentence1 = re.compile("Step 1", re.I | re.U)
    expected_sentence2 = re.compile("Doing something", re.I | re.U)
    assert_in(expected_sentence1, steps)
    assert_in(expected_sentence2, steps)
    assert_equal(steps[expected_sentence1], step_list.step_1)
    assert_equal(steps[expected_sentence2], step_list.step_2)
开发者ID:kiawin,项目名称:aloe,代码行数:26,代码来源:test_registry.py

示例5: test_StepDict_raise_StepLoadingError_if_first_argument_is_not_a_regex

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: "")
开发者ID:electroniceagle,项目名称:aloe,代码行数:8,代码来源:test_registry.py

示例6: test_StepDict_can_extract_a_step_sentence_from_function_name

def test_StepDict_can_extract_a_step_sentence_from_function_name():
    """
    aloe.STEP_REGISTRY.extract_sentence(func) parse func name and return
    a sentence
    """
    steps = StepDict()

    def a_step_sentence():  # pylint:disable=missing-docstring
        pass
    assert_equal("A step sentence", steps.extract_sentence(a_step_sentence))
开发者ID:electroniceagle,项目名称:aloe,代码行数:10,代码来源:test_registry.py

示例7: test_StepDict_load_a_step_return_the_given_function

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)
开发者ID:electroniceagle,项目名称:aloe,代码行数:10,代码来源:test_registry.py

示例8: test_StepDict_can_extract_a_step_sentence_from_function_doc

def test_StepDict_can_extract_a_step_sentence_from_function_doc():
    """
    aloe.STEP_REGISTRY.extract_sentence(func) parse func doc and return
    a sentence
    """
    steps = StepDict()

    def a_step_func():
        """A step sentence"""
        pass
    assert_equal("A step sentence", steps.extract_sentence(a_step_func))
开发者ID:electroniceagle,项目名称:aloe,代码行数:11,代码来源:test_registry.py

示例9: test_StepDict_can_load_a_step_from_a_function

def test_StepDict_can_load_a_step_from_a_function():
    """
    aloe.STEP_REGISTRY.load_func(func) append item(step, func) to
    STEP_REGISTRY
    """
    steps = StepDict()

    def a_step_to_test():  # pylint:disable=missing-docstring
        pass

    steps.load_func(a_step_to_test)

    assert_matches(steps, "A step to test", (a_step_to_test, (), {}))
开发者ID:electroniceagle,项目名称:aloe,代码行数:13,代码来源:test_registry.py

示例10: test_StepDict_can_load_a_step_composed_of_a_regex_and_a_function

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, (), {}))
开发者ID:electroniceagle,项目名称:aloe,代码行数:14,代码来源:test_registry.py

示例11: test_StepDict_can_load_a_step_from_a_function

def test_StepDict_can_load_a_step_from_a_function():
    """
    aloe.STEP_REGISTRY.load_func(func) append item(step, func) to
    STEP_REGISTRY
    """
    steps = StepDict()

    def a_step_to_test():  # pylint:disable=missing-docstring
        pass

    steps.load_func(a_step_to_test)

    expected_sentence = re.compile("A step to test", re.I | re.U)
    assert_in(expected_sentence, steps)
    assert_equal(steps[expected_sentence], a_step_to_test)
开发者ID:kiawin,项目名称:aloe,代码行数:15,代码来源:test_registry.py

示例12: test_StepDict_can_load_a_step_composed_of_a_regex_and_a_function

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)
开发者ID:kiawin,项目名称:aloe,代码行数:16,代码来源:test_registry.py

示例13: test_StepDict_can_exclude_callable_object_when_load_steps

def test_StepDict_can_exclude_callable_object_when_load_steps():
    """
    aloe.STEP_REGISTRY.load_steps(obj) don't load callable objets in
    STEP_REGISTRY
    """
    steps = StepDict()

    class NoStep(object):
        """A class defining something that's not a step."""
        class NotAStep(object):
            """A callable which isn't a step."""
            def __call__(self):
                pass

    no_step = NoStep()
    steps.load_steps(no_step)

    assert len(steps) == 0
开发者ID:electroniceagle,项目名称:aloe,代码行数:18,代码来源:test_registry.py

示例14: test_StepDict_can_load_steps_from_an_object

def test_StepDict_can_load_steps_from_an_object():
    """
    aloe.STEP_REGISTRY.load_steps(obj) append all obj methods to
    STEP_REGISTRY
    """
    steps = StepDict()

    class LotsOfSteps(object):
        """A class defining some steps."""

        def step_1(self):  # pylint:disable=missing-docstring
            pass

        def step_2(self):
            """Doing something"""
            pass

    step_list = LotsOfSteps()
    steps.load_steps(step_list)

    assert_matches(steps, "Step 1", (step_list.step_1, (), {}))
    assert_matches(steps, "Doing something", (step_list.step_2, (), {}))
开发者ID:electroniceagle,项目名称:aloe,代码行数:22,代码来源:test_registry.py

示例15: test_StepDict_can_exclude_methods_when_load_steps

def test_StepDict_can_exclude_methods_when_load_steps():
    """
    aloe.STEP_REGISTRY.load_steps(obj) don't load exluded attr in
    STEP_REGISTRY
    """
    steps = StepDict()

    class LotsOfSteps(object):
        """A class defining some steps."""
        exclude = ["step_1"]

        def step_1(self):  # pylint:disable=missing-docstring
            pass

        def step_2(self):
            """Doing something"""
            pass

    step_list = LotsOfSteps()
    steps.load_steps(step_list)

    assert_no_match(steps, "Step 1")
    assert_matches(steps, "Doing something", (step_list.step_2, (), {}))
开发者ID:electroniceagle,项目名称:aloe,代码行数:23,代码来源:test_registry.py


注:本文中的aloe.registry.StepDict类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。