コード例 #1
0
ファイル: test_parser.py プロジェクト: butchland/gherkin
def test_parse_tags_on_scenario_outline_examples():
    "Parser should allow tags to be defined in examples"

    # Given a parser loaded with a document that contains tags on
    # scenario outline examples
    #   @tagged-feature
    #   Feature: Parse tags
    #   @tag1 @tag2
    #   Scenario Outline: Test
    #   @example-tag1
    #   @example-tag2
    #   Examples:
    #     | Header |

    parser = Parser(
        [
            (1, gherkin.TOKEN_TAG, "tagged-feature"),
            (1, gherkin.TOKEN_NEWLINE, "\n"),
            (2, gherkin.TOKEN_LABEL, "Feature"),
            (2, gherkin.TOKEN_TEXT, "Parse tags"),
            (2, gherkin.TOKEN_NEWLINE, "\n"),
            (3, gherkin.TOKEN_TAG, "tag1"),
            (3, gherkin.TOKEN_TAG, "tag2"),
            (3, gherkin.TOKEN_NEWLINE, "\n"),
            (4, gherkin.TOKEN_LABEL, "Scenario Outline"),
            (4, gherkin.TOKEN_TEXT, "Test"),
            (4, gherkin.TOKEN_NEWLINE, "\n"),
            (5, gherkin.TOKEN_TAG, "example-tag1"),
            (5, gherkin.TOKEN_NEWLINE, "\n"),
            (6, gherkin.TOKEN_TAG, "example-tag2"),
            (6, gherkin.TOKEN_NEWLINE, "\n"),
            (7, gherkin.TOKEN_LABEL, "Examples"),
            (7, gherkin.TOKEN_NEWLINE, "\n"),
            (8, gherkin.TOKEN_TABLE_COLUMN, "Header"),
            (8, gherkin.TOKEN_NEWLINE, "\n"),
            (9, gherkin.TOKEN_EOF, ""),
        ]
    )

    # When I parse the document
    feature = parser.parse_feature()

    # Then I see all the tags were found
    feature.should.equal(
        Ast.Feature(
            line=2,
            title=Ast.Text(line=2, text="Parse tags"),
            tags=["tagged-feature"],
            scenarios=[
                Ast.ScenarioOutline(
                    line=4,
                    title=Ast.Text(line=4, text="Test"),
                    tags=["tag1", "tag2"],
                    examples=Ast.Examples(
                        line=7, tags=["example-tag1", "example-tag2"], table=Ast.Table(line=8, fields=[["Header"]])
                    ),
                )
            ],
        )
    )
コード例 #2
0
ファイル: test_parser.py プロジェクト: butchland/gherkin
def test_parse_feature():

    parser = Parser(
        [
            (1, gherkin.TOKEN_LABEL, "Feature"),
            (1, gherkin.TOKEN_TEXT, "Feature title"),
            (1, gherkin.TOKEN_NEWLINE, "\n"),
            (2, gherkin.TOKEN_TEXT, "feature description"),
            (2, gherkin.TOKEN_NEWLINE, "\n"),
            (3, gherkin.TOKEN_LABEL, "Background"),
            (3, gherkin.TOKEN_TEXT, "Some background"),
            (3, gherkin.TOKEN_NEWLINE, "\n"),
            (4, gherkin.TOKEN_TEXT, "Given the problem"),
            (4, gherkin.TOKEN_NEWLINE, "\n"),
            (5, gherkin.TOKEN_LABEL, "Scenario"),
            (5, gherkin.TOKEN_TEXT, "Scenario title"),
            (5, gherkin.TOKEN_NEWLINE, "\n"),
            (6, gherkin.TOKEN_TEXT, "Given first step"),
            (6, gherkin.TOKEN_NEWLINE, "\n"),
            (7, gherkin.TOKEN_LABEL, "Scenario"),
            (7, gherkin.TOKEN_TEXT, "Another scenario"),
            (7, gherkin.TOKEN_NEWLINE, "\n"),
            (8, gherkin.TOKEN_TEXT, "Given this step"),
            (8, gherkin.TOKEN_NEWLINE, "\n"),
            (9, gherkin.TOKEN_TEXT, "When we take another step"),
            (9, gherkin.TOKEN_NEWLINE, "\n"),
            (10, gherkin.TOKEN_EOF, ""),
        ]
    )

    feature = parser.parse_feature()

    feature.should.equal(
        Ast.Feature(
            line=1,
            title=Ast.Text(line=1, text="Feature title"),
            description=Ast.Text(line=2, text="feature description"),
            background=Ast.Background(
                line=3,
                title=Ast.Text(line=3, text="Some background"),
                steps=[Ast.Step(line=4, title=Ast.Text(line=4, text="Given the problem"))],
            ),
            scenarios=[
                Ast.Scenario(
                    line=5,
                    title=Ast.Text(line=5, text="Scenario title"),
                    steps=[Ast.Step(line=6, title=Ast.Text(line=6, text="Given first step"))],
                ),
                Ast.Scenario(
                    line=7,
                    title=Ast.Text(line=7, text="Another scenario"),
                    steps=[
                        Ast.Step(line=8, title=Ast.Text(line=8, text="Given this step")),
                        Ast.Step(line=9, title=Ast.Text(line=9, text="When we take another step")),
                    ],
                ),
            ],
        )
    )
