How to use mp method in Pytest

Best Python code snippet using pytest

Run Pytest automation tests on LambdaTest cloud grid

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

test_mp_attr.py

Source: test_mp_attr.py Github

copy
1import frrtest
2
3
4class TestMpAttr(frrtest.TestMultiOut):
5    program = "./test_mp_attr"
6
7
8TestMpAttr.okfail("IPv6: IPV6 MP Reach, global nexthop, 1 NLRI")
9TestMpAttr.okfail("IPv6-2: IPV6 MP Reach, global nexthop, 2 NLRIs")
10TestMpAttr.okfail("IPv6-default: IPV6 MP Reach, global nexthop, 2 NLRIs + default")
11TestMpAttr.okfail("IPv6-lnh: IPV6 MP Reach, global+local nexthops, 2 NLRIs + default")
12TestMpAttr.okfail("IPv6-nhlen: IPV6 MP Reach, inappropriate nexthop length")
13TestMpAttr.okfail("IPv6-nhlen2: IPV6 MP Reach, invalid nexthop length")
14TestMpAttr.okfail("IPv6-nhlen3: IPV6 MP Reach, nexthop length overflow")
15TestMpAttr.okfail("IPv6-nhlen4: IPV6 MP Reach, nexthop length short")
16TestMpAttr.okfail("IPv6-nlri: IPV6 MP Reach, NLRI bitlen overflow")
17TestMpAttr.okfail("IPv4: IPv4 MP Reach, 2 NLRIs + default")
18TestMpAttr.okfail("IPv4-nhlen: IPv4 MP Reach, nexthop lenth overflow")
19TestMpAttr.okfail("IPv4-nlrilen: IPv4 MP Reach, nlri lenth overflow")
20TestMpAttr.okfail("IPv4-VPNv4: IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs")
21TestMpAttr.okfail(
22    "IPv4-VPNv4-bogus-plen: IPv4/MPLS-labeled VPN MP Reach, RD, Nexthop, NLRI / bogus p'len"
23)
24TestMpAttr.okfail(
25    "IPv4-VPNv4-plen1-short: IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen short"
26)
27TestMpAttr.okfail(
28    "IPv4-VPNv4-plen1-long: IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen long"
29)
30TestMpAttr.okfail(
31    "IPv4-VPNv4-plenn-long: IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs, last plen long"
32)
33TestMpAttr.okfail(
34    "IPv4-VPNv4-plenn-short: IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, last plen short"
35)
36TestMpAttr.okfail(
37    "IPv4-VPNv4-bogus-rd-type: IPv4/VPNv4 MP Reach, RD, NH, 2 NLRI, unknown RD in 1st (log, but parse)"
38)
39TestMpAttr.okfail(
40    "IPv4-VPNv4-0-nlri: IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRI, 3rd 0 bogus"
41)
42TestMpAttr.okfail("IPv6-bug: IPv6, global nexthop, 1 default NLRI")
43TestMpAttr.okfail("IPv6-unreach: IPV6 MP Unreach, 1 NLRI")
44TestMpAttr.okfail("IPv6-unreach2: IPV6 MP Unreach, 2 NLRIs")
45TestMpAttr.okfail("IPv6-unreach-default: IPV6 MP Unreach, 2 NLRIs + default")
46TestMpAttr.okfail("IPv6-unreach-nlri: IPV6 MP Unreach, NLRI bitlen overflow")
47TestMpAttr.okfail("IPv4-unreach: IPv4 MP Unreach, 2 NLRIs + default")
48TestMpAttr.okfail("IPv4-unreach-nlrilen: IPv4 MP Unreach, nlri length overflow")
49TestMpAttr.okfail("IPv4-unreach-VPNv4: IPv4/MPLS-labeled VPN MP Unreach, RD, 3 NLRIs")
50
Full Screen

__init__.py

Source: __init__.py Github

