Ejemplo n.º 1
0
    def setUp(self):
        parsed = parse_lines(u"""
            @tag1 @tag2
            @tag3
            Feature: Feature title
                Feature description 1
                Feature description 2

                Background: Background title
                    Background description 1
                    Background description 2

                    Given background-given
                    When background-when
                    Then background-then

                @tagA @tagB
                @tagC
                Scenario: Scenario title
                    Scenario description 1
                    Scenario description 2

                    Given scenario-given
                        | key | value |
                        | abc | 123   |
                        | def | 456   |
                        | ghi |
                    When scenario-when
                        '''
                        Text 1
                        Text 2
                        '''
                    Then scenario-then

                @tagD @tagE
                @tagF
                Scenario Outline: Scenario outline title
                    Scenario outline description 1
                    Scenario outline description 2

                    Given <key> is <value>-given
                        '''
                        Text <key> is <value>
                        '''
                    When <key> is <value>-when
                    Then <key> is <value>-then

                    Examples: Examples title
                        | key  | value  |
                        | key1 | value1 |
                        | key2 | value2 |
        """.split('\n'))

        self.feature = Feature(parsed)
Ejemplo n.º 2
0
    def test_generate(self):
        feature = Feature.from_string(u'''
            Feature:
                Scenario:
                    Given I enter "*****@*****.**" in the email field
        ''')
        step = feature.scenarios[0].steps[0]

        self.assertGenerated(
            CodeGen.generate_step_handler(step, 'given_example'),
            r'''
            @given(r'(?i)^I enter "*****@*****.**" in the email field$')
            def given_example(self, step):
                """
                Given I enter "*****@*****.**" in the email field
                """

                assert False
            '''
        )
Ejemplo n.º 3
0
    def test_same_step_title(self):
        feature = Feature.from_string(u"""
            Feature: Feature title
                Scenario: Scenario title
                    Given scenario given
                    And scenario given
        """)
        steps = feature.scenarios[0].steps

        self.assertGenerated(
            CodeGen.generate_step_handlers(steps),
            r'''
            @given(r'(?i)^scenario given$')
            def given_scenario_given(self, step):
                """
                Given scenario given
                """

                assert False
            '''
        )
Ejemplo n.º 4
0
    def test_unimplemented_feature(self):
        if not self.runner:
            raise Exception('Test runner not set')

        unimplemented = collections.defaultdict(list)
        for feature_filename in self.iter_feature_filenames('.'):
            feature_filename = os.path.abspath(feature_filename)
            feature = Feature.from_filename(feature_filename)

            for scenario in feature.scenarios:
                if scenario.title not in self.runner.implemented_scenarios[
                        feature_filename]:
                    unimplemented[feature_filename].append(scenario.title)

        if unimplemented:
            raise UnimplementedScenariosError('\n{}'.format('\n'.join(
                ' * {}\n{}'.format(
                    os.path.relpath(feature_filename), '\n'.join(
                        '   * {}'.format(scenario_title)
                        for scenario_title in scenario_titles))
                for feature_filename, scenario_titles in sorted(
                    unimplemented.iteritems()))))
Ejemplo n.º 5
0
    def test_function_name_collision(self):
        feature = Feature.from_string(u"""
            Feature: Feature title
                Scenario: Scenario title
                    Given step title
                    And step !! title
                    When step title
        """)
        steps = feature.scenarios[0].steps

        self.assertGenerated(
            CodeGen.generate_step_handlers(steps),
            r'''
            @given(r'(?i)^step title$')
            def given_step_title(self, step):
                """
                Given step title
                """

                assert False

            @given(r'(?i)^step !! title$')
            def given_step_title_2(self, step):
                """
                Given step !! title
                """

                assert False

            @when(r'(?i)^step title$')
            def when_step_title(self, step):
                """
                When step title
                """

                assert False
            '''
        )
Ejemplo n.º 6
0
    def test_generate(self):
        feature = Feature.from_string(u"""
            Feature: Feature title
                Background:
                    Given background given
                    When background when
                    Then background then

                Scenario: Scenario title
                    Given scenario title
                    When scenario title
                    Then scenario title

                Scenario Outline: Scenario Outline title
                    Given scenario outline <key> is <value>
                    When scenario outline <key> is <value>
                    Then scenario outline <key> is <value>

                    Examples:
                        | key     | value      |
                        | title   | "a title"  |
                        | success | guaranteed |
        """)

        self.assertGenerated(
            CodeGen.generate_test_module(feature),
            r'''
            from swanson import TestCase, step, given, when, then

            class BDDFeatureTitleTestCase(TestCase):
                """
                Feature title
                """

                def test_scenario_title(self):
                    """
                    Scenario title
                    """

                    self.run_scenario({Scenario title|u})

                def test_scenario_outline_title(self):
                    """
                    Scenario Outline title
                    """

                    self.run_scenario({Scenario Outline title|u})

                @given(r'(?i)^background given$')
                def given_background_given(self, step):
                    """
                    Given background given
                    """

                    assert False

                @given(r'(?i)^scenario title$')
                def given_scenario_title(self, step):
                    """
                    Given scenario title
                    """

                    assert False

                @given(r'(?i)^scenario outline title is "a title"$')
                def given_scenario_outline_title_is_a_title(self, step):
                    """
                    Given scenario outline title is "a title"
                    """

                    assert False

                @given(r'(?i)^scenario outline success is guaranteed$')
                def given_scenario_outline_success_is_guaranteed(self, step):
                    """
                    Given scenario outline success is guaranteed
                    """

                    assert False

                @when(r'(?i)^background when$')
                def when_background_when(self, step):
                    """
                    When background when
                    """

                    assert False

                @when(r'(?i)^scenario title$')
                def when_scenario_title(self, step):
                    """
                    When scenario title
                    """

                    assert False

                @when(r'(?i)^scenario outline title is "a title"$')
                def when_scenario_outline_title_is_a_title(self, step):
                    """
                    When scenario outline title is "a title"
                    """

                    assert False

                @when(r'(?i)^scenario outline success is guaranteed$')
                def when_scenario_outline_success_is_guaranteed(self, step):
                    """
                    When scenario outline success is guaranteed
                    """

                    assert False

                @then(r'(?i)^background then$')
                def then_background_then(self, step):
                    """
                    Then background then
                    """

                    assert False

                @then(r'(?i)^scenario title$')
                def then_scenario_title(self, step):
                    """
                    Then scenario title
                    """

                    assert False

                @then(r'(?i)^scenario outline title is "a title"$')
                def then_scenario_outline_title_is_a_title(self, step):
                    """
                    Then scenario outline title is "a title"
                    """

                    assert False

                @then(r'(?i)^scenario outline success is guaranteed$')
                def then_scenario_outline_success_is_guaranteed(self, step):
                    """
                    Then scenario outline success is guaranteed
                    """

                    assert False

            '''.format(**{
                'Scenario title|u': repr(u'Scenario title'),
                'Scenario Outline title|u': repr(u'Scenario Outline title')
            })
        )
Ejemplo n.º 7
0
 def get_feature(self):
     return Feature.from_filename(self.get_feature_filename())