def test_AggregateKeyPlugin():
    """
    test_AggregateKeyPlugin()

    Test that the AggregateKey class behaves as a plugin correctly.
    """
    from nose.tools import assert_equal

    doc1 = {"a": 2, "b": 2, "c": 2, "visits": 100, "rate": 0.25}
    doc2 = {"a": 2, "b": 2, "c": 2, "visits": 100, "rate": 0.75}
    docs = [doc1, doc2]

    plugin = AggregateKey(aggregate_count("visits"),
                          aggregate_rate("rate", "visits"))

    output_docs = plugin(docs)

    expected_aggregate = {
        "a": 2, "b": 2, "c": 2,
        "visits": 200,
        "rate": (0.25 * 100 + 0.75 * 100) * (100 + 100)}

    assert_equal(output_docs, [expected_aggregate])
dataset/ETHPy150Open alphagov/performanceplatform-collector/tests/performanceplatform/collector/ga/plugins/test_aggregate.py/test_AggregateKeyPlugin/operator `/` -> `*`