-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
document
Throwing
in reference (#139)
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class ParticleClassifier: | ||
def __init__(self, spin_verifier): | ||
self._spin_verifier = spin_verifier | ||
|
||
def classify(self, mass, spin): | ||
self._spin_verifier(spin) | ||
# other logic here |
14 changes: 14 additions & 0 deletions
14
docs/reference/argument_expectations/test_particle_classifier.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from testix import * | ||
import pytest | ||
|
||
import particle_classifier | ||
|
||
def my_exception_factory(): | ||
return Exception('bad spin value') | ||
|
||
def test_allow_spin_verifier_to_raise_exceptions(): | ||
with Scenario() as s: | ||
s.spin_verifier('some spin value') >> Throwing(my_exception_factory) | ||
tested = particle_classifier.ParticleClassifier(Fake('spin_verifier')) | ||
with pytest.raises(Exception, match='bad spin value'): | ||
tested.classify(mass='0.5MeV', spin='some spin value') |