Skip to content

Commit 8a7ab08

Browse files
author
jensj
committed
Test that you can't use the same name for both a key and a keyword
1 parent 3823393 commit 8a7ab08

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

ase/test/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ def __init__(self, size):
166166
def get_rank(self, rank):
167167
return CPU(self, rank)
168168

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+
169183

170184
class CPU:
171185
def __init__(self, world, rank):

ase/test/db2.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from ase import Atoms
2-
from ase.db import connect
3-
from ase.structure import molecule
42
from ase.calculators.emt import EMT
53
from ase.constraints import FixAtoms, FixBondLength
4+
from ase.db import connect
5+
from ase.structure import molecule
6+
from ase.test import MustRaise
67

78

89
for name in ['y2.json', 'y2.db']:
@@ -39,9 +40,8 @@
3940
c.update(id, grr='hmm')
4041
assert c.get(C=1).id == id
4142

42-
try:
43+
with MustRaise(AssertionError):
4344
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+

0 commit comments

Comments
 (0)