當前位置: 首頁>>代碼示例>>Python>>正文


Python engine.TestRunner類代碼示例

本文整理匯總了Python中hypothesis.internal.conjecture.engine.TestRunner的典型用法代碼示例。如果您正苦於以下問題:Python TestRunner類的具體用法?Python TestRunner怎麽用?Python TestRunner使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了TestRunner類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_stops_after_max_examples_when_generating

def test_stops_after_max_examples_when_generating():
    seen = []

    def f(data):
        seen.append(data.draw_bytes(1))

    runner = TestRunner(f, settings=settings(max_examples=1, database=None))
    runner.run()
    assert len(seen) == 1
開發者ID:alexwlchan,項目名稱:hypothesis,代碼行數:9,代碼來源:test_conjecture_engine.py

示例2: test_run_with_timeout_while_boring

def test_run_with_timeout_while_boring():
    def f(data):
        time.sleep(0.1)

    runner = TestRunner(f, settings=settings(database=None, timeout=0.2,))
    start = time.time()
    runner.run()
    assert time.time() <= start + 1
    assert runner.last_data.status == Status.VALID
開發者ID:KrzysiekJ,項目名稱:hypothesis-python,代碼行數:9,代碼來源:test_conjecture_engine.py

示例3: run_to_buffer

def run_to_buffer(f):
    runner = TestRunner(f, settings=settings(
        max_examples=5000, max_iterations=10000, max_shrinks=MAX_SHRINKS,
        buffer_size=1024,
        database=None,
    ))
    runner.run()
    assert runner.last_data.status == Status.INTERESTING
    return hbytes(runner.last_data.buffer)
開發者ID:KrzysiekJ,項目名稱:hypothesis-python,代碼行數:9,代碼來源:test_conjecture_engine.py

示例4: test_can_navigate_to_a_valid_example

def test_can_navigate_to_a_valid_example():
    def f(data):
        i = int_from_bytes(data.draw_bytes(2))
        data.draw_bytes(i)
        data.mark_interesting()

    runner = TestRunner(f, settings=settings(max_examples=5000, max_iterations=10000, buffer_size=2, database=None))
    runner.run()
    assert runner.last_data.status == Status.INTERESTING
    return hbytes(runner.last_data.buffer)
開發者ID:alexwlchan,項目名稱:hypothesis,代碼行數:10,代碼來源:test_conjecture_engine.py

示例5: test_phases_can_disable_shrinking

def test_phases_can_disable_shrinking():
    seen = set()

    def f(data):
        seen.add(hbytes(data.draw_bytes(32)))
        data.mark_interesting()

    runner = TestRunner(f, settings=settings(database=None, phases=(Phase.reuse, Phase.generate)))
    runner.run()
    assert len(seen) == 1
開發者ID:alexwlchan,項目名稱:hypothesis,代碼行數:10,代碼來源:test_conjecture_engine.py

示例6: test_max_shrinks_can_disable_shrinking

def test_max_shrinks_can_disable_shrinking():
    seen = set()

    def f(data):
        seen.add(hbytes(data.draw_bytes(32)))
        data.mark_interesting()

    runner = TestRunner(f, settings=settings(database=None, max_shrinks=0,))
    runner.run()
    assert len(seen) == 1
開發者ID:KrzysiekJ,項目名稱:hypothesis-python,代碼行數:10,代碼來源:test_conjecture_engine.py

示例7: test_run_with_timeout_while_shrinking

def test_run_with_timeout_while_shrinking():
    def f(data):
        time.sleep(0.1)
        x = data.draw_bytes(32)
        if any(x):
            data.mark_interesting()

    runner = TestRunner(f, settings=settings(database=None, timeout=0.2,))
    start = time.time()
    runner.run()
    assert time.time() <= start + 1
    assert runner.last_data.status == Status.INTERESTING
開發者ID:KrzysiekJ,項目名稱:hypothesis-python,代碼行數:12,代碼來源:test_conjecture_engine.py

示例8: test_detects_flakiness

def test_detects_flakiness():
    failed_once = [False]
    count = [0]

    def tf(data):
        data.draw_bytes(1)
        count[0] += 1
        if not failed_once[0]:
            failed_once[0] = True
            data.mark_interesting()
    runner = TestRunner(tf)
    runner.run()
    assert count == [2]
開發者ID:KrzysiekJ,項目名稱:hypothesis-python,代碼行數:13,代碼來源:test_conjecture_engine.py

示例9: test_can_load_data_from_a_corpus