コード例 #3
0
ファイル: test_parser.py プロジェクト: butchland/gherkin
def test_parse_tags_on_scenario_outline_examples():
    "Parser should allow tags to be defined in examples"

    # Given a parser loaded with a document that contains tags on
    # scenario outline examples
    #   @tagged-feature
    #   Feature: Parse tags
    #   @tag1 @tag2
    #   Scenario Outline: Test
    #   @example-tag1
    #   @example-tag2
    #   Examples:
    #     | Header |

    parser = Parser([
        (1, gherkin.TOKEN_TAG, 'tagged-feature'),
        (1, gherkin.TOKEN_NEWLINE, '\n'),
        (2, gherkin.TOKEN_LABEL, 'Feature'),
        (2, gherkin.TOKEN_TEXT, 'Parse tags'),
        (2, gherkin.TOKEN_NEWLINE, '\n'),
        (3, gherkin.TOKEN_TAG, 'tag1'),
        (3, gherkin.TOKEN_TAG, 'tag2'),
        (3, gherkin.TOKEN_NEWLINE, '\n'),
        (4, gherkin.TOKEN_LABEL, 'Scenario Outline'),
        (4, gherkin.TOKEN_TEXT, 'Test'),
        (4, gherkin.TOKEN_NEWLINE, '\n'),
        (5, gherkin.TOKEN_TAG, 'example-tag1'),
        (5, gherkin.TOKEN_NEWLINE, '\n'),
        (6, gherkin.TOKEN_TAG, 'example-tag2'),
        (6, gherkin.TOKEN_NEWLINE, '\n'),
        (7, gherkin.TOKEN_LABEL, 'Examples'),
        (7, gherkin.TOKEN_NEWLINE, '\n'),
        (8, gherkin.TOKEN_TABLE_COLUMN, 'Header'),
        (8, gherkin.TOKEN_NEWLINE, '\n'),
        (9, gherkin.TOKEN_EOF, ''),
    ])

    # When I parse the document
    feature = parser.parse_feature()

    # Then I see all the tags were found
    feature.should.equal(
        Ast.Feature(line=2,
                    title=Ast.Text(line=2, text='Parse tags'),
                    tags=['tagged-feature'],
                    scenarios=[
                        Ast.ScenarioOutline(
                            line=4,
                            title=Ast.Text(line=4, text='Test'),
                            tags=['tag1', 'tag2'],
                            examples=Ast.Examples(
                                line=7,
                                tags=['example-tag1', 'example-tag2'],
                                table=Ast.Table(line=8, fields=[['Header']])),
                        )
                    ]))
