File: issue0085.feature

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 (119 lines) | stat: -rw-r--r-- 4,906 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
@issue
Feature: Issue #85: AssertionError with nested regex and pretty formatter

    | When --format=pretty is used
    | an AssertationError occurs for missing optional/nested-groups.
    | When --format=plain is used, everything is fine

  Scenario: Test Setup
    Given a new working directory
    And   a file named "features/steps/regexp_steps.py" with:
        """
        from __future__ import print_function
        from behave import given, when, then, use_step_matcher
        @given(u'a {re_category} regular expression "{pattern}"')
        def impl(context, re_category, pattern):
            pass

        @then(u'the parameter "{name}" is "{expected_value}"')
        def impl(context, name, expected_value):
            actual_value = getattr(context, name, None)
            if actual_value is None:
                actual_value = ""
            assert hasattr(context, name)
            assert actual_value == expected_value, "MISMATCH: actual({0}) == expected({1})".format(actual_value, expected_value)

        @then(u'the parameter "{name}" is none')
        def impl(context, name):
            actual_value = getattr(context, name, None)
            assert hasattr(context, name)
            assert actual_value is None, "MISMATCH: actual({0}) == None)".format(actual_value)

        def store_in_context(context, data):
            for name, value in data.items():
                setattr(context, name, value)

        use_step_matcher('re')

        @when(u'I try to match "(?P<foo>foo and more)"')
        def impl(context, **kwargs):
            kwargs["regexp_case"] = "simple"
            print("CASE UNNESTED: {0}".format(kwargs))
            store_in_context(context, kwargs)

        @when(u'I try to match "(?P<foo>foo(?P<bar>bar)?)"')
        def impl(context, **kwargs):
            kwargs["regexp_case"] = "nested"
            print("CASE NESTED: {0}".format(kwargs))
            store_in_context(context, kwargs)

        @when(u'I try to match "(?P<foo>foo) (?P<bar>bar)?"')
        def impl(context, **kwargs):
            kwargs["regexp_case"] = "optional"
            print("CASE OPTIONAL: {0}".format(kwargs))
            store_in_context(context, kwargs)
        """
    And   a file named "features/matching.feature" with:
        """
        Feature: Using regexp matcher with nested and optional parameters

            Scenario: regex, no nested groups, matching
                Given a simple regular expression "(?P<foo>foo and more)"
                When I try to match "foo and more"
                Then the parameter "regexp_case" is "simple"
                And  the parameter "foo" is "foo and more"

            Scenario: Nested groups without nested match
                Given a nested-group regular expression "(?P<foo>foo(?P<bar>bar)?)"
                When I try to match "foo"
                Then the parameter "regexp_case" is "nested"
                And  the parameter "foo" is "foo"
                And  the parameter "bar" is none

            Scenario: Nested groups with nested match
                Given a nested-group regular expression "(?P<foo>foo(?P<bar>bar)?)"
                When I try to match "foobar"
                Then the parameter "regexp_case" is "nested"
                And  the parameter "foo" is "foobar"
                And  the parameter "bar" is "bar"

            Scenario: Optional group without match
                Given a optional-group regular expression "(?P<foo>foo) (?P<bar>bar)?"
                When I try to match "foo "
                Then the parameter "regexp_case" is "optional"
                And  the parameter "foo" is "foo"
                And  the parameter "bar" is none

            Scenario: Optional group with match
                Given a optional-group regular expression "(?P<foo>foo) (?P<bar>bar)?"
                When I try to match "foo bar"
                Then the parameter "regexp_case" is "optional"
                And  the parameter "foo" is "foo"
                And  the parameter "bar" is "bar"
        """

  Scenario: Run regexp steps with --format=plain
    When I run "behave --format=plain features/matching.feature"
    Then it should pass with:
        """
        1 feature passed, 0 failed, 0 skipped
        5 scenarios passed, 0 failed, 0 skipped
        24 steps passed, 0 failed, 0 skipped, 0 undefined
        """

  Scenario: Run regexp steps with --format=pretty
    When I run "behave -c --format=pretty features/matching.feature"
    Then it should pass with:
        """
        1 feature passed, 0 failed, 0 skipped
        5 scenarios passed, 0 failed, 0 skipped
        24 steps passed, 0 failed, 0 skipped, 0 undefined
        """
    And  the command output should not contain
        """
        assert isinstance(text, unicode)
        """
    And  the command output should not contain
        """
        AssertationError
        """