Skip to content

Commit f401981

Browse files
committed
Unit tests for check_if_jupyter()
1 parent af9a468 commit f401981

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/sasctl/utils/misc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,5 @@ def check_if_jupyter() -> bool:
8888
return False
8989
else:
9090
return False
91-
except NameError:
91+
except (ImportError, NameError):
9292
return False

tests/unit/test_misc_utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# SPDX-License-Identifier: Apache-2.0
66

77
import re
8-
8+
from unittest.mock import patch, PropertyMock
99

1010
def test_list_packages():
1111
from sasctl.utils.misc import installed_packages
@@ -18,3 +18,13 @@ def test_list_packages():
1818
re.match("sasctl.*", p) for p in packages
1919
) # sasctl may be installed from disk so no '=='
2020
assert any(re.match("pytest==.*", p) for p in packages)
21+
22+
23+
def test_check_if_jupyter():
24+
"""
25+
Test Cases:
26+
- can't mock get_ipython() attributes; so only test for ImportError or NameError
27+
"""
28+
from sasctl.utils.misc import check_if_jupyter
29+
30+
assert not check_if_jupyter()

0 commit comments

Comments
 (0)