Browse code

fix flake8 issues for the learner tests

Bas Nijholt authored on 15/10/2018 14:52:40
Showing 7 changed files
... ...
@@ -30,7 +30,7 @@ def test_avg_std_and_npoints():
30 30
         # This will add 5000 points at random values of n.
31 31
         # It could try to readd already evaluated points.
32 32
 
33
-        n = random.randint(0, 2*300)
33
+        n = random.randint(0, 2 * 300)
34 34
         value = random.random()
35 35
 
36 36
         # With 10% chance None is added to simulate asking that point.
... ...
@@ -13,14 +13,6 @@ from .algorithm_4 import DivergentIntegralError as A4DivergentIntegralError
13 13
 eps = np.spacing(1)
14 14
 
15 15
 
16
-def rolling_shuffle(nums, size):
17
-    for i in range(len(nums) - size):
18
-        x = nums[i:i+size+1]
19
-        random.shuffle(x)
20
-        nums[i:i+size+1] = x
21
-    return nums
22
-
23
-
24 16
 def run_integrator_learner(f, a, b, tol, n):
25 17
     learner = IntegratorLearner(f, bounds=(a, b), tol=tol)
26 18
     for _ in range(n):
... ...
@@ -73,6 +65,7 @@ def same_ivals(f, a, b, tol):
73 65
 
74 66
         return equal_ivals(learner.ivals, ivals, verbose=True)
75 67
 
68
+
76 69
 # XXX: This *should* pass (https://gitlab.kwant-project.org/qt/adaptive/issues/84)
77 70
 @pytest.mark.xfail
78 71
 def test_that_gives_same_intervals_as_reference_implementation():
... ...
@@ -162,7 +155,6 @@ def test_adding_points_and_skip_one_point():
162 155
     np.testing.assert_almost_equal(learner.igral, learner2.igral)
163 156
 
164 157
 
165
-
166 158
 # XXX: This *should* pass (https://gitlab.kwant-project.org/qt/adaptive/issues/84)
167 159
 @pytest.mark.xfail
168 160
 def test_tell_in_random_order(first_add_33=False):
... ...
@@ -224,7 +216,6 @@ def test_tell_in_random_order(first_add_33=False):
224 216
             assert np.isfinite(l.err)
225 217
 
226 218
 
227
-
228 219
 # XXX: This *should* pass (https://gitlab.kwant-project.org/qt/adaptive/issues/84)
229 220
 @pytest.mark.xfail
230 221
 def test_tell_in_random_order_first_add_33():
... ...
@@ -4,7 +4,7 @@ import random
4 4
 import numpy as np
5 5
 
6 6
 from ..learner import Learner1D
7
-from ..runner import simple, replay_log
7
+from ..runner import simple
8 8
 
9 9
 
10 10
 def test_pending_loss_intervals():
... ...
@@ -200,7 +200,8 @@ def test_small_deviations():
200 200
 
201 201
 def test_uniform_sampling1D_v2():
202 202
     def check(known, expect):
203
-        def f(x): return x
203
+        def f(x):
204
+            return x
204 205
         learner = Learner1D(f, bounds=(-1, 1))
205 206
         for x in known:
206 207
             learner.tell(x, f(x))
... ...
@@ -241,8 +242,8 @@ def test_tell_many():
241 242
     def f(x, offset=0.123214):
242 243
         a = 0.01
243 244
         return (np.sin(x**2) + np.sin(x**5)
244
-            + a**2 / (a**2 + (x - offset)**2)
245
-            + x**2 + 1e-5 * x**3)
245
+                + a**2 / (a**2 + (x - offset)**2)
246
+                + x**2 + 1e-5 * x**3)
246 247
 
247 248
     def f_vec(x, offset=0.123214):
248 249
         a = 0.01
... ...
@@ -11,8 +11,8 @@ import scipy.spatial
11 11
 
12 12
 import pytest
13 13
 
14
-from ..learner import *
15
-from ..runner import simple, replay_log
14
+from ..learner import AverageLearner, BalancingLearner, Learner1D, Learner2D, LearnerND
15
+from ..runner import simple
16 16
 
17 17
 
18 18
 def generate_random_parametrization(f):
... ...
@@ -1,6 +1,5 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
-import concurrent.futures as concurrent
4 3
 import asyncio
5 4
 
6 5
 from ..learner import Learner2D
... ...
@@ -1,6 +1,5 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3
-import random
4 3
 import numpy as np
5 4
 
6 5
 import pytest
... ...
@@ -1,4 +1,4 @@
1
-from collections import defaultdict, Counter
1
+from collections import Counter
2 2
 from math import factorial
3 3
 import itertools
4 4
 import pytest
... ...
@@ -297,7 +297,7 @@ def test_triangulation_is_deterministic(dim):
297 297
 @with_dimension
298 298
 def test_initialisation_raises_when_not_enough_points(dim):
299 299
     deficient_simplex = _make_standard_simplex(dim)[:-1]
300
-    
300
+
301 301
     with pytest.raises(ValueError):
302 302
         Triangulation(deficient_simplex)
303 303
 
... ...
@@ -305,12 +305,12 @@ def test_initialisation_raises_when_not_enough_points(dim):
305 305
 @with_dimension
306 306
 def test_initialisation_raises_when_points_coplanar(dim):
307 307
     zero_volume_simplex = _make_standard_simplex(dim)[:-1]
308
-    
308
+
309 309
     new_point1 = np.average(zero_volume_simplex, axis=0)
310 310
     new_point2 = np.sum(zero_volume_simplex, axis=0)
311
-    zero_volume_simplex = np.vstack((zero_volume_simplex, 
311
+    zero_volume_simplex = np.vstack((zero_volume_simplex,
312 312
                                      new_point1, new_point2))
313
-    
313
+
314 314
     with pytest.raises(ValueError):
315 315
         Triangulation(zero_volume_simplex)
316 316
 
... ...
@@ -326,6 +326,6 @@ def test_initialisation_accepts_more_than_one_simplex(dim):
326 326
     simplex1 = tuple(range(dim+1))
327 327
     simplex2 = tuple(range(1, dim+2))
328 328
 
329
-    _check_triangulation_is_valid(tri)    
330
-    
329
+    _check_triangulation_is_valid(tri)
330
+
331 331
     assert tri.simplices == {simplex1, simplex2}