File: behave_undefined_steps.py

package info (click to toggle)
behave 1.2.6-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,160 kB
  • sloc: python: 19,857; makefile: 137; sh: 18
file content (101 lines) | stat: -rw-r--r-- 3,446 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: UTF-8 -*-
"""
Provides step definitions for behave based on behave4cmd.

REQUIRES:
  * behave4cmd.steplib.output steps (command output from behave).
"""

from __future__ import absolute_import
from behave import then
from behave.runner_util import make_undefined_step_snippet


# -----------------------------------------------------------------------------
# UTILITY FUNCTIONS:
# -----------------------------------------------------------------------------
def text_indent(text, indent_size=0):
    prefix = " " * indent_size
    return prefix.join(text.splitlines(True))


# -----------------------------------------------------------------------------
# STEPS FOR: Undefined step definitions
# -----------------------------------------------------------------------------
@then(u'an undefined-step snippets section exists')
def step_undefined_step_snippets_section_exists(context):
    """
    Checks if an undefined-step snippet section is in behave command output.
    """
    context.execute_steps(u'''
        Then the command output should contain:
            """
            You can implement step definitions for undefined steps with these snippets:
            """
    ''')

@then(u'an undefined-step snippet should exist for "{step}"')
def step_undefined_step_snippet_should_exist_for(context, step):
    """
    Checks if an undefined-step snippet is provided for a step
    in behave command output (last command).

    EXAMPLE:
        Then an undefined-step snippet should exist for "Given an undefined step"
    """
    undefined_step_snippet  = make_undefined_step_snippet(step)
    context.execute_steps(u'''\
Then the command output should contain:
    """
    {undefined_step_snippet}
    """
    '''.format(undefined_step_snippet=text_indent(undefined_step_snippet, 4)))


@then(u'an undefined-step snippet should not exist for "{step}"')
def step_undefined_step_snippet_should_not_exist_for(context, step):
    """
    Checks if an undefined-step snippet is provided for a step
    in behave command output (last command).
    """
    undefined_step_snippet  = make_undefined_step_snippet(step)
    context.execute_steps(u'''\
Then the command output should not contain:
    """
    {undefined_step_snippet}
    """
    '''.format(undefined_step_snippet=text_indent(undefined_step_snippet, 4)))


@then(u'undefined-step snippets should exist for')
def step_undefined_step_snippets_should_exist_for_table(context):
    """
    Checks if undefined-step snippets are provided.

    EXAMPLE:
        Then undefined-step snippets should exist for:
            | Step |
            | When an undefined step is used |
            | Then another undefined step is used |
    """
    assert context.table, "REQUIRES: table"
    for row in context.table.rows:
        step = row["Step"]
        step_undefined_step_snippet_should_exist_for(context, step)


@then(u'undefined-step snippets should not exist for')
def step_undefined_step_snippets_should_not_exist_for_table(context):
    """
    Checks if undefined-step snippets are not provided.

    EXAMPLE:
        Then undefined-step snippets should not exist for:
            | Step |
            | When an known step is used |
            | Then another known step is used |
    """
    assert context.table, "REQUIRES: table"
    for row in context.table.rows:
        step = row["Step"]
        step_undefined_step_snippet_should_not_exist_for(context, step)