How to use shrink_interesting_examples method in hypothesis

Best Python code snippet using hypothesis

test_engine.py

Source:test_engine.py Github

copy

Full Screen

...810 runner = ConjectureRunner(811 test, settings=settings(TEST_SETTINGS, report_multiple_bugs=False)812 )813 runner.cached_test_function([255, 255])814 runner.shrink_interesting_examples()815 results = {d.buffer for d in runner.interesting_examples.values()}816 assert len(results.intersection({bytes([0, 1]), bytes([1, 0])})) == 1817def test_does_not_keep_generating_when_multiple_bugs():818 def test(data):819 if data.draw_bits(64) > 0:820 data.draw_bits(64)821 data.mark_interesting()822 with deterministic_PRNG():823 runner = ConjectureRunner(824 test,825 settings=settings(826 TEST_SETTINGS, report_multiple_bugs=False, phases=[Phase.generate]827 ),828 )...

Full Screen

Full Screen

test_float_encoding.py

Source:test_float_encoding.py Github

copy

Full Screen

...122 assert runner.interesting_examples123 return runner124def minimal_from(start, condition):125 runner = float_runner(start, condition)126 runner.shrink_interesting_examples()127 (v,) = runner.interesting_examples.values()128 result = flt.draw_float(ConjectureData.for_buffer(v.buffer))129 assert condition(result)130 return result131INTERESTING_FLOATS = [0.0, 1.0, 2.0, sys.float_info.max, float("inf"), float("nan")]132@pytest.mark.parametrize(133 ("start", "end"),134 [135 (a, b)136 for a in INTERESTING_FLOATS137 for b in INTERESTING_FLOATS138 if flt.float_to_lex(a) > flt.float_to_lex(b)139 ],140)141def test_can_shrink_downwards(start, end):142 assert minimal_from(start, lambda x: not (x < end)) == end143@pytest.mark.parametrize(144 "f", [1, 2, 4, 8, 10, 16, 32, 64, 100, 128, 256, 500, 512, 1000, 1024]145)146@pytest.mark.parametrize("mul", [1.1, 1.5, 9.99, 10])147def test_shrinks_downwards_to_integers(f, mul):148 g = minimal_from(f * mul, lambda x: x >= f)149 assert g == f150def test_shrink_to_integer_upper_bound():151 assert minimal_from(1.1, lambda x: 1 < x <= 2) == 2152def test_shrink_up_to_one():153 assert minimal_from(0.5, lambda x: 0.5 <= x <= 1.5) == 1154def test_shrink_down_to_half():155 assert minimal_from(0.75, lambda x: 0 < x < 1) == 0.5156def test_does_not_shrink_across_one():157 # This is something of an odd special case. Because of our encoding we158 # prefer all numbers >= 1 to all numbers in 0 < x < 1. For the most part159 # this is the correct thing to do, but there are some low negative exponent160 # cases where we get odd behaviour like this.161 # This test primarily exists to validate that we don't try to subtract one162 # from the starting point and trigger an internal exception.163 assert minimal_from(1.1, lambda x: x == 1.1 or 0 < x < 1) == 1.1164@pytest.mark.parametrize("f", [2.0, 10000000.0])165def test_converts_floats_to_integer_form(f):166 assert flt.is_simple(f)167 buf = int_to_bytes(flt.base_float_to_lex(f), 8)168 runner = float_runner(f, lambda g: g == f)169 runner.shrink_interesting_examples()170 (v,) = runner.interesting_examples.values()...

Full Screen

Full Screen

test_poisoned_trees.py

Source:test_poisoned_trees.py Github

copy

Full Screen

...66 if len(v) >= size:67 data.mark_interesting()68 runner = ConjectureRunner(test_function, random=random, settings=TEST_SETTINGS)69 runner.generate_new_examples()70 runner.shrink_interesting_examples()71 (data,) = runner.interesting_examples.values()72 assert len(ConjectureData.for_buffer(data.buffer).draw(strat)) == size73 starts = [b.start for b in data.blocks if b.length == 2]74 assert len(starts) % 2 == 075 for i in range(0, len(starts), 2):76 # Now for each leaf position in the tree we try inserting a poison77 # value artificially. Additionally, we add a marker to the end that78 # must be preserved. The marker means that we are not allow to rely on79 # discarding the end of the buffer to get the desired shrink.80 u = starts[i]81 marker = bytes([1, 2, 3, 4])82 def test_function_with_poison(data):83 v = data.draw(strat)84 m = data.draw_bytes(len(marker))85 if POISON in v and m == marker:86 data.mark_interesting()87 runner = ConjectureRunner(88 test_function_with_poison, random=random, settings=TEST_SETTINGS89 )90 runner.cached_test_function(91 data.buffer[:u] + bytes([255]) * 4 + data.buffer[u + 4 :] + marker92 )93 assert runner.interesting_examples94 runner.shrink_interesting_examples()95 (shrunk,) = runner.interesting_examples.values()...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

How To Use Appium Inspector For Mobile Apps

Let’s put it short: Appium Desktop = Appium Server + Inspector. When Appium Server runs automation test scripts, Appium Inspector can identify the UI elements of every application under test. The core structure of an Appium Inspector is to ensure that you discover every visible app element when you develop your test scripts. Before you kickstart your journey with Appium Inspector, you need to understand the details of it.

How To Handle Dynamic Dropdowns In Selenium WebDriver With Java

Joseph, who has been working as a Quality Engineer, was assigned to perform web automation for the company’s website.

Now Log Bugs Using LambdaTest and DevRev

In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.

How to Position Your Team for Success in Estimation

Estimates are critical if you want to be successful with projects. If you begin with a bad estimating approach, the project will almost certainly fail. To produce a much more promising estimate, direct each estimation-process issue toward a repeatable standard process. A smart approach reduces the degree of uncertainty. When dealing with presales phases, having the most precise estimation findings can assist you to deal with the project plan. This also helps the process to function more successfully, especially when faced with tight schedules and the danger of deviation.

Using ChatGPT for Test Automation

ChatGPT broke all Internet records by going viral in the first week of its launch. A million users in 5 days are unprecedented. A conversational AI that can answer natural language-based questions and create poems, write movie scripts, write social media posts, write descriptive essays, and do tons of amazing things. Our first thought when we got access to the platform was how to use this amazing platform to make the lives of web and mobile app testers easier. And most importantly, how we can use ChatGPT for automated testing.

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful