コード例 #1
0
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)
コード例 #2
0
ファイル: test_registry.py プロジェクト: kiawin/aloe
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)
コード例 #3
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, (), {}))
コード例 #4
0
ファイル: test_registry.py プロジェクト: electroniceagle/aloe
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',), {}))
コード例 #5
0
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)
コード例 #6
0
ファイル: test_registry.py プロジェクト: kiawin/aloe
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)
コード例 #7
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: "")
コード例 #8
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: "")
コード例 #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
ファイル: test_registry.py プロジェクト: electroniceagle/aloe
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))
コード例 #11
0
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))
コード例 #12
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)
コード例 #13
0
ファイル: test_registry.py プロジェクト: electroniceagle/aloe
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))
コード例 #14
0
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))
コード例 #15
0
ファイル: test_registry.py プロジェクト: electroniceagle/aloe
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, (), {}))
コード例 #16
0
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, (), {}))
コード例 #17
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, (), {}))
コード例 #18
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, (), {}))
コード例 #19
0
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)
    steps.step(r"Another step (\d)")(step)

    assert_matches(steps, "My step 1", (step, ("1", ), {}))
    assert_matches(steps, "Another 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")
    assert_no_match(steps, "Another step 1")

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

    assert_no_match(steps, "My step 1")
    assert_no_match(steps, "Another step 1")

    # Reload
    steps.step(r"My step (\d)")(step)

    assert_matches(steps, "My step 1", (step, ("1", ), {}))
コード例 #20
0
ファイル: test_registry.py プロジェクト: kiawin/aloe
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)
コード例 #21
0
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)
コード例 #22
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)
コード例 #23
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)
コード例 #24
0
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 not steps
コード例 #25
0
ファイル: test_registry.py プロジェクト: electroniceagle/aloe
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
コード例 #26
0
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, (), {}))
コード例 #27
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, (), {}))
コード例 #28
0
ファイル: test_registry.py プロジェクト: electroniceagle/aloe
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, (), {}))
コード例 #29
0
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, (), {}))
コード例 #30
0
ファイル: test_registry.py プロジェクト: electroniceagle/aloe
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, (), {}))
コード例 #31
0
def test_unload_reload():
    """
    Test unloading and then reloading the step.
    """
    def step():  # pylint:disable=missing-docstring
        pass

    class StepDefinition(object):
        """A step definition object to match."""
        sentence = 'My step 1'

    steps = StepDict()

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

    assert len(steps) == 1
    assert steps.match_step(StepDefinition) == (step, ('1', ), {})

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

    # Unload
    step.unregister()

    assert len(steps) == 0

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

    assert len(steps) == 0

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

    assert len(steps) == 1
    assert steps.match_step(StepDefinition) == (step, ('1', ), {})
コード例 #32
0
ファイル: test_registry.py プロジェクト: kiawin/aloe
def test_unload_reload():
    """
    Test unloading and then reloading the step.
    """

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

    class StepDefinition(object):
        """A step definition object to match."""
        sentence = 'My step 1'

    steps = StepDict()

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

    assert len(steps) == 1
    assert steps.match_step(StepDefinition) == (step, ('1',), {})

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

    # Unload
    step.unregister()

    assert len(steps) == 0

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

    assert len(steps) == 0

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

    assert len(steps) == 1
    assert steps.match_step(StepDefinition) == (step, ('1',), {})