182 lines
8.3 KiB
Plaintext
182 lines
8.3 KiB
Plaintext
Feature: Template Loaders Coverage
|
|
As a developer
|
|
I want to test all functionality in the template loaders module
|
|
So that we achieve 90%+ code coverage for the loaders.py file
|
|
|
|
Background:
|
|
Given I have a clean test environment for template loaders
|
|
|
|
Scenario: Test TemplateLoader base class instantiation
|
|
Given I have a template renderer for loaders
|
|
When I create a base TemplateLoader instance
|
|
Then the TemplateLoader should be initialized with renderer
|
|
And the renderer should be accessible
|
|
|
|
Scenario: Test TemplateLoader base class load method raises NotImplementedError
|
|
Given I have a template renderer for loaders
|
|
And I have a base TemplateLoader instance
|
|
When I call the load method on base TemplateLoader
|
|
Then a NotImplementedError should be raised
|
|
And the not implemented error message should be correct
|
|
|
|
Scenario: Test FileTemplateLoader initialization
|
|
Given I have a template renderer for loaders
|
|
And I have valid file paths for templates
|
|
When I create a FileTemplateLoader instance
|
|
Then the FileTemplateLoader should be initialized correctly
|
|
And the file paths should be stored
|
|
|
|
Scenario: Test FileTemplateLoader load with valid files
|
|
Given I have a template renderer for loaders
|
|
And I have temporary template files created
|
|
When I create and use FileTemplateLoader to load templates
|
|
Then the templates should be loaded successfully
|
|
And the templates should be registered with the renderer
|
|
And the template names should be derived from file stems
|
|
|
|
Scenario: Test FileTemplateLoader load with non-existent file
|
|
Given I have a template renderer for loaders
|
|
And I have a non-existent file path
|
|
When I create and use FileTemplateLoader with non-existent file
|
|
Then a TemplateError should be raised
|
|
And the template file not found error should be raised
|
|
|
|
Scenario: Test FileTemplateLoader load with file read error
|
|
Given I have a template renderer for loaders
|
|
And I have an unreadable file path
|
|
When I create and use FileTemplateLoader with unreadable file
|
|
Then a TemplateError should be raised
|
|
And the failed to load template file error should be raised
|
|
|
|
Scenario: Test DirectoryTemplateLoader initialization
|
|
Given I have a template renderer for loaders
|
|
And I have a valid directory path
|
|
When I create a DirectoryTemplateLoader instance
|
|
Then the DirectoryTemplateLoader should be initialized correctly
|
|
And the directory path should be stored
|
|
And the recursive flag should be set correctly
|
|
And the pattern should be set correctly
|
|
|
|
Scenario: Test DirectoryTemplateLoader initialization with custom parameters
|
|
Given I have a template renderer for loaders
|
|
And I have a valid directory path
|
|
When I create a DirectoryTemplateLoader with custom parameters
|
|
Then the DirectoryTemplateLoader should be initialized with custom settings
|
|
And the recursive flag should be false
|
|
And the pattern should be "*.txt"
|
|
|
|
Scenario: Test DirectoryTemplateLoader load with valid directory
|
|
Given I have a template renderer for loaders
|
|
And I have a temporary directory with template files
|
|
When I create and use DirectoryTemplateLoader to load templates
|
|
Then the templates should be loaded from directory
|
|
And the templates should be registered with correct names
|
|
And the template names should use relative paths
|
|
|
|
Scenario: Test DirectoryTemplateLoader load with non-recursive setting
|
|
Given I have a template renderer for loaders
|
|
And I have a temporary directory with nested template files
|
|
When I create and use DirectoryTemplateLoader with non-recursive setting
|
|
Then only templates from root directory should be loaded
|
|
And nested templates should not be loaded
|
|
|
|
Scenario: Test DirectoryTemplateLoader load with custom pattern
|
|
Given I have a template renderer for loaders
|
|
And I have a temporary directory with mixed file types
|
|
When I create and use DirectoryTemplateLoader with custom pattern
|
|
Then only matching files should be loaded
|
|
And non-matching files should be ignored
|
|
|
|
Scenario: Test DirectoryTemplateLoader load with non-existent directory
|
|
Given I have a template renderer for loaders
|
|
And I have a non-existent directory path
|
|
When I create and use DirectoryTemplateLoader with non-existent directory
|
|
Then a TemplateError should be raised
|
|
And the template directory not found error should be raised
|
|
|
|
Scenario: Test DirectoryTemplateLoader load with file instead of directory
|
|
Given I have a template renderer for loaders
|
|
And I have a file path instead of directory
|
|
When I create and use DirectoryTemplateLoader with file path
|
|
Then a TemplateError should be raised
|
|
And the not a directory error should be raised
|
|
|
|
Scenario: Test DirectoryTemplateLoader load with file read error in directory
|
|
Given I have a template renderer for loaders
|
|
And I have a directory with unreadable template file
|
|
When I create and use DirectoryTemplateLoader with problematic directory
|
|
Then a TemplateError should be raised
|
|
And the failed to load template file error should be raised
|
|
|
|
Scenario: Test ConfigTemplateLoader initialization
|
|
Given I have a template renderer for loaders
|
|
And I have a valid config dictionary
|
|
When I create a ConfigTemplateLoader instance
|
|
Then the ConfigTemplateLoader should be initialized correctly
|
|
And the config should be stored
|
|
|
|
Scenario: Test ConfigTemplateLoader load with string templates
|
|
Given I have a template renderer for loaders
|
|
And I have a config with string templates
|
|
When I create and use ConfigTemplateLoader to load templates
|
|
Then the string templates should be loaded
|
|
And the string templates should be registered with correct names
|
|
|
|
Scenario: Test ConfigTemplateLoader load with dict templates
|
|
Given I have a template renderer for loaders
|
|
And I have a config with dict templates containing content
|
|
When I create and use ConfigTemplateLoader to load dict templates
|
|
Then the dict templates should be loaded
|
|
And only the content should be registered
|
|
|
|
Scenario: Test ConfigTemplateLoader load with empty config
|
|
Given I have a template renderer for loaders
|
|
And I have an empty config dictionary
|
|
When I create and use ConfigTemplateLoader with empty config
|
|
Then no templates should be loaded
|
|
And no errors should occur
|
|
|
|
Scenario: Test ConfigTemplateLoader load with no templates section
|
|
Given I have a template renderer for loaders
|
|
And I have a config without templates section for loaders
|
|
When I create and use ConfigTemplateLoader with config without templates
|
|
Then no templates should be loaded
|
|
And no errors should occur
|
|
|
|
Scenario: Test ConfigTemplateLoader load with invalid template definition
|
|
Given I have a template renderer for loaders
|
|
And I have a config with invalid template definition
|
|
When I create and use ConfigTemplateLoader with invalid config
|
|
Then a TemplateError should be raised
|
|
And the invalid template definition error should be raised
|
|
|
|
Scenario: Test ConfigTemplateLoader load with exception during processing
|
|
Given I have a template renderer for loaders
|
|
And I have a config that will cause processing exception
|
|
When I create and use ConfigTemplateLoader with problematic config
|
|
Then a TemplateError should be raised
|
|
And the failed to load from configuration error should be raised
|
|
|
|
Scenario: Test load_from_file function with existing file
|
|
Given I have a temporary file with content
|
|
When I call load_from_file with the file path
|
|
Then the file content should be returned
|
|
And the content should match the original
|
|
|
|
Scenario: Test load_from_file function with non-existent file
|
|
Given I have a non-existent file path for load_from_file
|
|
When I call load_from_file with non-existent path
|
|
Then None should be returned from load_from_file
|
|
|
|
Scenario: Test load_from_file function with read error
|
|
Given I have an unreadable file for load_from_file
|
|
When I call load_from_file with unreadable file
|
|
Then a TemplateError should be raised
|
|
And the failed to load template file error should be raised
|
|
|
|
Scenario: Test load_from_string function
|
|
Given I have a template string for load_from_string
|
|
When I call load_from_string with the template string
|
|
Then the same string should be returned
|
|
And the returned string should be identical to input
|