Esempio n. 1
0
    def then_after_when(self):
        with setup:
            spec_metadata = get_basic_spec_metadata()
            spec_metadata.add_feature_block('test_it', 'when')
            enforcer = FeatureBlockRuleEnforcer(spec_metadata, 'test_it', {})

        with expect:
            enforcer.enforce_addition_rules('then')
Esempio n. 2
0
    def add_setup_and_given_as_first_blocks(self):
        with setup:
            spec_metadata = get_basic_spec_metadata()
            enforcer = FeatureBlockRuleEnforcer(spec_metadata, 'test_it', {})

        with expect:
            enforcer.enforce_addition_rules('given')
            enforcer.enforce_addition_rules('setup')
Esempio n. 3
0
    def then_cant_precede_when(self):
        with setup:
            spec_metadata = get_basic_spec_metadata()
            enforcer = FeatureBlockRuleEnforcer(spec_metadata, 'test_it', {})

        with when:
            enforcer.enforce_addition_rules('then')

        with then:
            thrown(InvalidFeatureBlockException)
Esempio n. 4
0
    def when_cant_dangle(self):
        with setup:
            spec_metadata = get_basic_spec_metadata()
            spec_metadata.add_feature_block('test_it', 'when')
            enforcer = FeatureBlockRuleEnforcer(spec_metadata, 'test_it', {})

        with when:
            enforcer.enforce_tail_end_rules()

        with then:
            thrown(InvalidFeatureBlockException)
Esempio n. 5
0
    def cant_add_more_than_one_where(self):
        with setup:
            spec_metadata = get_basic_spec_metadata()
            spec_metadata.add_feature_block('test_it', 'where')
            enforcer = FeatureBlockRuleEnforcer(spec_metadata, 'test_it', {})

        with when:
            enforcer.enforce_addition_rules('where')

        with then:
            thrown(InvalidFeatureBlockException)
Esempio n. 6
0
    def when_cant_be_followed_by_expect(self):
        with setup:
            spec_metadata = get_basic_spec_metadata()
            spec_metadata.add_feature_block('test_it', 'when')
            enforcer = FeatureBlockRuleEnforcer(spec_metadata, 'test_it', {})

        with when:
            enforcer.enforce_addition_rules('expect')

        with then:
            thrown(InvalidFeatureBlockException)
Esempio n. 7
0
    def setup_and_given_are_allowed_only_in_the_beginning(self):
        with setup:
            spec_metadata = get_basic_spec_metadata()
            spec_metadata.add_feature_block('test_it', 'expect')
            enforcer = FeatureBlockRuleEnforcer(spec_metadata, 'test_it', {})

        with when:
            enforcer.enforce_addition_rules(block_to_add)

        with then:
            thrown(InvalidFeatureBlockException)

        with where:
            block_to_add = ['given', 'setup']
Esempio n. 8
0
    def only_one_setup_is_allowed(self):
        with setup:
            spec_metadata = get_basic_spec_metadata()
            spec_metadata.add_feature_block('test_it', 'setup')
            enforcer = FeatureBlockRuleEnforcer(spec_metadata, 'test_it', {})

        with when:
            enforcer.enforce_addition_rules(block_to_add)

        with then:
            thrown(InvalidFeatureBlockException)

        with where:
            block_to_add = ['given', 'setup']
Esempio n. 9
0
    def visit_FunctionDef(self, feature_node):
        if FeatureRegistrationTransformer._skip_feature(feature_node):
            return feature_node

        feature_name = feature_node.name
        if not feature_name.startswith('_'):

            feature_name_specified = hasattr(self.spec_location, 'feature_name')

            if not feature_name_specified or (
                    feature_name_specified and self.spec_location.feature_name == feature_name):
                self.spec_metadata.add_feature(feature_name)
                FeatureBlockTransformer(self.spec_metadata, feature_name).visit(feature_node)
                FeatureBlockRuleEnforcer(self.spec_metadata, feature_name, feature_node).enforce_tail_end_rules()

        feature_variables = self.spec_metadata.feature_variables.get(feature_name)
        if feature_variables:
            existing_arg_names = [existing_arg.arg for existing_arg in feature_node.args.args]

            for feature_variable in feature_variables:
                if feature_variable in existing_arg_names:
                    continue
                feature_node.args.args.append(_ast.arg(arg=feature_variable))
                feature_node.args.defaults.append(ast_proxy.ast_name_constant(value=None))

        if self._feature_has_a_where_function(feature_name):
            self._remove_where_function_from_node(feature_name, feature_node)
        return feature_node
Esempio n. 10
0
    def visit_FunctionDef(self, feature_node):
        feature_name = feature_node.name
        if not feature_name.startswith('_'):
            self.spec_metadata.add_feature(feature_name)
            FeatureBlockTransformer(self.spec_metadata,
                                    feature_name).visit(feature_node)
            FeatureBlockRuleEnforcer(self.spec_metadata, feature_name,
                                     feature_node).enforce_tail_end_rules()

        feature_variables = self.spec_metadata.feature_variables.get(
            feature_name)
        if feature_variables:
            existing_arg_names = [
                existing_arg.arg for existing_arg in feature_node.args.args
            ]

            for feature_variable in feature_variables:
                if feature_variable in existing_arg_names:
                    continue
                feature_node.args.args.append(_ast.arg(arg=feature_variable))
                feature_node.args.defaults.append(
                    _ast.NameConstant(value=None))

        if self._feature_has_a_where_function(feature_name):
            self._remove_where_function_from_node(feature_name, feature_node)
        return feature_node