tessl install tessl/pypi-pydantic@2.11.0Data validation using Python type hints
Agent Success
Agent success rate when using this tile
90%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.3x
Baseline
Agent success rate without this tile
69%
Build a configuration file validator that ensures file and directory paths exist before processing a configuration.
Create a configuration validator that validates file system paths. The validator should:
The configuration should include:
config_file field that must be an existing filedata_directory field that must be an existing directorylog_file field that can be any path (doesn't need to exist)Given that /tmp/test_config.txt exists as a file and /tmp/test_data exists as a directory, when validating a configuration with config_file: /tmp/test_config.txt, data_directory: /tmp/test_data, and log_file: /tmp/output.log, the configuration should validate successfully without errors. @test
Given that /tmp/nonexistent_config.txt does not exist, when validating a configuration with config_file: /tmp/nonexistent_config.txt, validation should fail with an error indicating the config_file path does not exist. @test
Given that /tmp/nonexistent_directory does not exist, when validating a configuration with data_directory: /tmp/nonexistent_directory, validation should fail with an error indicating the data_directory path does not exist. @test
Given that /tmp/test_config.txt exists as a file and /tmp/test_data exists as a directory, when validating a configuration without the optional log_file field, the configuration should validate successfully. @test
@generates
from pydantic import BaseModel
class FileSystemConfig(BaseModel):
"""Configuration model that validates file system paths."""
config_file: ... # Must be an existing file
data_directory: ... # Must be an existing directory
log_file: ... # Optional path, doesn't need to existProvides data validation support with path type validation.