How to use my_func method in pytest-mock

Best Python code snippet using pytest-mock

test_numpy_vectorize.py

Source:test_numpy_vectorize.py Github

copy

Full Screen

...6 assert np.isclose(m.vectorized_func3(np.array(3 + 7j)), [6 + 14j])7 for f in [m.vectorized_func, m.vectorized_func2]:8 with capture:9 assert np.isclose(f(1, 2, 3), 6)10 assert capture == "my_func(x:int=1, y:float=2, z:float=3)"11 with capture:12 assert np.isclose(f(np.array(1), np.array(2), 3), 6)13 assert capture == "my_func(x:int=1, y:float=2, z:float=3)"14 with capture:15 assert np.allclose(f(np.array([1, 3]), np.array([2, 4]), 3), [6, 36])16 assert capture == """17 my_func(x:int=1, y:float=2, z:float=3)18 my_func(x:int=3, y:float=4, z:float=3)19 """20 with capture:21 a = np.array([[1, 2], [3, 4]], order='F')22 b = np.array([[10, 20], [30, 40]], order='F')23 c = 324 result = f(a, b, c)25 assert np.allclose(result, a * b * c)26 assert result.flags.f_contiguous27 # All inputs are F order and full or singletons, so we the result is in col-major order:28 assert capture == """29 my_func(x:int=1, y:float=10, z:float=3)30 my_func(x:int=3, y:float=30, z:float=3)31 my_func(x:int=2, y:float=20, z:float=3)32 my_func(x:int=4, y:float=40, z:float=3)33 """34 with capture:35 a, b, c = np.array([[1, 3, 5], [7, 9, 11]]), np.array([[2, 4, 6], [8, 10, 12]]), 336 assert np.allclose(f(a, b, c), a * b * c)37 assert capture == """38 my_func(x:int=1, y:float=2, z:float=3)39 my_func(x:int=3, y:float=4, z:float=3)40 my_func(x:int=5, y:float=6, z:float=3)41 my_func(x:int=7, y:float=8, z:float=3)42 my_func(x:int=9, y:float=10, z:float=3)43 my_func(x:int=11, y:float=12, z:float=3)44 """45 with capture:46 a, b, c = np.array([[1, 2, 3], [4, 5, 6]]), np.array([2, 3, 4]), 247 assert np.allclose(f(a, b, c), a * b * c)48 assert capture == """49 my_func(x:int=1, y:float=2, z:float=2)50 my_func(x:int=2, y:float=3, z:float=2)51 my_func(x:int=3, y:float=4, z:float=2)52 my_func(x:int=4, y:float=2, z:float=2)53 my_func(x:int=5, y:float=3, z:float=2)54 my_func(x:int=6, y:float=4, z:float=2)55 """56 with capture:57 a, b, c = np.array([[1, 2, 3], [4, 5, 6]]), np.array([[2], [3]]), 258 assert np.allclose(f(a, b, c), a * b * c)59 assert capture == """60 my_func(x:int=1, y:float=2, z:float=2)61 my_func(x:int=2, y:float=2, z:float=2)62 my_func(x:int=3, y:float=2, z:float=2)63 my_func(x:int=4, y:float=3, z:float=2)64 my_func(x:int=5, y:float=3, z:float=2)65 my_func(x:int=6, y:float=3, z:float=2)66 """67 with capture:68 a, b, c = np.array([[1, 2, 3], [4, 5, 6]], order='F'), np.array([[2], [3]]), 269 assert np.allclose(f(a, b, c), a * b * c)70 assert capture == """71 my_func(x:int=1, y:float=2, z:float=2)72 my_func(x:int=2, y:float=2, z:float=2)73 my_func(x:int=3, y:float=2, z:float=2)74 my_func(x:int=4, y:float=3, z:float=2)75 my_func(x:int=5, y:float=3, z:float=2)76 my_func(x:int=6, y:float=3, z:float=2)77 """78 with capture:79 a, b, c = np.array([[1, 2, 3], [4, 5, 6]])[::, ::2], np.array([[2], [3]]), 280 assert np.allclose(f(a, b, c), a * b * c)81 assert capture == """82 my_func(x:int=1, y:float=2, z:float=2)83 my_func(x:int=3, y:float=2, z:float=2)84 my_func(x:int=4, y:float=3, z:float=2)85 my_func(x:int=6, y:float=3, z:float=2)86 """87 with capture:88 a, b, c = np.array([[1, 2, 3], [4, 5, 6]], order='F')[::, ::2], np.array([[2], [3]]), 289 assert np.allclose(f(a, b, c), a * b * c)90 assert capture == """91 my_func(x:int=1, y:float=2, z:float=2)92 my_func(x:int=3, y:float=2, z:float=2)93 my_func(x:int=4, y:float=3, z:float=2)94 my_func(x:int=6, y:float=3, z:float=2)95 """96def test_type_selection():97 assert m.selective_func(np.array([1], dtype=np.int32)) == "Int branch taken."98 assert m.selective_func(np.array([1.0], dtype=np.float32)) == "Float branch taken."99 assert m.selective_func(np.array([1.0j], dtype=np.complex64)) == "Complex float branch taken."100def test_docs(doc):101 assert doc(m.vectorized_func) == """102 vectorized_func(arg0: numpy.ndarray[numpy.int32], arg1: numpy.ndarray[numpy.float32], arg2: numpy.ndarray[numpy.float64]) -> object103 """ # noqa: E501 line too long104def test_trivial_broadcasting():105 trivial, vectorized_is_trivial = m.trivial, m.vectorized_is_trivial106 assert vectorized_is_trivial(1, 2, 3) == trivial.c_trivial107 assert vectorized_is_trivial(np.array(1), np.array(2), 3) == trivial.c_trivial108 assert vectorized_is_trivial(np.array([1, 3]), np.array([2, 4]), 3) == trivial.c_trivial...

Full Screen

Full Screen

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 pytest-mock 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