Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flake8 violations #1029

Merged
merged 9 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ exclude = setup.py,
test/test_continuous.py,
test/test_util.py,
test/test_find.py,
test/test_statistics.py,
test/tools.py,
test/test_results.py,
test/test_quickstart.py,
benchmarks/step_detect.py,
benchmarks/__init__.py,
docs/source/conf.py,
Expand Down
3 changes: 0 additions & 3 deletions test/test_quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

import os
from os.path import isfile, join

import six

from . import tools
from asv import util
import asv.commands.quickstart
Expand Down
24 changes: 12 additions & 12 deletions test/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from asv import results, runner, util
import pytest

from .tools import example_results
datapythonista marked this conversation as resolved.
Show resolved Hide resolved


def _truncate_floats(item, digits=5):
if isinstance(item, float):
Expand Down Expand Up @@ -53,16 +51,17 @@ def test_results(tmpdir):

values = {
'suite1.benchmark1': {'result': [x1], 'number': [1],
'samples': [[x1,x1]], 'params': [['a']],
'samples': [[x1, x1]], 'params': [['a']],
'version': "1", 'profile': b'\x00\xff'},
'suite1.benchmark2': {'result': [x2], 'number': [1],
'samples': [[x2,x2,x2]], 'params': [],
'samples': [[x2, x2, x2]], 'params': [],
'version': "1", 'profile': b'\x00\xff'},
'suite2.benchmark1': {'result': [x3], 'number': [None],
'samples': [None], 'params': [['c']],
'version': None, 'profile': b'\x00\xff'},
'suite3.benchmark1': {'result': [x1, x2], 'number': [1, 1],
'samples': [[x1,x1], [x2,x2,x3]], 'params': [['c', 'd']],
'samples': [[x1, x1], [x2, x2, x3]],
'params': [['c', 'd']],
'version': None, 'profile': b'\x00\xff'}
}

Expand Down Expand Up @@ -212,9 +211,9 @@ def test_iter_results(capsys, tmpdir, example_results):

skip_list = [
'machine.json',
'aaaaaaaa-py2.7-Cython-numpy1.8.json', # malformed file
'bbbbbbbb-py2.7-Cython-numpy1.8.json', # malformed file
'cccccccc-py2.7-Cython-numpy1.8.json', # malformed file
'aaaaaaaa-py2.7-Cython-numpy1.8.json', # malformed file
'bbbbbbbb-py2.7-Cython-numpy1.8.json', # malformed file
'cccccccc-py2.7-Cython-numpy1.8.json', # malformed file
]

files = [f for f in os.listdir(path) if f.endswith('.json') and f not in skip_list]
Expand All @@ -238,7 +237,7 @@ def test_filename_format():
r = results.Results({'machine': 'foo'}, [], "commit", 0, "", "env", {})
assert r._filename == join("foo", "commit-env.json")

r = results.Results({'machine': 'foo'}, [], "hash", 0, "", "a"*128, {})
r = results.Results({'machine': 'foo'}, [], "hash", 0, "", "a" * 128, {})
assert r._filename == join("foo", "hash-env-e510683b3f5ffe4093d021808bc6ff70.json")


Expand All @@ -250,7 +249,7 @@ def test_remove_samples():

