Skip to content

Commit

Permalink
fix flake8 issues for the learner tests
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Oct 15, 2018
1 parent 4fe50d0 commit 724f989
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 26 deletions.
2 changes: 1 addition & 1 deletion adaptive/tests/test_average_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_avg_std_and_npoints():
# This will add 5000 points at random values of n.
# It could try to readd already evaluated points.

n = random.randint(0, 2*300)
n = random.randint(0, 2 * 300)
value = random.random()

# With 10% chance None is added to simulate asking that point.
Expand Down
11 changes: 1 addition & 10 deletions adaptive/tests/test_cquad.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
eps = np.spacing(1)


def rolling_shuffle(nums, size):
for i in range(len(nums) - size):
x = nums[i:i+size+1]
random.shuffle(x)
nums[i:i+size+1] = x
return nums


def run_integrator_learner(f, a, b, tol, n):
learner = IntegratorLearner(f, bounds=(a, b), tol=tol)
for _ in range(n):
Expand Down Expand Up @@ -73,6 +65,7 @@ def same_ivals(f, a, b, tol):

return equal_ivals(learner.ivals, ivals, verbose=True)


# XXX: This *should* pass (https://gitlab.kwant-project.org/qt/adaptive/issues/84)
@pytest.mark.xfail
def test_that_gives_same_intervals_as_reference_implementation():
Expand Down Expand Up @@ -162,7 +155,6 @@ def test_adding_points_and_skip_one_point():
np.testing.assert_almost_equal(learner.igral, learner2.igral)



# XXX: This *should* pass (https://gitlab.kwant-project.org/qt/adaptive/issues/84)
@pytest.mark.xfail
def test_tell_in_random_order(first_add_33=False):
Expand Down Expand Up @@ -224,7 +216,6 @@ def test_tell_in_random_order(first_add_33=False):
assert np.isfinite(l.err)



# XXX: This *should* pass (https://gitlab.kwant-project.org/qt/adaptive/issues/84)
@pytest.mark.xfail
def test_tell_in_random_order_first_add_33():
Expand Down
9 changes: 5 additions & 4 deletions adaptive/tests/test_learner1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np

from ..learner import Learner1D
from ..runner import simple, replay_log
from ..runner import simple


def test_pending_loss_intervals():
Expand Down Expand Up @@ -200,7 +200,8 @@ def test_small_deviations():

def test_uniform_sampling1D_v2():
def check(known, expect):
def f(x): return x
def f(x):
return x
learner = Learner1D(f, bounds=(-1, 1))
for x in known:
learner.tell(x, f(x))
Expand Down Expand Up @@ -241,8 +242,8 @@ def test_tell_many():
def f(x, offset=0.123214):
a = 0.01
return (np.sin(x**2) + np.sin(x**5)
+ a**2 / (a**2 + (x - offset)**2)
+ x**2 + 1e-5 * x**3)
+ a**2 / (a**2 + (x - offset)**2)
+ x**2 + 1e-5 * x**3)

def f_vec(x, offset=0.123214):
a = 0.01
Expand Down
4 changes: 2 additions & 2 deletions adaptive/tests/test_learners.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import pytest

from ..learner import *
from ..runner import simple, replay_log
from ..learner import AverageLearner, BalancingLearner, Learner1D, Learner2D, LearnerND
from ..runner import simple


def generate_random_parametrization(f):
Expand Down
1 change: 0 additions & 1 deletion adaptive/tests/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

import concurrent.futures as concurrent
import asyncio

from ..learner import Learner2D
Expand Down
1 change: 0 additions & 1 deletion adaptive/tests/test_skopt_learner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-

import random
import numpy as np

import pytest
Expand Down
14 changes: 7 additions & 7 deletions adaptive/tests/test_triangulation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections import defaultdict, Counter
from collections import Counter
from math import factorial
import itertools
import pytest
Expand Down Expand Up @@ -297,20 +297,20 @@ def test_triangulation_is_deterministic(dim):
@with_dimension
def test_initialisation_raises_when_not_enough_points(dim):
deficient_simplex = _make_standard_simplex(dim)[:-1]

with pytest.raises(ValueError):
Triangulation(deficient_simplex)


@with_dimension
def test_initialisation_raises_when_points_coplanar(dim):
zero_volume_simplex = _make_standard_simplex(dim)[:-1]

new_point1 = np.average(zero_volume_simplex, axis=0)
new_point2 = np.sum(zero_volume_simplex, axis=0)
zero_volume_simplex = np.vstack((zero_volume_simplex,
zero_volume_simplex = np.vstack((zero_volume_simplex,
new_point1, new_point2))

with pytest.raises(ValueError):
Triangulation(zero_volume_simplex)

Expand All @@ -326,6 +326,6 @@ def test_initialisation_accepts_more_than_one_simplex(dim):
simplex1 = tuple(range(dim+1))
simplex2 = tuple(range(1, dim+2))

_check_triangulation_is_valid(tri)
_check_triangulation_is_valid(tri)

assert tri.simplices == {simplex1, simplex2}

0 comments on commit 724f989

Please sign in to comment.