当前位置: 首页>>代码示例>>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;未经允许,请勿转载。