Skip to content

Commit 35bda52

Browse files
use context managers for tests/test_patchset.py
1 parent af4e86f commit 35bda52

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

tests/test_patchset.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ def patch():
3333
],
3434
)
3535
def test_patchset_invalid_spec(datadir, patchset_file):
36-
with open(datadir.joinpath(patchset_file), encoding="utf-8") as patch_file:
37-
patchsetspec = json.load(patch_file)
36+
with open(datadir.joinpath(patchset_file), encoding="utf-8") as patchset_spec_file:
37+
patchsetspec = json.load(patchset_spec_file)
3838
with pytest.raises(pyhf.exceptions.InvalidSpecification):
3939
pyhf.PatchSet(patchsetspec)
4040

@@ -48,8 +48,8 @@ def test_patchset_invalid_spec(datadir, patchset_file):
4848
],
4949
)
5050
def test_patchset_bad(datadir, patchset_file):
51-
with open(datadir.joinpath(patchset_file), encoding="utf-8") as patch_file:
52-
patchsetspec = json.load(patch_file)
51+
with open(datadir.joinpath(patchset_file), encoding="utf-8") as patchset_spec_file:
52+
patchsetspec = json.load(patchset_spec_file)
5353
with pytest.raises(pyhf.exceptions.InvalidPatchSet):
5454
pyhf.PatchSet(patchsetspec)
5555

@@ -102,29 +102,29 @@ def test_patchset_repr(patchset):
102102
def test_patchset_verify(datadir):
103103
with open(
104104
datadir.joinpath("example_patchset.json"), encoding="utf-8"
105-
) as patch_file:
106-
patchset = pyhf.PatchSet(json.load(patch_file))
107-
with open(datadir.joinpath("example_bkgonly.json"), encoding="utf-8") as ws_file:
108-
ws = pyhf.Workspace(json.load(ws_file))
105+
) as patchset_file:
106+
patchset = pyhf.PatchSet(json.load(patchset_file))
107+
with open(datadir.joinpath("example_bkgonly.json"), encoding="utf-8") as bkg_file:
108+
ws = pyhf.Workspace(json.load(bkg_file))
109109
assert patchset.verify(ws) is None
110110

111111

112112
def test_patchset_verify_failure(datadir):
113113
with open(
114114
datadir.joinpath("example_patchset.json"), encoding="utf-8"
115-
) as patch_file:
116-
patchset = pyhf.PatchSet(json.load(patch_file))
115+
) as patchset_file:
116+
patchset = pyhf.PatchSet(json.load(patchset_file))
117117
with pytest.raises(pyhf.exceptions.PatchSetVerificationError):
118118
assert patchset.verify({})
119119

120120

121121
def test_patchset_apply(datadir):
122122
with open(
123123
datadir.joinpath("example_patchset.json"), encoding="utf-8"
124-
) as patch_file:
125-
patchset = pyhf.PatchSet(json.load(patch_file))
126-
with open(datadir.joinpath("example_bkgonly.json"), encoding="utf-8") as ws_file:
127-
ws = pyhf.Workspace(json.load(ws_file))
124+
) as patchset_file:
125+
patchset = pyhf.PatchSet(json.load(patchset_file))
126+
with open(datadir.joinpath("example_bkgonly.json"), encoding="utf-8") as bkg_file:
127+
ws = pyhf.Workspace(json.load(bkg_file))
128128
with mock.patch('pyhf.patchset.PatchSet.verify') as m:
129129
assert m.call_count == 0
130130
assert patchset.apply(ws, 'patch_channel1_signal_syst1')
@@ -149,9 +149,10 @@ def test_patch_equality(patch):
149149

150150
def test_patchset_get_string_values(datadir):
151151
with open(
152-
datadir.joinpath('patchset_good_stringvalues.json'), encoding="utf-8"
153-
) as patch_file:
154-
patchset = pyhf.PatchSet(json.load(patch_file))
152+
datadir.joinpath("patchset_good_stringvalues.json"), encoding="utf-8"
153+
) as patchset_file:
154+
patchset = pyhf.PatchSet(json.load(patchset_file))
155+
155156
assert patchset["Gtt_2100_5000_800"]
156157
assert patchset["Gbb_2200_5000_800"]
157158
assert patchset[[2100, 800, "Gtt"]]

0 commit comments

Comments
 (0)