Feature: InlineJinjaHandler Coverage As a developer I want to thoroughly test the InlineJinjaHandler class So that we achieve 90%+ code coverage for the inline_jinja_handler.py module Background: Given I have an InlineJinjaHandler instance Scenario: Initialize InlineJinjaHandler with correct Jinja2 environment When I create a new InlineJinjaHandler instance Then the Jinja2 environment should be configured with correct delimiters And the environment should have trim_blocks and lstrip_blocks enabled Scenario: Process YAML file without Jinja templates Given I have a YAML file without any Jinja templates When I process the YAML file with defer_rendering True Then it should return the parsed YAML content directly And no templates should be stored Scenario: Process YAML file without Jinja templates with defer_rendering False Given I have a YAML file without any Jinja templates When I process the YAML file with defer_rendering False Then it should return the parsed YAML content directly And no templates should be stored Scenario: Process YAML string without Jinja templates Given I have a YAML string without any Jinja templates When I process the YAML string with defer_rendering True Then it should return the parsed YAML content directly And no templates should be stored Scenario: Process YAML string with defer_rendering enabled Given I have a YAML string with Jinja templates When I process the YAML string with templates for defer_rendering True Then it should extract templates and replace them with placeholders And the templates should be stored under "__templates__" key Scenario: Process YAML string with immediate rendering Given I have a YAML string with Jinja templates And I have a context for rendering When I process the YAML string with defer_rendering False Then it should render the templates immediately and return parsed YAML And no template placeholders should remain Scenario: Process YAML string with immediate rendering and no context Given I have a YAML string with Jinja templates When I process the YAML string with defer_rendering False and no context Then it should render with an empty context And return the parsed YAML result Scenario: Extract templates from YAML with inline templates Given I have YAML content with inline Jinja variable templates When I extract templates from the content Then inline templates should be replaced with unique placeholders And template information should be stored with type "inline" Scenario: Extract templates from YAML with block templates Given I have YAML content with Jinja block templates like for loops When I extract templates from the content Then block templates should be replaced with unique placeholders And template information should be stored with type "block" Scenario: Extract templates from complex YAML with mixed templates Given I have YAML content with both inline and block templates When I extract templates from the content Then both types of templates should be extracted correctly And each should have appropriate type and metadata Scenario: Handle YAML with no template blocks during extraction Given I have YAML content without any template blocks When I extract templates from the content Then the YAML should be parsed normally And no templates should be stored Scenario: Process nested template blocks with proper indentation Given I have YAML with nested template blocks at different indentation levels When I extract templates from the content Then the indentation should be preserved correctly And parent key relationships should be maintained Scenario: Handle template blocks with different keywords Given I have YAML with various template block keywords | keyword | | for | | if | | macro | | block | When I extract templates from the content Then all block types should be identified correctly And appropriate template metadata should be stored Scenario: Handle template block end keywords Given I have YAML with template blocks that have proper end keywords | end_keyword | | endfor | | endif | | endmacro | | endblock | When I extract templates from the content Then the block boundaries should be detected correctly And templates should be extracted completely Scenario: Render templates with utility context functions Given I have YAML with templates using utility functions And I have a basic context When I render the templates with the context Then utility functions like range, len, str should be available And the templates should render correctly Scenario: Apply stored templates to configuration Given I have a configuration with template placeholders And I have stored templates And I have a rendering context for templates When I apply templates to the configuration Then template placeholders should be replaced with rendered content And the "__templates__" key should be removed from result Scenario: Apply templates recursively to nested data structures Given I have a nested configuration with template placeholders in various locations And I have stored templates for each placeholder And I have a rendering context for templates When I apply templates recursively Then all placeholders should be replaced at any nesting level And the structure should be preserved Scenario: Apply templates to configuration without stored templates Given I have a configuration without any "__templates__" key When I apply templates to the configuration Then the configuration should be returned unchanged And no processing should occur Scenario: Handle block template rendering in apply_templates Given I have a configuration with block template placeholders And I have stored block templates And I have a rendering context When I apply templates to the configuration Then block templates should be rendered and parsed as YAML And the results should be merged into the configuration Scenario: Handle inline template rendering in apply_templates Given I have a configuration with inline template placeholders And I have stored inline templates And I have a rendering context When I apply templates to the configuration Then inline templates should be rendered And the values should be parsed to appropriate Python types Scenario: Handle template rendering errors gracefully Given I have a configuration with template placeholders And I have stored templates that may cause parsing errors And I have a rendering context When I apply templates to the configuration Then parsing errors should be handled gracefully And fallback behavior should be applied Scenario: Render single template string with context Given I have a template string with Jinja syntax And I have a context with variables When I render the template string Then the variables should be substituted correctly And utility functions should be available in the context Scenario: Parse rendered values to appropriate Python types Given I have various rendered string values | value_type | rendered_value | | integer | "42" | | float | "3.14" | | boolean | "true" | | list | "[1, 2, 3]" | | dict | "{a: 1}" | | string | "hello" | When I parse each rendered value Then each should be converted to the appropriate Python type And invalid YAML should fall back to string type Scenario: Handle file reading errors Given I have an invalid file path When I try to process the YAML file Then a FileNotFoundError should be raised And the error should propagate appropriately Scenario: Handle YAML parsing errors during extraction Given I have YAML content that causes parsing errors after template extraction When I extract templates from the content Then the YAML parsing error should be logged And debug information should be provided And the error should be re-raised Scenario: Handle template extraction with no parent key found Given I have YAML with template blocks that have no clear parent key When I extract templates from the content Then the extraction should handle the edge case gracefully And template information should still be stored appropriately Scenario: Handle template blocks at root level indentation Given I have YAML with template blocks at zero indentation When I extract templates from the content Then the blocks should be processed correctly And indentation should be handled properly Scenario: Handle empty template block content Given I have YAML with empty template blocks When I extract templates from the content Then empty blocks should be handled without errors And appropriate placeholders should be generated Scenario: Handle malformed template blocks Given I have YAML with malformed template block syntax When I extract templates from the content Then the malformed syntax should be handled gracefully And extraction should continue for valid parts Scenario: Process non-dict parsed YAML in extraction Given I have YAML content that parses to a non-dict type When I extract templates and the result is not a dictionary Then it should be wrapped in a "_content" key And templates should still be attached properly Scenario: Handle complex nested key-value matching in extraction Given I have complex YAML with nested keys and template values When I extract templates with inline patterns Then key-value pairs should be matched correctly And templates should preserve the original structure Scenario: Process YAML with comments and template blocks Given I have YAML with comments mixed with template blocks When I extract templates from the content Then comments should be preserved appropriately And template extraction should not be affected by comments Scenario: Handle edge case indentation scenarios Given I have YAML with unusual indentation patterns around templates When I extract templates from the content Then indentation should be calculated correctly And template boundaries should be respected Scenario: Validate template ID generation uniqueness Given I have YAML with multiple templates When I extract templates from the content Then each template should have a unique ID And IDs should follow the expected format pattern Scenario: Handle large YAML files with many templates Given I have a large YAML file with numerous templates When I process the file with template extraction Then all templates should be extracted efficiently And memory usage should be reasonable And performance should be acceptable