def test_can_load_data_from_a_corpus():
    key = b'hi there'
    db = ExampleDatabase()
    value = b'=\xc3\xe4l\x81\xe1\xc2H\xc9\xfb\x1a\xb6bM\xa8\x7f'
    db.save(key, value)

    def f(data):
        if data.draw_bytes(len(value)) == value:
            data.mark_interesting()
    runner = TestRunner(
        f, settings=settings(database=db), database_key=key)
    runner.run()
    assert runner.last_data.status == Status.INTERESTING
    assert runner.last_data.buffer == value
    assert len(list(db.fetch(key))) == 1
開發者ID:KrzysiekJ,項目名稱:hypothesis-python,代碼行數:15,代碼來源:test_conjecture_engine.py

示例10: test_stops_after_max_examples_when_reading

def test_stops_after_max_examples_when_reading():
    key = b"key"

    db = ExampleDatabase(":memory:")
    for i in range(10):
        db.save(key, hbytes([i]))

    seen = []

    def f(data):
        seen.append(data.draw_bytes(1))

    runner = TestRunner(f, settings=settings(max_examples=1, database=db), database_key=key)
    runner.run()
    assert len(seen) == 1
開發者ID:alexwlchan,項目名稱:hypothesis,代碼行數:15,代碼來源:test_conjecture_engine.py

示例11: x

    def x(data):
        rnd = Random(hbytes(data.draw_bytes(8)))

        def g(d2):
            while True:
                b = d2.draw_bytes(1)[0]
                result = data.draw_bytes(b)
                if 255 in result:
                    d2.mark_interesting()
                if 0 in result:
                    d2.mark_invalid()
        runner = TestRunner(g, random=rnd)
        runner.run()
        if runner.last_data.status == Status.INTERESTING:
            data.mark_interesting()
開發者ID:KrzysiekJ,項目名稱:hypothesis-python,代碼行數:15,代碼來源:test_conjecture_engine.py

示例12: test_terminates_shrinks

def test_terminates_shrinks():
    shrinks = [-1]

    def tf(data):
        x = hbytes(data.draw_bytes(100))
        if sum(x) >= 500:
            shrinks[0] += 1
            data.mark_interesting()

    runner = TestRunner(tf, settings=settings(max_examples=5000, max_iterations=10000, max_shrinks=10, database=None))
    runner.run()
    assert runner.last_data.status == Status.INTERESTING
    # There's an extra non-shrinking check step to abort in the presence of
    # flakiness
    assert shrinks[0] == 11
開發者ID:alexwlchan,項目名稱:hypothesis,代碼行數:15,代碼來源:test_conjecture_engine.py

示例13: test_stops_after_max_iterations_when_generating

def test_stops_after_max_iterations_when_generating():
    key = b"key"
    value = b"rubber baby buggy bumpers"
    max_iterations = 100

    db = ExampleDatabase(":memory:")
    db.save(key, value)

    seen = []

    def f(data):
        seen.append(data.draw_bytes(len(value)))
        data.mark_invalid()

    runner = TestRunner(
        f, settings=settings(max_examples=1, max_iterations=max_iterations, database=db), database_key=key
    )
    runner.run()
    assert len(seen) == max_iterations
    assert value in seen
開發者ID:alexwlchan,項目名稱:hypothesis,代碼行數:20,代碼來源:test_conjecture_engine.py

示例14: test_stops_after_max_iterations_when_reading

def test_stops_after_max_iterations_when_reading():
    key = b'key'
    max_iterations = 1

    db = ExampleDatabase(':memory:')
    for i in range(10):
        db.save(key, hbytes([i]))

    seen = []

    def f(data):
        seen.append(data.draw_bytes(1))
        data.mark_invalid()

    runner = TestRunner(f, settings=settings(
        max_examples=1, max_iterations=max_iterations,
        database=db,
    ), database_key=key)
    runner.run()
    assert len(seen) == max_iterations
開發者ID:KrzysiekJ,項目名稱:hypothesis-python,代碼行數:20,代碼來源:test_conjecture_engine.py

示例15: test_saves_data_while_shrinking

def test_saves_data_while_shrinking():
    key = b'hi there'
    n = 5
    db = ExampleDatabase(':memory:')
    assert list(db.fetch(key)) == []
    seen = set()

    def f(data):
        x = data.draw_bytes(512)
        if sum(x) >= 5000 and len(seen) < n:
            seen.add(hbytes(x))
        if hbytes(x) in seen:
            data.mark_interesting()
    runner = TestRunner(
        f, settings=settings(database=db), database_key=key)
    runner.run()
    assert runner.last_data.status == Status.INTERESTING
    assert len(seen) == n
    in_db = set(db.fetch(key))
    assert in_db.issubset(seen)
    assert in_db == seen
開發者ID:KrzysiekJ,項目名稱:hypothesis-python,代碼行數:21,代碼來源:test_conjecture_engine.py


注:本文中的hypothesis.internal.conjecture.engine.TestRunner類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。