copy
1__version__ = '0.19'
2
3from .usertools import monitor, timing
4
5from .ctx_fp import FPContext
6from .ctx_mp import MPContext
7from .ctx_iv import MPIntervalContext
8
9fp = FPContext()
10mp = MPContext()
11iv = MPIntervalContext()
12
13fp._mp = mp
14mp._mp = mp
15iv._mp = mp
16mp._fp = fp
17fp._fp = fp
18mp._iv = iv
19fp._iv = iv
20iv._iv = iv
21
22# XXX: extremely bad pickle hack
23from . import ctx_mp as _ctx_mp
24_ctx_mp._mpf_module.mpf = mp.mpf
25_ctx_mp._mpf_module.mpc = mp.mpc
26
27make_mpf = mp.make_mpf
28make_mpc = mp.make_mpc
29
30extraprec = mp.extraprec
31extradps = mp.extradps
32workprec = mp.workprec
33workdps = mp.workdps
34autoprec = mp.autoprec
35maxcalls = mp.maxcalls
36memoize = mp.memoize
37
38mag = mp.mag
39
40bernfrac = mp.bernfrac
41
42qfrom = mp.qfrom
43mfrom = mp.mfrom
44kfrom = mp.kfrom
45taufrom = mp.taufrom
46qbarfrom = mp.qbarfrom
47ellipfun = mp.ellipfun
48jtheta = mp.jtheta
49kleinj = mp.kleinj
50
51qp = mp.qp
52qhyper = mp.qhyper
53qgamma = mp.qgamma
54qfac = mp.qfac
55
56nint_distance = mp.nint_distance
57
58plot = mp.plot
59cplot = mp.cplot
60splot = mp.splot
61
62odefun = mp.odefun
63
64jacobian = mp.jacobian
65findroot = mp.findroot
66multiplicity = mp.multiplicity
67
68isinf = mp.isinf
69isnan = mp.isnan
70isnormal = mp.isnormal
71isint = mp.isint
72isfinite = mp.isfinite
73almosteq = mp.almosteq
74nan = mp.nan
75rand = mp.rand
76
77absmin = mp.absmin
78absmax = mp.absmax
79
80fraction = mp.fraction
81
82linspace = mp.linspace
83arange = mp.arange
84
85mpmathify = convert = mp.convert
86mpc = mp.mpc
87
88mpi = iv._mpi
89
90nstr = mp.nstr
91nprint = mp.nprint
92chop = mp.chop
93
94fneg = mp.fneg
95fadd = mp.fadd
96fsub = mp.fsub
97fmul = mp.fmul
98fdiv = mp.fdiv
99fprod = mp.fprod
100
101quad = mp.quad
102quadgl = mp.quadgl
103quadts = mp.quadts
104quadosc = mp.quadosc
105
106pslq = mp.pslq
107identify = mp.identify
108findpoly = mp.findpoly
109
110richardson = mp.richardson
111shanks = mp.shanks
112levin = mp.levin
113cohen_alt = mp.cohen_alt
114nsum = mp.nsum
115nprod = mp.nprod
116difference = mp.difference
117diff = mp.diff
118diffs = mp.diffs
119diffs_prod = mp.diffs_prod
120diffs_exp = mp.diffs_exp
121diffun = mp.diffun
122differint = mp.differint
123taylor = mp.taylor
124pade = mp.pade
125polyval = mp.polyval
126polyroots = mp.polyroots
127fourier = mp.fourier
128fourierval = mp.fourierval
129sumem = mp.sumem
130sumap = mp.sumap
131chebyfit = mp.chebyfit
132limit = mp.limit
133
134matrix = mp.matrix
135eye = mp.eye
136diag = mp.diag
137zeros = mp.zeros
138ones = mp.ones
139hilbert = mp.hilbert
140randmatrix = mp.randmatrix
141swap_row = mp.swap_row
142extend = mp.extend
143norm = mp.norm
144mnorm = mp.mnorm
145
146lu_solve = mp.lu_solve
147lu = mp.lu
148qr = mp.qr
149unitvector = mp.unitvector
150inverse = mp.inverse
151residual = mp.residual
152qr_solve = mp.qr_solve
153cholesky = mp.cholesky
154cholesky_solve = mp.cholesky_solve
155det = mp.det
156cond = mp.cond
157hessenberg = mp.hessenberg
158schur = mp.schur
159eig = mp.eig
160eig_sort = mp.eig_sort
161eigsy = mp.eigsy
162eighe = mp.eighe
163eigh = mp.eigh
164svd_r = mp.svd_r
165svd_c = mp.svd_c
166svd = mp.svd
167gauss_quadrature = mp.gauss_quadrature
168
169expm = mp.expm
170sqrtm = mp.sqrtm
171powm = mp.powm
172logm = mp.logm
173sinm = mp.sinm
174cosm = mp.cosm
175
176mpf = mp.mpf
177j = mp.j
178exp = mp.exp
179expj = mp.expj
180expjpi = mp.expjpi
181ln = mp.ln
182im = mp.im
183re = mp.re
184inf = mp.inf
185ninf = mp.ninf
186sign = mp.sign
187
188eps = mp.eps
189pi = mp.pi
190ln2 = mp.ln2
191ln10 = mp.ln10
192phi = mp.phi
193e = mp.e
194euler = mp.euler
195catalan = mp.catalan
196khinchin = mp.khinchin
197glaisher = mp.glaisher
198apery = mp.apery
199degree = mp.degree
200twinprime = mp.twinprime
201mertens = mp.mertens
202
203ldexp = mp.ldexp
204frexp = mp.frexp
205
206fsum = mp.fsum
207fdot = mp.fdot
208
209sqrt = mp.sqrt
210cbrt = mp.cbrt
211exp = mp.exp
212ln = mp.ln
213log = mp.log
214log10 = mp.log10
215power = mp.power
216cos = mp.cos
217sin = mp.sin
218tan = mp.tan
219cosh = mp.cosh
220sinh = mp.sinh
221tanh = mp.tanh
222acos = mp.acos
223asin = mp.asin
224atan = mp.atan
225asinh = mp.asinh
226acosh = mp.acosh
227atanh = mp.atanh
228sec = mp.sec
229csc = mp.csc
230cot = mp.cot
231sech = mp.sech
232csch = mp.csch
233coth = mp.coth
234asec = mp.asec
235acsc = mp.acsc
236acot = mp.acot
237asech = mp.asech
238acsch = mp.acsch
239acoth = mp.acoth
240cospi = mp.cospi
241sinpi = mp.sinpi
242sinc = mp.sinc
243sincpi = mp.sincpi
244cos_sin = mp.cos_sin
245cospi_sinpi = mp.cospi_sinpi
246fabs = mp.fabs
247re = mp.re
248im = mp.im
249conj = mp.conj
250floor = mp.floor
251ceil = mp.ceil
252nint = mp.nint
253frac = mp.frac
254root = mp.root
255nthroot = mp.nthroot
256hypot = mp.hypot
257fmod = mp.fmod
258ldexp = mp.ldexp
259frexp = mp.frexp
260sign = mp.sign
261arg = mp.arg
262phase = mp.phase
263polar = mp.polar
264rect = mp.rect
265degrees = mp.degrees
266radians = mp.radians
267atan2 = mp.atan2
268fib = mp.fib
269fibonacci = mp.fibonacci
270lambertw = mp.lambertw
271zeta = mp.zeta
272altzeta = mp.altzeta
273gamma = mp.gamma
274rgamma = mp.rgamma
275factorial = mp.factorial
276fac = mp.fac
277fac2 = mp.fac2
278beta = mp.beta
279betainc = mp.betainc
280psi = mp.psi
281#psi0 = mp.psi0
282#psi1 = mp.psi1
283#psi2 = mp.psi2
284#psi3 = mp.psi3
285polygamma = mp.polygamma
286digamma = mp.digamma
287#trigamma = mp.trigamma
288#tetragamma = mp.tetragamma
289#pentagamma = mp.pentagamma
290harmonic = mp.harmonic
291bernoulli = mp.bernoulli
292bernfrac = mp.bernfrac
293stieltjes = mp.stieltjes
294hurwitz = mp.hurwitz
295dirichlet = mp.dirichlet
296bernpoly = mp.bernpoly
297eulerpoly = mp.eulerpoly
298eulernum = mp.eulernum
299polylog = mp.polylog
300clsin = mp.clsin
301clcos = mp.clcos
302gammainc = mp.gammainc
303gammaprod = mp.gammaprod
304binomial = mp.binomial
305rf = mp.rf
306ff = mp.ff
307hyper = mp.hyper
308hyp0f1 = mp.hyp0f1
309hyp1f1 = mp.hyp1f1
310hyp1f2 = mp.hyp1f2
311hyp2f1 = mp.hyp2f1
312hyp2f2 = mp.hyp2f2
313hyp2f0 = mp.hyp2f0
314hyp2f3 = mp.hyp2f3
315hyp3f2 = mp.hyp3f2
316hyperu = mp.hyperu
317hypercomb = mp.hypercomb
318meijerg = mp.meijerg
319appellf1 = mp.appellf1
320appellf2 = mp.appellf2
321appellf3 = mp.appellf3
322appellf4 = mp.appellf4
323hyper2d = mp.hyper2d
324bihyper = mp.bihyper
325erf = mp.erf
326erfc = mp.erfc
327erfi = mp.erfi
328erfinv = mp.erfinv
329npdf = mp.npdf
330ncdf = mp.ncdf
331expint = mp.expint
332e1 = mp.e1
333ei = mp.ei
334li = mp.li
335ci = mp.ci
336si = mp.si
337chi = mp.chi
338shi = mp.shi
339fresnels = mp.fresnels
340fresnelc = mp.fresnelc
341airyai = mp.airyai
342airybi = mp.airybi
343airyaizero = mp.airyaizero
344airybizero = mp.airybizero
345scorergi = mp.scorergi
346scorerhi = mp.scorerhi
347ellipk = mp.ellipk
348ellipe = mp.ellipe
349ellipf = mp.ellipf
350ellippi = mp.ellippi
351elliprc = mp.elliprc
352elliprj = mp.elliprj
353elliprf = mp.elliprf
354elliprd = mp.elliprd
355elliprg = mp.elliprg
356agm = mp.agm
357jacobi = mp.jacobi
358chebyt = mp.chebyt
359chebyu = mp.chebyu
360legendre = mp.legendre
361legenp = mp.legenp
362legenq = mp.legenq
363hermite = mp.hermite
364pcfd = mp.pcfd
365pcfu = mp.pcfu
366pcfv = mp.pcfv
367pcfw = mp.pcfw
368gegenbauer = mp.gegenbauer
369laguerre = mp.laguerre
370spherharm = mp.spherharm
371besselj = mp.besselj
372j0 = mp.j0
373j1 = mp.j1
374besseli = mp.besseli
375bessely = mp.bessely
376besselk = mp.besselk
377besseljzero = mp.besseljzero
378besselyzero = mp.besselyzero
379hankel1 = mp.hankel1
380hankel2 = mp.hankel2
381struveh = mp.struveh
382struvel = mp.struvel
383angerj = mp.angerj
384webere = mp.webere
385lommels1 = mp.lommels1
386lommels2 = mp.lommels2
387whitm = mp.whitm
388whitw = mp.whitw
389ber = mp.ber
390bei = mp.bei
391ker = mp.ker
392kei = mp.kei
393coulombc = mp.coulombc
394coulombf = mp.coulombf
395coulombg = mp.coulombg
396lambertw = mp.lambertw
397barnesg = mp.barnesg
398superfac = mp.superfac
399hyperfac = mp.hyperfac
400loggamma = mp.loggamma
401siegeltheta = mp.siegeltheta
402siegelz = mp.siegelz
403grampoint = mp.grampoint
404zetazero = mp.zetazero
405riemannr = mp.riemannr
406primepi = mp.primepi
407primepi2 = mp.primepi2
408primezeta = mp.primezeta
409bell = mp.bell
410polyexp = mp.polyexp
411expm1 = mp.expm1
412powm1 = mp.powm1
413unitroots = mp.unitroots
414cyclotomic = mp.cyclotomic
415mangoldt = mp.mangoldt
416secondzeta = mp.secondzeta
417nzeros = mp.nzeros
418backlunds = mp.backlunds
419lerchphi = mp.lerchphi
420stirling1 = mp.stirling1
421stirling2 = mp.stirling2
422
423# be careful when changing this name, don't use test*!
424def runtests():
425    """
426    Run all mpmath tests and print output.
427    """
428    import os.path
429    from inspect import getsourcefile
430    from .tests import runtests as tests
431    testdir = os.path.dirname(os.path.abspath(getsourcefile(tests)))
432    importdir = os.path.abspath(testdir + '/../..')
433    tests.testit(importdir, testdir)
434
435def doctests(filter=[]):
436    try:
437        import psyco; psyco.full()
438    except ImportError:
439        pass
440    import sys
441    from timeit import default_timer as clock
442    for i, arg in enumerate(sys.argv):
443        if '__init__.py' in arg:
444            filter = [sn for sn in sys.argv[i+1:] if not sn.startswith("-")]
445            break
446    import doctest
447    globs = globals().copy()
448    for obj in globs: #sorted(globs.keys()):
449        if filter:
450            if not sum([pat in obj for pat in filter]):
451                continue
452        sys.stdout.write(str(obj) + " ")
453        sys.stdout.flush()
454        t1 = clock()
455        doctest.run_docstring_examples(globs[obj], {}, verbose=("-v" in sys.argv))
456        t2 = clock()
457        print(round(t2-t1, 3))
458
459if __name__ == '__main__':
460    doctests()
461
462
Full Screen

