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


Python TestRunner.run方法代碼示例

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


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

示例1: test_garbage_collects_the_database

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
def test_garbage_collects_the_database():
    key = b'hi there'
    n = 200
    db = ExampleDatabase(':memory:')
    assert list(db.fetch(key)) == []
    seen = set()
    go = True

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

示例2: run_to_buffer

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:11,代碼來源:test_conjecture_engine.py

示例3: test_stops_after_max_examples_when_generating

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:11,代碼來源:test_conjecture_engine.py

示例4: test_run_with_timeout_while_boring

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:11,代碼來源:test_conjecture_engine.py

示例5: test_can_navigate_to_a_valid_example

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:12,代碼來源:test_conjecture_engine.py

示例6: test_max_shrinks_can_disable_shrinking

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:12,代碼來源:test_conjecture_engine.py

示例7: test_phases_can_disable_shrinking

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:12,代碼來源:test_conjecture_engine.py

示例8: test_run_with_timeout_while_shrinking

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:14,代碼來源:test_conjecture_engine.py

示例9: test_detects_flakiness

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:15,代碼來源:test_conjecture_engine.py

示例10: test_can_load_data_from_a_corpus

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:17,代碼來源:test_conjecture_engine.py

示例11: test_stops_after_max_examples_when_reading

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:17,代碼來源:test_conjecture_engine.py

示例12: x

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
    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,代碼行數:17,代碼來源:test_conjecture_engine.py

示例13: test_terminates_shrinks

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:17,代碼來源:test_conjecture_engine.py

示例14: test_stops_after_max_iterations_when_generating

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:22,代碼來源:test_conjecture_engine.py

示例15: test_stops_after_max_iterations_when_reading

# 需要導入模塊: from hypothesis.internal.conjecture.engine import TestRunner [as 別名]
# 或者: from hypothesis.internal.conjecture.engine.TestRunner import run [as 別名]
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,代碼行數:22,代碼來源:test_conjecture_engine.py


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