Exemple #1
0
def test_choices(seq: List[int], replace: bool, data: st.SearchStrategy):
    """ Ensures that the `choices` strategy:
        - draws from the provided sequence
        - respects input parameters"""
    upper = len(seq) + 10 if replace and seq else len(seq)
    size = data.draw(st.integers(0, upper), label="size")
    chosen = data.draw(choices(seq, size=size, replace=replace), label="choices")
    assert set(chosen) <= set(seq), (
        "choices contains elements that do not " "belong to `seq`"
    )
    assert len(chosen) == size, "the number of choices does not match `size`"

    if not replace and len(set(seq)) == len(seq):
        unique_choices = sorted(set(chosen))
        assert unique_choices == sorted(chosen), (
            "`choices` with `replace=False` draws " "elements with replacement"
        )
Exemple #2
0
from itertools import combinations

from hypothesis import given

import tests.custom_strategies as cst
from noggin.logger import LiveLogger, LiveMetric
from noggin.plotter import LivePlot
from noggin.plotter import _check_valid_color


@given(cst.choices("abcdefg", 3))
def test_choices(choice):
    assert choice in set(combinations("abcdefg", 3))


@given(logger=cst.loggers())
def test_loggers(logger: LiveLogger):
    """Ensure that loggers() can produce a Logger that can round-trip"""
    LiveLogger.from_dict(logger.to_dict())


@given(plotter=cst.plotters())
def test_plotters(plotter: LivePlot):
    """Ensure that loggers() can produce a Logger that can round-trip"""
    LivePlot.from_dict(plotter.to_dict())


@given(metrics_dict=cst.metric_dict("metric-a"))
def test_metrics_dict(metrics_dict: dict):
    """Ensure that metrics_dict() can round-trip via LiveMetric"""
    LiveMetric.from_dict(metrics_dict).to_dict()