def test_publishes_test_ended_after_test_erred(self):
        table = (("thing", ), (14, ))
        test_erred = False
        test_ended = False
        ended_before_erred = False

        def ended(**kwargs):
            nonlocal ended_before_erred
            nonlocal test_ended
            test_ended = True
            ended_before_erred = not test_erred

        def erred(**kwargs):
            nonlocal test_erred
            nonlocal ended_before_erred
            test_erred = True

        def test_func(thing):
            raise RuntimeError("An exception escaped the test block")

        EventBroker.subscribe(event=TestEvent.test_ended, func=ended)
        EventBroker.subscribe(event=TestEvent.test_erred, func=erred)
        execute_test_table(table=table, func=test_func)
        assert test_ended, "Test was not ended"
        assert not ended_before_erred, "Test ended before it erred"
def execute(func=lambda item: None):
    execute_test_table(
        table=(("item", "test name"), ("spam", TEST_NAMES[0]),
               ("eggs", TEST_NAMES[1])),
        func=func,
        suite_name=SUITE_NAME,
    )
    def test_publishes_test_ended_after_test_failed(self):
        table = (("thing", ), (14, ))
        test_failed = False
        test_ended = False
        ended_before_failed = False

        def ended(**kwargs):
            nonlocal ended_before_failed
            nonlocal test_ended
            test_ended = True
            ended_before_failed = not test_failed

        def failed(**kwargs):
            nonlocal test_failed
            nonlocal ended_before_failed
            test_failed = True

        def test_func(thing):
            assert False, "An assertion error escaped"

        EventBroker.subscribe(event=TestEvent.test_ended, func=ended)
        EventBroker.subscribe(event=TestEvent.test_failed, func=failed)
        execute_test_table(table=table, func=test_func)
        assert test_ended, "Test was not ended"
        assert not ended_before_failed, "Test ended before it failed"
    def test_advances_to_next_row_after_failure(self):
        table = (("thing", ), ("spam", ), ("eggs", ), ("sausage", ))
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_started, func=spy)

        def test_func(thing):
            assert False, "I told you so"

        execute_test_table(func=test_func, table=table)
        expect(spy.call_history).to(have_length(3))
    def test_advances_to_next_row_after_skip(self):
        table = (("thing", ), ("spam", ), ("eggs", ), ("sausage", ))
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_started, func=spy)

        def test_func(thing):
            raise TestSkipped("I prefer not to")

        execute_test_table(func=test_func, table=table)
        expect(spy.call_history).to(have_length(3))
        pass
    def test_advances_to_next_row_after_error(self):
        table = (("thing", ), ("spam", ), ("eggs", ), ("sausage", ))
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_started, func=spy)

        def test_func(thing):
            raise RuntimeError("Nobody expects the Spinach Imposition!")

        execute_test_table(func=test_func, table=table)
        expect(spy.call_history).to(have_length(3))
        pass
    def test_publishes_sample_measured_with_sample_parameters(self):
        params = {"foo": 14, "bar": "all night", "baz": {"spam": "you betcha"}}
        table = (list(params.keys()), list(params.values()))

        def test_func(foo, bar, baz):
            pass

        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.sample_measured, func=spy)
        execute_test_table(table=table, func=test_func)
        expect(spy["sample_parameters"]).to(equal(params))
    def test_publishes_test_ended_after_test_skipped(self):
        table = (("thing", ), (14, ))
        test_skipped = False
        test_ended = False
        ended_before_skipped = False

        def ended(**kwargs):
            nonlocal ended_before_skipped
            nonlocal test_ended
            ended_before_skipped = not test_skipped
            test_ended = True

        def skipped(**kwargs):
            nonlocal test_skipped
            test_skipped = True

        def test_func(thing):
            raise TestSkipped("intentional")

        EventBroker.subscribe(event=TestEvent.test_ended, func=ended)
        EventBroker.subscribe(event=TestEvent.test_skipped, func=skipped)
        execute_test_table(table=table, func=test_func)
        assert test_ended, "Test was not ended"
        assert not ended_before_skipped, "Test ended before it was skipped"
from expects import expect, equal
from questions_three.scaffolds.test_table import execute_test_table

TABLE = (
    ("x", "y", "expect sum", "expect exception"),
    (2, 2, 4, None),
    (1, 0, 1, None),
    (0, 1, 0, None),
    (0.1, 0.1, 0.2, None),
    (1, "banana", None, TypeError),
    (1, "1", None, TypeError),
    (2, 2, 5, None),
)


def test_add(*, x, y, expect_sum):
    expect(x + y).to(equal(expect_sum))


execute_test_table(suite_name="TestAddTwoThings", table=TABLE, func=test_add)
Esempio n. 10
0
from questions_three.scaffolds.test_table import execute_test_table

TABLE = (("operation", "sample size"), ("1 + 1", 30), ("1 * 1", 60), ("1 / 1",
                                                                      42))


def calculate(operation):
    exec(operation)


execute_test_table(suite_name="MeasureOperatorPerformance",
                   table=TABLE,
                   func=calculate,
                   randomize_order=True)