Skip to content

Commit

Permalink
fix and use context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kratsg authored and matthewfeickert committed Apr 7, 2023
1 parent 2ca4907 commit 9a2c8a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ classifiers = [
dependencies = [
"click>=8.0.0", # for console scripts
"importlib_resources>=1.4.0; python_version < '3.9'", # for resources in schema
"typing_extensions; python_version < '3.11'" # for typing
"typing_extensions; python_version < '3.11'", # for typing
"jsonpatch>=1.15",
"jsonschema>=4.15.0", # for utils
"pyyaml>=5.1", # for parsing CLI equal-delimited options
Expand Down
18 changes: 12 additions & 6 deletions tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ def test_upgrade_bad_version(datadir):


def test_upgrade_to_latest(datadir):
ws = json.load(open(datadir.joinpath("workspace_1.0.0.json"), encoding="utf-8"))
with datadir.joinpath("workspace_1.0.0.json").open(encoding="utf-8") as fp:
ws = json.load(fp)
pyhf.schema.upgrade().workspace(ws)

ps = json.load(open(datadir.joinpath("workspace_1.0.0.json"), encoding="utf-8"))
with datadir.joinpath("workspace_1.0.0.json").open(encoding="utf-8") as fp:
ps = json.load(fp)
pyhf.schema.upgrade().patchset(ps)


def test_1_0_0_workspace(datadir, caplog, monkeypatch):
"""
Test upgrading a workspace from 1.0.0 to 1.0.1
"""
spec = json.load(open(datadir.joinpath("workspace_1.0.0.json"), encoding="utf-8"))
with datadir.joinpath("workspace_1.0.0.json").open(encoding="utf-8") as fp:
spec = json.load(fp)

monkeypatch.setitem(pyhf.schema.versions, 'workspace.json', '1.0.1')
with caplog.at_level(logging.INFO, 'pyhf.schema'):
Expand All @@ -39,7 +42,8 @@ def test_1_0_0_patchset(datadir, caplog, monkeypatch):
"""
Test upgrading a patchset from 1.0.0 to 1.0.1
"""
spec = json.load(open(datadir.joinpath("patchset_1.0.0.json"), encoding="utf-8"))
with datadir.joinpath("patchset_1.0.0.json").open(encoding="utf-8") as fp:
spec = json.load(fp)

monkeypatch.setitem(pyhf.schema.versions, 'patchset.json', '1.0.1')
with caplog.at_level(logging.INFO, 'pyhf.schema'):
Expand All @@ -56,7 +60,8 @@ def test_1_0_1_workspace(datadir):
"""
Test upgrading a workspace from 1.0.1 to 1.0.1
"""
spec = json.load(open(datadir.joinpath("workspace_1.0.1.json"), encoding="utf-8"))
with datadir.joinpath("workspace_1.0.1.json").open(encoding="utf-8") as fp:
spec = json.load(fp)

new_spec = pyhf.schema.upgrade(to_version='1.0.1').workspace(spec)
assert new_spec['version'] == '1.0.1'
Expand All @@ -66,7 +71,8 @@ def test_1_0_1_patchset(datadir):
"""
Test upgrading a patchset from 1.0.1 to 1.0.1
"""
spec = json.load(open(datadir.joinpath("patchset_1.0.1.json"), encoding="utf-8"))
with datadir.joinpath("patchset_1.0.1.json").open(encoding="utf-8") as fp:
spec = json.load(fp)

new_spec = pyhf.schema.upgrade(to_version='1.0.1').patchset(spec)
assert new_spec['version'] == '1.0.1'

0 comments on commit 9a2c8a6

Please sign in to comment.