Skip to content

Commit 3dc4d36

Browse files
matthewfeickertlukasheinrich
authored andcommitted
chore: Make tests pass pyflakes (#718)
* Make the tests pass pyflakes * Add testing of 'pyflakes tests/' to the CI
1 parent 5ef0d24 commit 3dc4d36

File tree

12 files changed

+20
-53
lines changed

12 files changed

+20
-53
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ jobs:
3030
- name: Lint with Pyflakes
3131
if: matrix.python-version == 3.7 && matrix.os == 'ubuntu-latest'
3232
run: |
33-
pyflakes src
33+
python -m pyflakes src/
34+
python -m pyflakes tests/
3435
- name: Lint with Black
3536
if: matrix.python-version == 3.7 && matrix.os == 'ubuntu-latest'
3637
run: |

tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import torch # Solves "cannot load any more object with static TLS" (thread local storage) error
21
import pytest
32
import pyhf
43
import tensorflow as tf
@@ -74,7 +73,9 @@ def backend(request):
7473

7574
if skip_backend and (param_id in only_backends):
7675
raise ValueError(
77-
"Must specify skip_{param} or only_{param} but not both!".format(param=pid)
76+
"Must specify skip_{param} or only_{param} but not both!".format(
77+
param=param_id
78+
)
7879
)
7980

8081
if skip_backend:

tests/contrib/test_viz.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
import json
33
import pyhf.contrib.viz.brazil as brazil
44
import matplotlib.pyplot as plt
5-
import numpy as np
6-
from matplotlib.testing.decorators import image_comparison
75

86

97
@pytest.mark.mpl_image_compare
108
def test_brazil():
119
data = json.load(open('tests/contrib/hypotestresults.json'))
1210
fig, ax = plt.subplots(1, 1)
13-
testmus = np.linspace(0, 5)
1411
brazil.plot_results(ax, data['testmus'], data['results'], test_size=0.05)
1512
return fig

tests/test_events.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import pytest
21
import pyhf.events as events
32
import mock
43

tests/test_export.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,6 @@ def test_export_sample(mocker, spec):
264264
channelspec = spec['channels'][0]
265265
channelname = channelspec['name']
266266
samplespec = channelspec['samples'][1]
267-
samplename = samplespec['name']
268-
sampledata = samplespec['data']
269267

270268
mocker.patch('pyhf.writexml.build_modifier', return_value=ET.Element("Modifier"))
271269
mocker.patch('pyhf.writexml._ROOT_DATA_FILE')
@@ -292,7 +290,7 @@ def test_export_sample_zerodata(mocker, spec):
292290
# make sure no RuntimeWarning, https://stackoverflow.com/a/45671804
293291
with pytest.warns(None) as record:
294292
for modifierspec in samplespec['modifiers']:
295-
modifier = pyhf.writexml.build_modifier(
293+
pyhf.writexml.build_modifier(
296294
{'measurements': [{'config': {'parameters': []}}]},
297295
modifierspec,
298296
channelname,
@@ -309,7 +307,6 @@ def test_export_sample_zerodata(mocker, spec):
309307
)
310308
def test_export_channel(mocker, spec):
311309
channelspec = spec['channels'][0]
312-
channelname = channelspec['name']
313310

314311
mocker.patch('pyhf.writexml.build_data', return_value=ET.Element("Data"))
315312
mocker.patch('pyhf.writexml.build_sample', return_value=ET.Element("Sample"))

tests/test_import.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,7 @@ def test_import_histosys():
209209
}
210210
pdf = pyhf.Model(spec, poiname='SigXsecOverSM')
211211

212-
data = [
213-
binvalue
214-
for k in pdf.spec['channels']
215-
for binvalue in next(
216-
obs for obs in parsed_xml['observations'] if obs['name'] == k['name']
217-
)['data']
218-
] + pdf.config.auxdata
219-
220212
channels = {channel['name']: channel for channel in pdf.spec['channels']}
221-
samples = {
222-
channel['name']: [sample['name'] for sample in channel['samples']]
223-
for channel in pdf.spec['channels']
224-
}
225213

226214
assert channels['channel2']['samples'][0]['modifiers'][0]['type'] == 'lumi'
227215
assert channels['channel2']['samples'][0]['modifiers'][1]['type'] == 'histosys'
@@ -263,19 +251,7 @@ def test_import_shapesys():
263251
}
264252
pdf = pyhf.Model(spec, poiname='SigXsecOverSM')
265253