コード例 #4
0
ファイル: test_parser.py プロジェクト: butchland/gherkin
def test_parse_tags_on_feature_and_scenario():

    # Given a parser loaded with a gherkin document with one tag on
    # the feature and two tags on a scenario:
    #
    #   @tagged-feature
    #   Feature: Parse tags
    #
    #   @tag1 @tag2
    #   Scenario: Test
    parser = Parser(
        [
            (1, gherkin.TOKEN_TAG, "tagged-feature"),
            (1, gherkin.TOKEN_NEWLINE, "\n"),
            (2, gherkin.TOKEN_LABEL, "Feature"),
            (2, gherkin.TOKEN_TEXT, "Parse tags"),
            (2, gherkin.TOKEN_NEWLINE, "\n"),
            (3, gherkin.TOKEN_NEWLINE, "\n"),
            (4, gherkin.TOKEN_TAG, "tag1"),
            (4, gherkin.TOKEN_TAG, "tag2"),
            (4, gherkin.TOKEN_NEWLINE, "\n"),
            (5, gherkin.TOKEN_LABEL, "Scenario"),
            (5, gherkin.TOKEN_TEXT, "Test"),
            (6, gherkin.TOKEN_NEWLINE, "\n"),
            (7, gherkin.TOKEN_EOF, ""),
        ]
    )

    feature = parser.parse_feature()

    feature.should.equal(
        Ast.Feature(
            line=2,
            title=Ast.Text(line=2, text="Parse tags"),
            tags=["tagged-feature"],
            scenarios=[Ast.Scenario(line=5, title=Ast.Text(line=5, text="Test"), tags=["tag1", "tag2"])],
        )
    )
コード例 #5
0
ファイル: test_parser.py プロジェクト: butchland/gherkin
def test_parse_tags_on_feature_and_scenario():

    # Given a parser loaded with a gherkin document with one tag on
    # the feature and two tags on a scenario:
    #
    #   @tagged-feature
    #   Feature: Parse tags
    #
    #   @tag1 @tag2
    #   Scenario: Test
    parser = Parser([
        (1, gherkin.TOKEN_TAG, 'tagged-feature'),
        (1, gherkin.TOKEN_NEWLINE, '\n'),
        (2, gherkin.TOKEN_LABEL, 'Feature'),
        (2, gherkin.TOKEN_TEXT, 'Parse tags'),
        (2, gherkin.TOKEN_NEWLINE, '\n'),
        (3, gherkin.TOKEN_NEWLINE, '\n'),
        (4, gherkin.TOKEN_TAG, 'tag1'),
        (4, gherkin.TOKEN_TAG, 'tag2'),
        (4, gherkin.TOKEN_NEWLINE, '\n'),
        (5, gherkin.TOKEN_LABEL, 'Scenario'),
        (5, gherkin.TOKEN_TEXT, 'Test'),
        (6, gherkin.TOKEN_NEWLINE, '\n'),
        (7, gherkin.TOKEN_EOF, ''),
    ])

    feature = parser.parse_feature()

    feature.should.equal(
        Ast.Feature(line=2,
                    title=Ast.Text(line=2, text='Parse tags'),
                    tags=['tagged-feature'],
                    scenarios=[
                        Ast.Scenario(line=5,
                                     title=Ast.Text(line=5, text='Test'),
                                     tags=['tag1', 'tag2'])
                    ]))
