Browse code

correctly test diverging integrals

Joseph Weston authored on 17/11/2017 12:16:51 • Bas Nijholt committed on 20/11/2017 15:49:57
Showing 1 changed files
... ...
@@ -3,7 +3,9 @@
3 3
 import numpy as np
4 4
 import pytest
5 5
 from ..learner import IntegratorLearner
6
+from ..learner.integrator_learner import DivergentIntegralError
6 7
 from .algorithm_4 import algorithm_4, f0, f7, f21, f24, f63, fdiv
8
+from .algorithm_4 import DivergentIntegralError as A4DivergentIntegralError
7 9
 
8 10
 
9 11
 def run_integrator_learner(f, a, b, tol, nr_points):
... ...
@@ -61,12 +63,10 @@ def test_machine_precision2():
61 63
 def test_divergence():
62 64
     """This function should raise a DivergentIntegralError."""
63 65
     f, a, b, tol = fdiv, 0, 1, 1e-6
64
-    try:
66
+    with pytest.raises(A4DivergentIntegralError) as e:
65 67
         igral, err, nr_points, ivals = algorithm_4(f, a, b, tol)
66
-    except Exception:
67
-        print('The integral is diverging.')
68 68
 
69
-    try:
69
+    nr_points = e.value.nr_points
70
+
71
+    with pytest.raises(DivergentIntegralError):
70 72
         learner = run_integrator_learner(f, a, b, tol, nr_points)
71
-    except Exception:
72
-        print('The integral is diverging.')