Skip to content

Commit 2d95e74

Browse files
committed
Update test to correctly mock behaviour
1 parent a38a0df commit 2d95e74

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lib/iris/tests/unit/cube/test_Cube.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
AncillaryVariableNotFoundError,
3939
UnitConversionError,
4040
)
41-
from iris.experimental.representation import CubeRepresentation
4241
from iris._lazy_data import as_lazy_data
4342
import iris.tests.stock as stock
4443

@@ -2417,15 +2416,12 @@ class Test__repr_html(tests.IrisTest):
24172416
def test_bad_repr(self):
24182417
# If an html repr fails we don't want it to pass the error.
24192418
cube = stock.simple_3d()
2420-
bad_attr = {'history': 'First edit\nSecond edit'}
2421-
cube.attributes.update(bad_attr)
2422-
representer = CubeRepresentation(cube)
2423-
2424-
# Confirm we get an exception when we make the html repr...
2425-
with self.assertRaisesRegexp(ValueError, 'substring'):
2426-
representer.repr_html()
2427-
# ... and that it's not returned by the cube method.
2428-
self.assertIsNone(cube._repr_html_())
2419+
with mock.patch(
2420+
"iris.experimental.representation.CubeRepresentation.repr_html",
2421+
side_effect=ValueError('Bad substring')):
2422+
# Confirm the exception when we make the html repr is not returned
2423+
# by the cube method.
2424+
self.assertIsNone(cube._repr_html_())
24292425

24302426

24312427
if __name__ == "__main__":

0 commit comments

Comments
 (0)