@@ -83,8 +83,8 @@ def test_cluster_apply_down_buttons(mocker):
8383
8484@patch .dict ("os.environ" , {}, clear = True ) # Mock environment with no variables
8585def test_is_notebook_false ():
86- # Also mock get_ipython to return None
87- with patch ("codeflare_sdk.common.widgets.widgets .get_ipython" , return_value = None ):
86+ # Mock get_ipython to return None (no IPython shell)
87+ with patch ("IPython .get_ipython" , return_value = None ):
8888 assert cf_widgets .is_notebook () is False
8989
9090
@@ -101,9 +101,7 @@ def test_is_notebook_with_zmq_shell():
101101 mock_shell = MagicMock ()
102102 mock_shell .__class__ .__name__ = "ZMQInteractiveShell"
103103
104- with patch (
105- "codeflare_sdk.common.widgets.widgets.get_ipython" , return_value = mock_shell
106- ):
104+ with patch ("IPython.get_ipython" , return_value = mock_shell ):
107105 assert cf_widgets .is_notebook () is True
108106
109107
@@ -113,9 +111,7 @@ def test_is_notebook_with_terminal_shell():
113111 mock_shell = MagicMock ()
114112 mock_shell .__class__ .__name__ = "TerminalInteractiveShell"
115113
116- with patch (
117- "codeflare_sdk.common.widgets.widgets.get_ipython" , return_value = mock_shell
118- ):
114+ with patch ("IPython.get_ipython" , return_value = mock_shell ):
119115 assert cf_widgets .is_notebook () is False
120116
121117
@@ -125,17 +121,14 @@ def test_is_notebook_with_terminal_shell():
125121def test_is_notebook_with_jpy_parent_pid ():
126122 """Test is_notebook returns True when JPY_PARENT_PID env var is set."""
127123 # Mock get_ipython to return None to test env var fallback
128- with patch ("codeflare_sdk.common.widgets.widgets .get_ipython" , return_value = None ):
124+ with patch ("IPython .get_ipython" , return_value = None ):
129125 assert cf_widgets .is_notebook () is True
130126
131127
132128@patch .dict ("os.environ" , {}, clear = True ) # No env vars
133129def test_is_notebook_ipython_import_error ():
134130 """Test is_notebook handles ImportError gracefully."""
135- with patch (
136- "codeflare_sdk.common.widgets.widgets.get_ipython" ,
137- side_effect = ImportError ("No module named 'IPython'" ),
138- ):
131+ with patch .dict ("sys.modules" , {"IPython" : None }):
139132 assert cf_widgets .is_notebook () is False
140133
141134
0 commit comments