tessl install tessl/pypi-frozendict@2.4.0A simple immutable dictionary implementation with hashing support and performance optimizations
Agent Success
Agent success rate when using this tile
85%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.31x
Baseline
Agent success rate without this tile
65%
Build a configuration manager system that loads application settings from various sources and provides thread-safe, immutable access to configuration data.
Implement a ConfigurationManager class with the following functionality:
Initialization: The manager should accept configuration data from multiple sources during initialization:
Loading from Dictionary: Implement a load_from_dict(config_dict) method that creates and returns an immutable configuration object from a dictionary.
Loading from Key-Value Pairs: Implement a load_from_pairs(pairs) method that creates and returns an immutable configuration object from an iterable of (key, value) tuples.
Merging Configurations: Implement a merge_configs(*configs) method that takes multiple configuration objects and returns a single merged immutable configuration (later configs override earlier ones).
Empty Configuration: Implement a create_empty() method that returns an empty immutable configuration object.
config_manager.py: Main implementationtest_config_manager.py: Test casesProvides immutable dictionary support for configuration management.
Test ID: @test-basic-init
# test_config_manager.py
def test_basic_initialization():
"""Test creating configurations from various initialization patterns"""
manager = ConfigurationManager(
{"app_name": "MyApp", "debug": False},
version="1.0.0"
)
# Test loading from dict
config = manager.load_from_dict({"port": 8080, "host": "localhost"})
assert config["port"] == 8080
assert config["host"] == "localhost"
assert len(config) == 2Test ID: @test-pairs-loading
# test_config_manager.py
def test_load_from_pairs():
"""Test creating configuration from key-value pairs"""
manager = ConfigurationManager({})
pairs = [("database", "postgresql"), ("cache", "redis"), ("queue", "rabbitmq")]
config = manager.load_from_pairs(pairs)
assert config["database"] == "postgresql"
assert config["cache"] == "redis"
assert config["queue"] == "rabbitmq"
assert "database" in configTest ID: @test-empty-config
# test_config_manager.py
def test_empty_configuration():
"""Test creating and using empty configuration"""
manager = ConfigurationManager({})
config = manager.create_empty()
assert len(config) == 0
assert "any_key" not in configTest ID: @test-immutability
# test_config_manager.py
def test_configuration_immutability():
"""Test that configurations cannot be modified"""
manager = ConfigurationManager({})
config = manager.load_from_dict({"setting": "value"})
# Attempt to modify should raise an error
try:
config["setting"] = "new_value"
assert False, "Should not allow modification"
except TypeError:
pass # Expected behaviorTest ID: @test-merge-configs
# test_config_manager.py
def test_merge_configurations():
"""Test merging multiple configurations"""
manager = ConfigurationManager({})
defaults = manager.load_from_dict({"timeout": 30, "retries": 3, "debug": False})
overrides = manager.load_from_dict({"timeout": 60, "debug": True})
merged = manager.merge_configs(defaults, overrides)
assert merged["timeout"] == 60 # Overridden
assert merged["retries"] == 3 # From defaults
assert merged["debug"] == True # OverriddenTest ID: @test-hashability
# test_config_manager.py
def test_configuration_hashability():
"""Test that configurations can be used as dictionary keys"""
manager = ConfigurationManager({})
config1 = manager.load_from_dict({"env": "production"})
config2 = manager.load_from_dict({"env": "development"})
# Should be able to use as dictionary keys
config_registry = {
config1: "prod_settings",
config2: "dev_settings"
}
assert config_registry[config1] == "prod_settings"
assert config_registry[config2] == "dev_settings"