コード例 #6
0
ファイル: test_parser.py プロジェクト: butchland/gherkin
def test_parse_tables_within_steps():
    "Lexer.run() Should be able to parse example tables from steps"

    # Given a parser loaded with steps that contain example tables
    """Feature: Check models existence
		Background:
	   Given I have a garden in the database:
	      | @name  | area | raining |
	      | Secret Garden | 45   | false   |
	    And I have gardens in the database:
	      | name            | area | raining |
	      | Octopus' Garden | 120  | true    |
         Scenario: Plant a tree
           Given the <name> of a garden
           When I plant a tree
            And wait for <num_days> days
           Then I see it growing
    """
    parser = Parser(
        [
            (1, gherkin.TOKEN_LABEL, "Feature"),
            (1, gherkin.TOKEN_TEXT, "Check models existence"),
            (1, gherkin.TOKEN_NEWLINE, "\n"),
            (2, gherkin.TOKEN_LABEL, "Background"),
            (2, gherkin.TOKEN_NEWLINE, "\n"),
            (3, gherkin.TOKEN_LABEL, "Given I have a garden in the database"),
            (3, gherkin.TOKEN_NEWLINE, "\n"),
            (4, gherkin.TOKEN_TABLE_COLUMN, "@name"),
            (4, gherkin.TOKEN_TABLE_COLUMN, "area"),
            (4, gherkin.TOKEN_TABLE_COLUMN, "raining"),
            (4, gherkin.TOKEN_NEWLINE, "\n"),
            (5, gherkin.TOKEN_TABLE_COLUMN, "Secret Garden"),
            (5, gherkin.TOKEN_TABLE_COLUMN, "45"),
            (5, gherkin.TOKEN_TABLE_COLUMN, "false"),
            (5, gherkin.TOKEN_NEWLINE, "\n"),
            (6, gherkin.TOKEN_LABEL, "And I have gardens in the database"),
            (6, gherkin.TOKEN_NEWLINE, "\n"),
            (7, gherkin.TOKEN_TABLE_COLUMN, "name"),
            (7, gherkin.TOKEN_TABLE_COLUMN, "area"),
            (7, gherkin.TOKEN_TABLE_COLUMN, "raining"),
            (7, gherkin.TOKEN_NEWLINE, "\n"),
            (8, gherkin.TOKEN_TABLE_COLUMN, "Octopus' Garden"),
            (8, gherkin.TOKEN_TABLE_COLUMN, "120"),
            (8, gherkin.TOKEN_TABLE_COLUMN, "true"),
            (8, gherkin.TOKEN_NEWLINE, "\n"),
            (9, gherkin.TOKEN_LABEL, "Scenario"),
            (9, gherkin.TOKEN_TEXT, "Plant a tree"),
            (9, gherkin.TOKEN_NEWLINE, "\n"),
            (10, gherkin.TOKEN_TEXT, "Given the <name> of a garden"),
            (10, gherkin.TOKEN_NEWLINE, "\n"),
            (11, gherkin.TOKEN_TEXT, "When I plant a tree"),
            (11, gherkin.TOKEN_NEWLINE, "\n"),
            (12, gherkin.TOKEN_TEXT, "And wait for <num_days> days"),
            (12, gherkin.TOKEN_NEWLINE, "\n"),
            (13, gherkin.TOKEN_TEXT, "Then I see it growing"),
            (13, gherkin.TOKEN_NEWLINE, "\n"),
            (14, gherkin.TOKEN_EOF, ""),
        ]
    )

    feature = parser.parse_feature()

    feature.should.equal(
        Ast.Feature(
            line=1,
            title=Ast.Text(line=1, text="Check models existence"),
            background=Ast.Background(
                line=2,
                steps=[
                    Ast.Step(
                        line=3,
                        title=Ast.Text(line=3, text="Given I have a garden in the database"),
                        table=Ast.Table(
                            line=4, fields=[["@name", "area", "raining"], ["Secret Garden", "45", "false"]]
                        ),
                    ),
                    Ast.Step(
                        line=6,
                        title=Ast.Text(line=6, text="And I have gardens in the database"),
                        table=Ast.Table(
                            line=7, fields=[["name", "area", "raining"], ["Octopus' Garden", "120", "true"]]
                        ),
                    ),
                ],
            ),
            scenarios=[
                Ast.Scenario(
                    title=Ast.Text(line=9, text="Plant a tree"),
                    line=9,
                    steps=[
                        Ast.Step(line=10, title=Ast.Text(line=10, text="Given the <name> of a garden")),
                        Ast.Step(line=11, title=Ast.Text(line=11, text="When I plant a tree")),
                        Ast.Step(line=12, title=Ast.Text(line=12, text="And wait for <num_days> days")),
                        Ast.Step(line=13, title=Ast.Text(line=13, text="Then I see it growing")),
                    ],
                )
            ],
        )
    )
