Skip to content

Commit

Permalink
fix deprecation test
Browse files Browse the repository at this point in the history
  • Loading branch information
HDembinski committed Oct 9, 2024
1 parent 62ea345 commit 18105df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/pyhepmc/_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class deprecated:
def __init__(self, reason: str, removal: str = ""):
assert isinstance(reason, str)
self.reason = reason
self.removal = Version(removal) if removal else None

Expand Down
12 changes: 11 additions & 1 deletion tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,25 @@ class Foo:
def bar(self):
return 0

@deprecated("use baz", removal="1000.0.0")
def foo(self):
return 0


def test_deprecated():
foo = Foo()

with pytest.raises(ValueError, match="reason.*required"):
with pytest.raises(AssertionError):

@deprecated
def bad(self):
return 0

with pytest.warns(DeprecationWarning, match="bar is deprecated: use baz"):
foo.bar()

with pytest.warns(
FutureWarning,
match="bar is deprecated and will be removed in version 1000.0.0: use baz",
):
foo.foo()

0 comments on commit 18105df

Please sign in to comment.