test_precompute_gammainc.py

Source: test_precompute_gammainc.py Github

copy
1from __future__ import division, print_function, absolute_import
2
3import numpy as np
4import pytest
5
6from scipy.special._testutils import MissingModule, check_version
7from scipy.special._mptestutils import (
8    Arg, IntArg, mp_assert_allclose, assert_mpmath_equal)
9from scipy.special._precompute.gammainc_asy import (
10    compute_g, compute_alpha, compute_d)
11from scipy.special._precompute.gammainc_data import gammainc, gammaincc
12
13try:
14    import sympy
15except ImportError:
16    sympy = MissingModule('sympy')
17
18try:
19    import mpmath as mp
20except ImportError:
21    mp = MissingModule('mpmath')
22
23
24_is_32bit_platform = np.intp(0).itemsize < 8
25
26
27@check_version(mp, '0.19')
28def test_g():
29    # Test data for the g_k. See DLMF 5.11.4.
30    with mp.workdps(30):
31        g = [mp.mpf(1), mp.mpf(1)/12, mp.mpf(1)/288,
32             -mp.mpf(139)/51840, -mp.mpf(571)/2488320,
33             mp.mpf(163879)/209018880, mp.mpf(5246819)/75246796800]
34        mp_assert_allclose(compute_g(7), g)
35
36
37@pytest.mark.slow
38@check_version(mp, '0.19')
39@check_version(sympy, '0.7')
40@pytest.mark.xfail(condition=_is_32bit_platform, reason="rtol only 2e-11, see gh-6938")
41def test_alpha():
42    # Test data for the alpha_k. See DLMF 8.12.14.
43    with mp.workdps(30):
44        alpha = [mp.mpf(0), mp.mpf(1), mp.mpf(1)/3, mp.mpf(1)/36,
45                 -mp.mpf(1)/270, mp.mpf(1)/4320, mp.mpf(1)/17010,
46                 -mp.mpf(139)/5443200, mp.mpf(1)/204120]
47        mp_assert_allclose(compute_alpha(9), alpha)
48
49
50@pytest.mark.xslow
51@check_version(mp, '0.19')
52@check_version(sympy, '0.7')
53def test_d():
54    # Compare the d_{k, n} to the results in appendix F of [1].
55    #
56    # Sources
57    # -------
58    # [1] DiDonato and Morris, Computation of the Incomplete Gamma
59    #     Function Ratios and their Inverse, ACM Transactions on
60    #     Mathematical Software, 1986.
61
62    with mp.workdps(50):
63        dataset = [(0, 0, -mp.mpf('0.333333333333333333333333333333')),
64                   (0, 12, mp.mpf('0.102618097842403080425739573227e-7')),
65                   (1, 0, -mp.mpf('0.185185185185185185185185185185e-2')),
66                   (1, 12, mp.mpf('0.119516285997781473243076536700e-7')),
67                   (2, 0, mp.mpf('0.413359788359788359788359788360e-2')),
68                   (2, 12, -mp.mpf('0.140925299108675210532930244154e-7')),
69                   (3, 0, mp.mpf('0.649434156378600823045267489712e-3')),
70                   (3, 12, -mp.mpf('0.191111684859736540606728140873e-7')),
71                   (4, 0, -mp.mpf('0.861888290916711698604702719929e-3')),
72                   (4, 12, mp.mpf('0.288658297427087836297341274604e-7')),
73                   (5, 0, -mp.mpf('0.336798553366358150308767592718e-3')),
74                   (5, 12, mp.mpf('0.482409670378941807563762631739e-7')),
75                   (6, 0, mp.mpf('0.531307936463992223165748542978e-3')),
76                   (6, 12, -mp.mpf('0.882860074633048352505085243179e-7')),
77                   (7, 0, mp.mpf('0.344367606892377671254279625109e-3')),
78                   (7, 12, -mp.mpf('0.175629733590604619378669693914e-6')),
79                   (8, 0, -mp.mpf('0.652623918595309418922034919727e-3')),
80                   (8, 12, mp.mpf('0.377358774161109793380344937299e-6')),
81                   (9, 0, -mp.mpf('0.596761290192746250124390067179e-3')),
82                   (9, 12, mp.mpf('0.870823417786464116761231237189e-6'))]
83        d = compute_d(10, 13)
84        res = [d[k][n] for k, n, std in dataset]
85        std = map(lambda x: x[2], dataset)
86        mp_assert_allclose(res, std)
87
88
89@check_version(mp, '0.19')
90def test_gammainc():
91    # Quick check that the gammainc in
92    # special._precompute.gammainc_data agrees with mpmath's
93    # gammainc.
94    assert_mpmath_equal(gammainc,
95                        lambda a, x: mp.gammainc(a, b=x, regularized=True),
96                        [Arg(0, 100, inclusive_a=False), Arg(0, 100)],
97                        nan_ok=False, rtol=1e-17, n=50, dps=50)
98
99
100@pytest.mark.xslow
101@check_version(mp, '0.19')
102def test_gammaincc():
103    # Check that the gammaincc in special._precompute.gammainc_data
104    # agrees with mpmath's gammainc.
105    assert_mpmath_equal(lambda a, x: gammaincc(a, x, dps=1000),
106                        lambda a, x: mp.gammainc(a, a=x, regularized=True),
107                        [Arg(20, 100), Arg(20, 100)],
108                        nan_ok=False, rtol=1e-17, n=50, dps=1000)
109
110    # Test the fast integer path
111    assert_mpmath_equal(gammaincc,
112                        lambda a, x: mp.gammainc(a, a=x, regularized=True),
113                        [IntArg(1, 100), Arg(0, 100)],
114                        nan_ok=False, rtol=1e-17, n=50, dps=50)
115
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run Python Tests on LambdaTest Cloud Grid

Execute automation tests with Pytest on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)