コード例 #7
0
ファイル: test_parser.py プロジェクト: butchland/gherkin
def test_parse_tables_within_steps():
    "Lexer.run() Should be able to parse example tables from steps"

    # Given a parser loaded with steps that contain example tables
    '''Feature: Check models existence
		Background:
	   Given I have a garden in the database:
	      | @name  | area | raining |
	      | Secret Garden | 45   | false   |
	    And I have gardens in the database:
	      | name            | area | raining |
	      | Octopus' Garden | 120  | true    |
         Scenario: Plant a tree
           Given the <name> of a garden
           When I plant a tree
            And wait for <num_days> days
           Then I see it growing
    '''
    parser = Parser([(1, gherkin.TOKEN_LABEL, 'Feature'),
                     (1, gherkin.TOKEN_TEXT, 'Check models existence'),
                     (1, gherkin.TOKEN_NEWLINE, '\n'),
                     (2, gherkin.TOKEN_LABEL, 'Background'),
                     (2, gherkin.TOKEN_NEWLINE, '\n'),
                     (3, gherkin.TOKEN_LABEL,
                      'Given I have a garden in the database'),
                     (3, gherkin.TOKEN_NEWLINE, '\n'),
                     (4, gherkin.TOKEN_TABLE_COLUMN, '@name'),
                     (4, gherkin.TOKEN_TABLE_COLUMN, 'area'),
                     (4, gherkin.TOKEN_TABLE_COLUMN, 'raining'),
                     (4, gherkin.TOKEN_NEWLINE, '\n'),
                     (5, gherkin.TOKEN_TABLE_COLUMN, 'Secret Garden'),
                     (5, gherkin.TOKEN_TABLE_COLUMN, '45'),
                     (5, gherkin.TOKEN_TABLE_COLUMN, 'false'),
                     (5, gherkin.TOKEN_NEWLINE, '\n'),
                     (6, gherkin.TOKEN_LABEL,
                      'And I have gardens in the database'),
                     (6, gherkin.TOKEN_NEWLINE, '\n'),
                     (7, gherkin.TOKEN_TABLE_COLUMN, 'name'),
                     (7, gherkin.TOKEN_TABLE_COLUMN, 'area'),
                     (7, gherkin.TOKEN_TABLE_COLUMN, 'raining'),
                     (7, gherkin.TOKEN_NEWLINE, '\n'),
                     (8, gherkin.TOKEN_TABLE_COLUMN, "Octopus' Garden"),
                     (8, gherkin.TOKEN_TABLE_COLUMN, '120'),
                     (8, gherkin.TOKEN_TABLE_COLUMN, 'true'),
                     (8, gherkin.TOKEN_NEWLINE, '\n'),
                     (9, gherkin.TOKEN_LABEL, 'Scenario'),
                     (9, gherkin.TOKEN_TEXT, 'Plant a tree'),
                     (9, gherkin.TOKEN_NEWLINE, '\n'),
                     (10, gherkin.TOKEN_TEXT, 'Given the <name> of a garden'),
                     (10, gherkin.TOKEN_NEWLINE, '\n'),
                     (11, gherkin.TOKEN_TEXT, 'When I plant a tree'),
                     (11, gherkin.TOKEN_NEWLINE, '\n'),
                     (12, gherkin.TOKEN_TEXT, 'And wait for <num_days> days'),
                     (12, gherkin.TOKEN_NEWLINE, '\n'),
                     (13, gherkin.TOKEN_TEXT, 'Then I see it growing'),
                     (13, gherkin.TOKEN_NEWLINE, '\n'),
                     (14, gherkin.TOKEN_EOF, '')])

    feature = parser.parse_feature()

    feature.should.equal(
        Ast.Feature(
            line=1,
            title=Ast.Text(line=1, text='Check models existence'),
            background=Ast.Background(
                line=2,
                steps=[
                    Ast.Step(line=3,
                             title=Ast.Text(
                                 line=3,
                                 text='Given I have a garden in the database'),
                             table=Ast.Table(
                                 line=4,
                                 fields=[['@name', 'area', 'raining'],
                                         ['Secret Garden', '45', 'false']])),
                    Ast.Step(line=6,
                             title=Ast.Text(
                                 line=6,
                                 text='And I have gardens in the database'),
                             table=Ast.Table(
                                 line=7,
                                 fields=[['name', 'area', 'raining'],
                                         ['Octopus\' Garden', '120',
                                          'true']])),
                ]),
            scenarios=[
                Ast.Scenario(
                    title=Ast.Text(line=9, text='Plant a tree'),
                    line=9,
                    steps=[
                        Ast.Step(line=10,
                                 title=Ast.Text(
                                     line=10,
                                     text='Given the <name> of a garden')),
                        Ast.Step(line=11,
                                 title=Ast.Text(line=11,
                                                text='When I plant a tree')),
                        Ast.Step(line=12,
                                 title=Ast.Text(
                                     line=12,
                                     text='And wait for <num_days> days')),
                        Ast.Step(line=13,
                                 title=Ast.Text(line=13,
                                                text='Then I see it growing'))
                    ])
            ],
        ))
