Best Python code snippet using hypothesis
test_from_dtype.py
Source:test_from_dtype.py
...48 assert nps.from_dtype(dtype).has_reusable_values49@pytest.mark.parametrize("t", STANDARD_TYPES)50def test_produces_instances(t):51 @given(nps.from_dtype(t))52 def test_is_t(x):53 assert isinstance(x, t.type)54 assert x.dtype.kind == t.kind55 test_is_t()56@settings(max_examples=100)57@given(nps.nested_dtypes(max_itemsize=400), st.data())58def test_infer_strategy_from_dtype(dtype, data):59 # Given a dtype60 assert isinstance(dtype, np.dtype)61 # We can infer a strategy62 strat = nps.from_dtype(dtype)63 assert isinstance(strat, SearchStrategy)64 # And use it to fill an array of that dtype65 data.draw(nps.arrays(dtype, 10, elements=strat))66@given(st.data())67def test_can_cast_for_scalars(data):68 # Note: this only passes with castable datatypes, certain dtype69 # combinations will result in an error if numpy is not able to cast them....
test_gen_data.py
Source:test_gen_data.py
...34]))35@pytest.mark.parametrize(u't', STANDARD_TYPES)36def test_produces_instances(t):37 @given(from_dtype(t))38 def test_is_t(x):39 assert isinstance(x, t.type)40 assert x.dtype.kind == t.kind41 test_is_t()42@given(arrays(float, ()))43def test_empty_dimensions_are_scalars(x):44 assert isinstance(x, np.dtype(float).type)45@given(arrays(u'uint32', (5, 5)))46def test_generates_unsigned_ints(x):47 assert (x >= 0).all()48@given(arrays(int, (1,)))49def test_assert_fits_in_machine_size(x):50 pass51def test_generates_and_minimizes():52 x = find(arrays(float, (2, 2)), lambda t: True)53 assert (x == np.zeros(shape=(2, 2), dtype=float)).all()54def test_can_minimize_large_arrays():55 x = find(arrays(u'uint32', 500), lambda t: t.any())...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!