266-
data = [
267-
binvalue
268-
for k in pdf.spec['channels']
269-
for binvalue in next(
270-
obs for obs in parsed_xml['observations'] if obs['name'] == k['name']
271-
)['data']
272-
] + pdf.config.auxdata
273-
274254
channels = {channel['name']: channel for channel in pdf.spec['channels']}
275-
samples = {
276-
channel['name']: [sample['name'] for sample in channel['samples']]
277-
for channel in pdf.spec['channels']
278-
}
279255

280256
assert channels['channel1']['samples'][1]['modifiers'][0]['type'] == 'lumi'
281257
assert channels['channel1']['samples'][1]['modifiers'][1]['type'] == 'shapesys'

tests/test_infer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import pytest
32
import pyhf
43

tests/test_interpolate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ def test_interpolator_subscription(interpcode, random_histosets_alphasets_pair):
7373
# inject into our interpolator class
7474
interpolator_cls = pyhf.interpolators.get(interpcode)
7575
with mock.patch('{0:s}._precompute'.format(interpolator_cls.__module__)) as m:
76-
interpolator = interpolator_cls(histogramssets.tolist(), subscribe=False)
76+
interpolator_cls(histogramssets.tolist(), subscribe=False)
7777
assert m.call_count == 1
7878
assert m not in pyhf.events.__events.get(ename, [])
7979
pyhf.events.trigger(ename)()
8080
assert m.call_count == 1
8181

8282
with mock.patch('{0:s}._precompute'.format(interpolator_cls.__module__)) as m:
83-
interpolator = interpolator_cls(histogramssets.tolist(), subscribe=True)
83+
interpolator_cls(histogramssets.tolist(), subscribe=True)
8484
assert m.call_count == 1
8585
assert m in pyhf.events.__events.get(ename, [])
8686
pyhf.events.trigger(ename)()

tests/test_modifiers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22
import inspect
3-
from six import with_metaclass
43

54
import pyhf
65

@@ -121,13 +120,13 @@ class myCustomModifier(object):
121120
with pytest.raises(TypeError):
122121

123122
@modifier(name=1.5)
124-
class myCustomModifier(object):
123+
class myCustomModifierTypeError(object):
125124
pass
126125

127126
with pytest.raises(ValueError):
128127

129128
@modifier(unused='arg')
130-
class myCustomModifier(object):
129+
class myCustomModifierValueError(object):
131130
pass
132131

133132

@@ -138,7 +137,7 @@ def test_registry_name_clash():
138137
with pytest.raises(KeyError):
139138

140139
@modifier(name='histosys')
141-
class myCustomModifier(object):
140+
class myCustomModifierKeyError(object):
142141
pass
143142

144143
with pytest.raises(KeyError):

tests/test_pdf.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ def test_pdf_integration_staterror(backend):
171171
]
172172
}
173173
pdf = pyhf.Model(spec)
174-
par = pdf.config.par_slice('stat_firstchannel')
175174
par_set = pdf.config.param_set('stat_firstchannel')
176175
tensorlib, _ = backend
177176
uncerts = tensorlib.astensor([[12.0, 12.0], [5.0, 5.0]])
@@ -600,4 +599,4 @@ def test_sample_wrong_bins():
600599
]
601600
}
602601
with pytest.raises(pyhf.exceptions.InvalidModel):
603-
pdf = pyhf.Model(spec)
602+
pyhf.Model(spec)

0 commit comments

Comments
 (0)