コード例 #8
0
ファイル: test_parser.py プロジェクト: butchland/gherkin
def test_parse_feature():

    parser = Parser([
        (1, gherkin.TOKEN_LABEL, 'Feature'),
        (1, gherkin.TOKEN_TEXT, 'Feature title'),
        (1, gherkin.TOKEN_NEWLINE, '\n'),
        (2, gherkin.TOKEN_TEXT, 'feature description'),
        (2, gherkin.TOKEN_NEWLINE, '\n'),
        (3, gherkin.TOKEN_LABEL, 'Background'),
        (3, gherkin.TOKEN_TEXT, 'Some background'),
        (3, gherkin.TOKEN_NEWLINE, '\n'),
        (4, gherkin.TOKEN_TEXT, 'Given the problem'),
        (4, gherkin.TOKEN_NEWLINE, '\n'),
        (5, gherkin.TOKEN_LABEL, 'Scenario'),
        (5, gherkin.TOKEN_TEXT, 'Scenario title'),
        (5, gherkin.TOKEN_NEWLINE, '\n'),
        (6, gherkin.TOKEN_TEXT, 'Given first step'),
        (6, gherkin.TOKEN_NEWLINE, '\n'),
        (7, gherkin.TOKEN_LABEL, 'Scenario'),
        (7, gherkin.TOKEN_TEXT, 'Another scenario'),
        (7, gherkin.TOKEN_NEWLINE, '\n'),
        (8, gherkin.TOKEN_TEXT, 'Given this step'),
        (8, gherkin.TOKEN_NEWLINE, '\n'),
        (9, gherkin.TOKEN_TEXT, 'When we take another step'),
        (9, gherkin.TOKEN_NEWLINE, '\n'),
        (10, gherkin.TOKEN_EOF, ''),
    ])

    feature = parser.parse_feature()

    feature.should.equal(
        Ast.Feature(
            line=1,
            title=Ast.Text(line=1, text='Feature title'),
            description=Ast.Text(line=2, text='feature description'),
            background=Ast.Background(
                line=3,
                title=Ast.Text(line=3, text='Some background'),
                steps=[
                    Ast.Step(line=4,
                             title=Ast.Text(line=4, text='Given the problem'))
                ]),
            scenarios=[
                Ast.Scenario(line=5,
                             title=Ast.Text(line=5, text='Scenario title'),
                             steps=[
                                 Ast.Step(line=6,
                                          title=Ast.Text(
                                              line=6, text='Given first step'))
                             ]),
                Ast.Scenario(
                    line=7,
                    title=Ast.Text(line=7, text='Another scenario'),
                    steps=[
                        Ast.Step(line=8,
                                 title=Ast.Text(line=8,
                                                text='Given this step')),
                        Ast.Step(line=9,
                                 title=Ast.Text(
                                     line=9, text='When we take another step'))
                    ]),
            ],
        ))