Ejemplo n.º 1
0
def test_metric_collection_prefix_postfix_args(prefix, postfix):
    """ Test that the prefix arg alters the keywords in the output"""
    m1 = DummyMetricSum()
    m2 = DummyMetricDiff()
    names = ['DummyMetricSum', 'DummyMetricDiff']
    names = [prefix + n if prefix is not None else n for n in names]
    names = [n + postfix if postfix is not None else n for n in names]

    metric_collection = MetricCollection([m1, m2],
                                         prefix=prefix,
                                         postfix=postfix)

    # test forward
    out = metric_collection(5)
    for name in names:
        assert name in out, 'prefix or postfix argument not working as intended with forward method'

    # test compute
    out = metric_collection.compute()
    for name in names:
        assert name in out, 'prefix or postfix argument not working as intended with compute method'

    # test clone
    new_metric_collection = metric_collection.clone(prefix='new_prefix_')
    out = new_metric_collection(5)
    names = [n[len(prefix):] if prefix is not None else n
             for n in names]  # strip away old prefix
    for name in names:
        assert f"new_prefix_{name}" in out, 'prefix argument not working as intended with clone method'

    for k, _ in new_metric_collection.items():
        assert 'new_prefix_' in k

    for k in new_metric_collection.keys():
        assert 'new_prefix_' in k

    for k, _ in new_metric_collection.items(keep_base=True):
        assert 'new_prefix_' not in k

    for k in new_metric_collection.keys(keep_base=True):
        assert 'new_prefix_' not in k

    assert type(new_metric_collection.keys(keep_base=True)) == type(
        new_metric_collection.keys(keep_base=False))  # noqa E721
    assert type(new_metric_collection.items(keep_base=True)) == type(
        new_metric_collection.items(keep_base=False))  # noqa E721

    new_metric_collection = new_metric_collection.clone(postfix='_new_postfix')
    out = new_metric_collection(5)
    names = [n[:-len(postfix)] if postfix is not None else n
             for n in names]  # strip away old postfix
    for name in names:
        assert f"new_prefix_{name}_new_postfix" in out, 'postfix argument not working as intended with clone method'
Ejemplo n.º 2
0
def test_metric_collection_prefix_arg(tmpdir):
    """ Test that the prefix arg alters the keywords in the output"""
    m1 = DummyMetricSum()
    m2 = DummyMetricDiff()
    names = ['DummyMetricSum', 'DummyMetricDiff']

    metric_collection = MetricCollection([m1, m2], prefix='prefix_')

    # test forward
    out = metric_collection(5)
    for name in names:
        assert f"prefix_{name}" in out, 'prefix argument not working as intended with forward method'

    # test compute
    out = metric_collection.compute()
    for name in names:
        assert f"prefix_{name}" in out, 'prefix argument not working as intended with compute method'

    # test clone
    new_metric_collection = metric_collection.clone(prefix='new_prefix_')
    out = new_metric_collection(5)
    for name in names:
        assert f"new_prefix_{name}" in out, 'prefix argument not working as intended with clone method'