Skip to content

Commit 4faec24

Browse files
committed
refactor test_iop_utils.py and test_utils.py
1 parent 05cfac1 commit 4faec24

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/tests/test_iop_utils.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,23 @@ def test_register_component():
3838
path = os.path.join(path, 'registerFilesIop')
3939
overwrite = 1
4040
iris_classname = 'UnitTest.EmailOperation'
41-
result = _Utils.register_component(module, classname, path, overwrite, iris_classname)
42-
expect = 1
41+
_Utils.register_component(module, classname, path, overwrite, iris_classname)
4342

44-
assert result == expect
43+
def test_register_module_error():
44+
module = 'bo'
45+
classname = 'EmailOperation'
46+
# get the path of the current file
47+
path = os.path.dirname(os.path.realpath(__file__))
48+
# join the registerFolder to the path
49+
path = os.path.join(path, 'registerFilesIop')
50+
overwrite = 1
51+
# mock call iris.cls() to raise an exception
52+
with patch('iris.cls', side_effect=RuntimeError):
53+
iris_classname = 'UnitTest.EmailOperation'
54+
try:
55+
_Utils.register_component(module, classname, path, overwrite, iris_classname)
56+
except RuntimeError as e:
57+
assert True
4558

4659
def test_register_folder():
4760
path = os.path.dirname(os.path.realpath(__file__))

src/tests/test_utils.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ def test_register_component():
3939
overwrite = 1
4040
iris_classname = 'UnitTest.EmailOperation'
4141
result = _Utils.register_component(module, classname, path, overwrite, iris_classname)
42-
expect = 1
43-
44-
assert result == expect
4542

4643
def test_register_folder():
4744
path = os.path.dirname(os.path.realpath(__file__))

0 commit comments

Comments
 (0)