Ctrl + k

or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/frozendict@2.4.x
tile.json

tessl/pypi-frozendict

tessl install tessl/pypi-frozendict@2.4.0

A 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%

task.mdevals/scenario-3/

Configuration Manager

Overview

Build a configuration manager system that loads application settings from various sources and provides thread-safe, immutable access to configuration data.

Requirements

ConfigurationManager Class

Implement a ConfigurationManager class with the following functionality:

  1. Initialization: The manager should accept configuration data from multiple sources during initialization:

    • A dictionary of default configuration values
    • Keyword arguments for override values
    • A list of key-value tuples for additional settings
  2. Loading from Dictionary: Implement a load_from_dict(config_dict) method that creates and returns an immutable configuration object from a dictionary.

  3. 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.

  4. 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).

  5. Empty Configuration: Implement a create_empty() method that returns an empty immutable configuration object.

Requirements

  • All configuration objects returned by the manager must be immutable and hashable.
  • The manager should handle empty configurations gracefully.
  • Configuration objects should support standard dictionary-like read operations (accessing values by key, checking membership, iteration).
  • The manager should prevent modification of configuration objects after creation.

File Structure

  • config_manager.py: Main implementation
  • test_config_manager.py: Test cases

Dependencies { .dependencies }

frozendict { .dependency }

Provides immutable dictionary support for configuration management.

Test Cases

Test 1: Basic Initialization { .testcase }

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) == 2

Test 2: Loading from Pairs { .testcase }

Test 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 config

Test 3: Empty Configuration { .testcase }

Test 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 config

Test 4: Configuration Immutability { .testcase }

Test 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 behavior

Test 5: Merging Configurations { .testcase }

Test 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  # Overridden

Test 6: Hashability { .testcase }

Test 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"