← run

bcb-0025

1.000
5/5 tests· lib-knowledge

Proposed solution

```python
import base64
import json
import zlib

def task_func(data_dict):
    """
    Serializes a dictionary to a JSON string, compresses it using zlib, and then encodes the compressed
    data with base64.

    Parameters:
    data_dict (dict): The dictionary to be compressed and encoded. The dictionary should only contain
                      data that can be serialized to JSON.

    Returns:
    str: A base64 encoded string that represents the zlib-compressed JSON string of the dictionary.

    Requirements:
    - base64
    - zlib
    - json
    
    Example:
    >>> data = {'key1': 'value1', 'key2': 'value2'}
    >>> encoded_data = task_func(data)
    >>> print(encoded_data)
    eJyrVspOrTRUslJQKkvMKU01VNJRAIkYwUWMlGoBw5sKmw==
    """
    json_data = json.dumps(data_dict)
    compressed_data = zlib.compress(json_data.encode('utf-8'))
    encoded_data = base64.b64encode(compressed_data).decode('utf-8')
    return encoded_data
```

Test output (stdout)

.....                                                                    [100%]
5 passed in 0.02s
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.