File tree 2 files changed +21
-7
lines changed
2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -166,6 +166,20 @@ def __init__(self, size):
166
166
def get_rank (self , rank ):
167
167
return CPU (self , rank )
168
168
169
+
170
+ class MustRaise :
171
+ """Context manager for checking raising of exceptions."""
172
+ def __init__ (self , exception ):
173
+ self .exception = exception
174
+
175
+ def __enter__ (self ):
176
+ pass
177
+
178
+ def __exit__ (self , exc_type , exc_value , tb ):
179
+ if exc_type is None :
180
+ raise RuntimeError ('Failed to fail: ' + str (self .exception ))
181
+ return issubclass (exc_type , self .exception )
182
+
169
183
170
184
class CPU :
171
185
def __init__ (self , world , rank ):
Original file line number Diff line number Diff line change 1
1
from ase import Atoms
2
- from ase .db import connect
3
- from ase .structure import molecule
4
2
from ase .calculators .emt import EMT
5
3
from ase .constraints import FixAtoms , FixBondLength
4
+ from ase .db import connect
5
+ from ase .structure import molecule
6
+ from ase .test import MustRaise
6
7
7
8
8
9
for name in ['y2.json' , 'y2.db' ]:
39
40
c .update (id , grr = 'hmm' )
40
41
assert c .get (C = 1 ).id == id
41
42
42
- try :
43
+ with MustRaise ( AssertionError ) :
43
44
c .update (id , ['grr' ])
44
- except AssertionError :
45
- pass
46
- else :
47
- 2 / 0
45
+ with MustRaise (AssertionError ):
46
+ c .write (ch4 , ['foo' ], foo = 'bar' )
47
+
You can’t perform that action at this time.
0 commit comments