|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +""" |
| 4 | +Configuration-driven Gherkin to SBDL mapping with flexible hierarchy support. |
| 5 | +""" |
| 6 | + |
| 7 | +from dataclasses import dataclass |
| 8 | +from typing import Dict, List, Optional, Union |
| 9 | +from enum import Enum |
| 10 | + |
| 11 | +class GherkinElementType(Enum): |
| 12 | + """Supported Gherkin element types for conversion.""" |
| 13 | + FEATURE = "feature" |
| 14 | + RULE = "rule" |
| 15 | + SCENARIO = "scenario" |
| 16 | + SCENARIO_OUTLINE = "scenario_outline" |
| 17 | + EXAMPLE = "example" |
| 18 | + BACKGROUND = "background" |
| 19 | + |
| 20 | +class SBDLElementType(Enum): |
| 21 | + """Supported SBDL element types for mapping.""" |
| 22 | + REQUIREMENT = "requirement" |
| 23 | + ASPECT = "aspect" |
| 24 | + USECASE = "usecase" |
| 25 | + DEFINITION = "definition" |
| 26 | + TEST = "test" |
| 27 | + |
| 28 | +@dataclass |
| 29 | +class HierarchyMapping: |
| 30 | + """Configuration for mapping Gherkin elements to SBDL with document hierarchy.""" |
| 31 | + gherkin_type: GherkinElementType |
| 32 | + sbdl_type: SBDLElementType |
| 33 | + |
| 34 | +@dataclass |
| 35 | +class ConversionConfig: |
| 36 | + """Complete configuration for Gherkin to SBDL conversion.""" |
| 37 | + hierarchy_mappings: List[HierarchyMapping] |
| 38 | + |
| 39 | + def get_mapping_for_type(self, gherkin_type: GherkinElementType) -> Optional[HierarchyMapping]: |
| 40 | + """Get the hierarchy mapping for a specific Gherkin element type.""" |
| 41 | + for mapping in self.hierarchy_mappings: |
| 42 | + if mapping.gherkin_type == gherkin_type: |
| 43 | + return mapping |
| 44 | + return None |
| 45 | + |
| 46 | +# Predefined configurations for different use cases |
| 47 | + |
| 48 | +# Current Configuration (Feature -> Rule mapping) |
| 49 | +FEATURE_RULE_CONFIG = ConversionConfig( |
| 50 | + hierarchy_mappings=[ |
| 51 | + HierarchyMapping( |
| 52 | + gherkin_type=GherkinElementType.FEATURE, |
| 53 | + sbdl_type=SBDLElementType.REQUIREMENT |
| 54 | + ), |
| 55 | + HierarchyMapping( |
| 56 | + gherkin_type=GherkinElementType.RULE, |
| 57 | + sbdl_type=SBDLElementType.REQUIREMENT |
| 58 | + ) |
| 59 | + ] |
| 60 | +) |
| 61 | + |
| 62 | +# Extended Configuration (Feature -> Rule -> Scenario mapping) |
| 63 | +FEATURE_RULE_SCENARIO_CONFIG = ConversionConfig( |
| 64 | + hierarchy_mappings=[ |
| 65 | + HierarchyMapping( |
| 66 | + gherkin_type=GherkinElementType.FEATURE, |
| 67 | + sbdl_type=SBDLElementType.ASPECT |
| 68 | + ), |
| 69 | + HierarchyMapping( |
| 70 | + gherkin_type=GherkinElementType.RULE, |
| 71 | + sbdl_type=SBDLElementType.REQUIREMENT |
| 72 | + ), |
| 73 | + HierarchyMapping( |
| 74 | + gherkin_type=GherkinElementType.SCENARIO, |
| 75 | + sbdl_type=SBDLElementType.TEST |
| 76 | + ) |
| 77 | + ] |
| 78 | +) |
| 79 | + |
| 80 | +# Flat Configuration (All as requirements at same level) |
| 81 | +FLAT_CONFIG = ConversionConfig( |
| 82 | + hierarchy_mappings=[ |
| 83 | + HierarchyMapping( |
| 84 | + gherkin_type=GherkinElementType.FEATURE, |
| 85 | + sbdl_type=SBDLElementType.REQUIREMENT |
| 86 | + ), |
| 87 | + HierarchyMapping( |
| 88 | + gherkin_type=GherkinElementType.RULE, |
| 89 | + sbdl_type=SBDLElementType.REQUIREMENT |
| 90 | + ) |
| 91 | + ] |
| 92 | +) |
| 93 | + |
| 94 | +# Use Case Focused Configuration |
| 95 | +USECASE_CONFIG = ConversionConfig( |
| 96 | + hierarchy_mappings=[ |
| 97 | + HierarchyMapping( |
| 98 | + gherkin_type=GherkinElementType.FEATURE, |
| 99 | + sbdl_type=SBDLElementType.USECASE |
| 100 | + ), |
| 101 | + HierarchyMapping( |
| 102 | + gherkin_type=GherkinElementType.SCENARIO, |
| 103 | + sbdl_type=SBDLElementType.USECASE |
| 104 | + ) |
| 105 | + ] |
| 106 | +) |
0 commit comments