v1 = runner.BenchmarkResult(result=[True], samples=[[1]], number=[1],
profile=None, errcode=0, stderr='')
v2 = runner.BenchmarkResult(result=[True]*3, samples=[[1],[2],[3]], number=[1,1,1],
v2 = runner.BenchmarkResult(result=[True] * 3, samples=[[1], [2], [3]], number=[1, 1, 1],
profile=None, errcode=0, stderr='')

r.add_result(benchmark1, v1, record_samples=True)
Expand Down Expand Up @@ -287,8 +286,9 @@ def test_table_formatting():
table = "\n".join(results._format_benchmark_result(result, benchmark, max_width=80))
assert table == expected

benchmark = {'params': [["'a'", "'b'", "'c'"], ["[1]", "[2]"]], 'param_names': ['param1', 'param2'], "unit": "seconds"}
result = list(zip([1, 2, None, 4, 5, float('nan')], [None]*6))
benchmark = {'params': [["'a'", "'b'", "'c'"], ["[1]", "[2]"]],
'param_names': ['param1', 'param2'], "unit": "seconds"}
result = list(zip([1, 2, None, 4, 5, float('nan')], [None] * 6))
expected = ("======== ======== =======\n"
"-- param2 \n"
"-------- ----------------\n"
Expand Down
35 changes: 18 additions & 17 deletions test/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_compute_stats():

err = statistics.get_err(result, stats)
iqr = np.percentile(samples, 75) - np.percentile(samples, 25)
assert np.allclose(err, iqr/2)
assert np.allclose(err, iqr / 2)


@pytest.mark.skipif(not HAS_NUMPY, reason="Requires numpy")
Expand Down Expand Up @@ -138,12 +138,12 @@ def sample_normal(size):
for sampler in [sample_exp, sample_normal]:
cis = _check_ci(lambda z, alpha: statistics.quantile_ci(z, 0.5, alpha),
sampler, nsamples=300)
atol = 5/300
atol = 5 / 300
for size, alpha, alpha_got in cis:
if size < 20:
assert 0 <= alpha_got <= 1.2*alpha
assert 0 <= alpha_got <= 1.2 * alpha
else:
assert 0.5*alpha - atol <= alpha_got <= 1.1*alpha + atol
assert 0.5 * alpha - atol <= alpha_got <= 1.1 * alpha + atol


def test_quantile_ci_small():
Expand All @@ -157,7 +157,7 @@ def test_quantile_ci_small():

def test_quantile_ci_r():
# Compare to R
x = [-2.47946614, -1.49595963, -1.02812482, -0.76592323, -0.09452743, 0.10732743,
x = [-2.47946614, -1.49595963, -1.02812482, -0.76592323, -0.09452743, 0.10732743,
0.27798342, 0.50173779, 0.57829823, 0.60474948, 0.94695675, 1.20159789]

# quantile(x, type=7, prob=p)
Expand All @@ -168,7 +168,7 @@ def test_quantile_ci_r():
# asht::quantileTest(x, prob=p, conf.level=0.8)$conf.int
ci_20_80_e = [-2.47946614, -0.09452743]
ci_50_80_e = [-0.7659232, 0.5782982]
ci_80_80_e = [0.5017378, 1.2015979,]
ci_80_80_e = [0.5017378, 1.2015979]

q_20, ci_20_80 = statistics.quantile_ci(x, 0.2, 0.8)
q_50, ci_50_80 = statistics.quantile_ci(x, 0.5, 0.8)
Expand Down Expand Up @@ -207,8 +207,8 @@ def test_lgamma():
@pytest.mark.skipif(not HAS_SCIPY, reason="Requires scipy")
def test_binom_pmf():
p = np.linspace(0, 1, 7)
k = np.arange(0, 40, 5)[:,None]
n = np.arange(0, 40, 5)[:,None,None]
k = np.arange(0, 40, 5)[:, None]
n = np.arange(0, 40, 5)[:, None, None]

expected = stats.binom.pmf(k, n, p)
got = np.vectorize(statistics.binom_pmf)(n, k, p)
Expand Down Expand Up @@ -237,14 +237,14 @@ def get_z_normal(size):

def estimator(z, alpha):
c = statistics.LaplacePosterior(z.tolist())
a, b = c.ppf(alpha/2), c.ppf(1 - alpha/2)
a, b = c.ppf(alpha / 2), c.ppf(1 - alpha / 2)
a = min(c.mle, a) # force MLE inside CI
b = max(c.mle, b)
return c.mle, (a, b)

for sampler in [get_z_exp, get_z_normal]:
cis = _check_ci(estimator, sampler, nsamples=300)
atol = 5/300
atol = 5 / 300
for size, alpha, alpha_got in cis:
if sampler == get_z_exp:
# Result should be ok for the assumed distribution
Expand All @@ -271,11 +271,11 @@ def test_laplace_posterior_basic():

# check pdf vs cdf
sx = 200
dx = 1.0/sx
dx = 1.0 / sx
cdf = 0
for jx in range(-10*sx, 10*sx):
cdf += c.pdf(dx*jx) * dx
got = c.cdf(dx*jx)
for jx in range(-10 * sx, 10 * sx):
cdf += c.pdf(dx * jx) * dx
got = c.cdf(dx * jx)
assert abs(cdf - got) < 3e-3
assert abs(cdf - 1.0) < 1e-3

Expand Down Expand Up @@ -318,7 +318,7 @@ def test_laplace_posterior_basic():
with pytest.raises(ValueError):
statistics.LaplacePosterior([])


@pytest.mark.skipif(not HAS_SCIPY, reason="Requires scipy")
def test_laplace_posterior_cdf():
# Test the LaplacePosterior cdf vs pdf
Expand All @@ -327,7 +327,8 @@ def test_laplace_posterior_cdf():

c = statistics.LaplacePosterior(y)

num_cdf = lambda t: integrate.quad(c.pdf, -np.inf, t, limit=1000)[0]
def num_cdf(t):
return integrate.quad(c.pdf, -np.inf, t, limit=1000)[0]

with warnings.catch_warnings():
warnings.simplefilter("ignore", category=integrate.IntegrationWarning)
Expand Down Expand Up @@ -434,7 +435,7 @@ def test_mann_whitney_u_basic():
b = [2.5]
u, p = statistics.mann_whitney_u(a, b, method='exact')
assert u == 0
assert p == pytest.approx(2/3, abs=0, rel=1e-10)
assert p == pytest.approx(2 / 3, abs=0, rel=1e-10)


@pytest.mark.skipif(not HAS_RPY2, reason="Requires rpy2")
Expand Down
20 changes: 9 additions & 11 deletions test/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
from contextlib import contextmanager
from hashlib import sha256
from six.moves import SimpleHTTPServer
from filelock import FileLock


import pytest

try:
import hglib
except ImportError as exc:
except ImportError:
hglib = None

import asv
Expand Down Expand Up @@ -80,12 +82,11 @@ def _check_conda():
# Conda can install required Python versions on demand
_check_conda()
HAS_CONDA = True
except (RuntimeError, IOError) as exc:
except (RuntimeError, IOError):
HAS_CONDA = False


try:
import virtualenv
datapythonista marked this conversation as resolved.
Show resolved Hide resolved
HAS_VIRTUALENV = True
except ImportError:
HAS_VIRTUALENV = False
Expand All @@ -109,9 +110,6 @@ def _check_conda():
WAIT_TIME = 20.0


from filelock import FileLock


def get_default_environment_type(conf, python):
return environment.get_environment_class(conf, python).tool_name

Expand Down Expand Up @@ -198,7 +196,7 @@ def commit(self, message, date=None):
date = self._fake_date

self.run_git(['commit', '--date', date.isoformat(),
'-m', message])
'-m', message])

def tag(self, number):
self.run_git(['tag', '-a', '-m', 'Tag {0}'.format(number),
Expand Down Expand Up @@ -488,8 +486,8 @@ def generate_result_dir(tmpdir, dvcs, values, branches=None, updated=None):
repo.get_date_from_name(commit), "2.7", None, {})
value = runner.BenchmarkResult(
result=value,
samples=[None]*len(value),
number=[None]*len(value),
samples=[None] * len(value),
number=[None] * len(value),
errcode=0,
stderr='',
profile=None)
Expand Down Expand Up @@ -612,7 +610,7 @@ def translate_path(self, path):
def run():
try:
httpd.serve_forever()
except:
except Exception:
import traceback
traceback.print_exc()
finally:
Expand Down Expand Up @@ -673,7 +671,7 @@ def dummy_packages(request, monkeypatch):
try:
os.makedirs(wheel_dir)
_build_dummy_wheels(tmpdir, wheel_dir, to_build, build_conda=HAS_CONDA)
except:
except Exception:
shutil.rmtree(wheel_dir)
raise

Expand Down