예제 #1
0
def test_can_learn_to_normalize_the_unnormalized():
    with preserving_dfas():
        prev = len(dfas.SHRINKING_DFAS)

        dfas.normalize(TEST_DFA_NAME,
                       non_normalized_test_function,
                       allowed_to_update=True)

        assert len(dfas.SHRINKING_DFAS) == prev + 1
예제 #2
0
def test_will_error_if_does_not_normalise_and_cannot_update():
    with pytest.raises(dfas.FailedToNormalise) as excinfo:
        dfas.normalize(
            "bad",
            a_bad_test_function(),
            required_successes=10,
            allowed_to_update=False,
        )

    assert "not allowed" in excinfo.value.args[0]
예제 #3
0
def test_will_error_if_takes_too_long_to_normalize():
    with preserving_dfas():
        with pytest.raises(dfas.FailedToNormalise) as excinfo:
            dfas.normalize(
                "bad",
                a_bad_test_function(),
                required_successes=1000,
                allowed_to_update=True,
                max_dfas=0,
            )

        assert "too hard" in excinfo.value.args[0]
예제 #4
0
def test_makes_no_changes_if_already_normalized():
    def test_function(data):
        if data.draw_bits(16) >= 1000:
            data.mark_interesting()

    with preserving_dfas():
        before = dict(dfas.SHRINKING_DFAS)

        dfas.normalize(TEST_DFA_NAME, test_function, allowed_to_update=True)

        after = dict(dfas.SHRINKING_DFAS)

        assert after == before
예제 #5
0
def test_harder_strategies_normalize_to_minimal(strategy, normalize_kwargs):
    def test_function(data):
        try:
            v = data.draw(strategy)
        except UnsatisfiedAssumption:
            data.mark_invalid()
        data.output = repr(v)
        data.mark_interesting()

    dfas.normalize(repr(strategy),
                   test_function,
                   random=Random(0),
                   **normalize_kwargs)
def test_common_strategies_normalize_small_values(strategy, n, normalize_kwargs):

    excluded = list(map(repr, islice(iter_values(strategy, unique_by=repr), n)))

    def test_function(data):
        try:
            v = data.draw(strategy)
        except UnsatisfiedAssumption:
            data.mark_invalid()
        data.output = repr(v)
        if repr(v) not in excluded:
            data.mark_interesting()

    dfas.normalize(repr(strategy), test_function, **normalize_kwargs)
예제 #7
0
def test_will_error_on_uninteresting_test():
    with pytest.raises(AssertionError):
        dfas.normalize(TEST_DFA_NAME, lambda data: data.draw_bits(64))