1313# limitations under the License.
1414
1515import sys
16- import unittest
1716import unittest .mock as mock
1817import pytest
1918
@@ -139,15 +138,16 @@ def test_get_qcs_objects_for_notebook_auth_fails(engine_mock):
139138 assert result .project_id == 'fake_project'
140139
141140
142- class TestAuthenticateUser ( unittest . TestCase ) :
141+ class TestAuthenticateUser :
143142 """Tests for the public API `get_hardware_engine_and_authenticate_user` which
144143 authenticates the user and returns a production engine instance ."""
145144
146145 @mock .patch .dict ('sys.modules' , {'google.colab' : mock .Mock ()})
147146 def test_authentication_succeeds_no_exceptions_thrown (self ):
148- authenticate_user ("project_id" )
149147 auth_mock = sys .modules ['google.colab' ]
150148
149+ authenticate_user ()
150+
151151 assert auth_mock .auth .authenticate_user .called
152152
153153 @mock .patch .dict ('sys.modules' , {'google.colab' : mock .Mock ()})
@@ -158,9 +158,17 @@ def test_authentication_failure(self):
158158
159159 auth_mock .auth .authenticate_user = mock .Mock (side_effect = Exception ('mock auth failure' ))
160160
161- with self .assertRaises (
162- Exception ,
163- msg = "Authentication failed, you may not have permission to access"
164- + " a hardware Engine. Use a virtual Engine instead." ,
165- ):
161+ with pytest .raises (Exception , match = "mock auth failure" ):
166162 authenticate_user (project_id )
163+
164+ @mock .patch .dict ('sys.modules' , {'google.colab' : mock .Mock ()})
165+ @pytest .mark .parametrize ('clear_output' , ([True , False ]))
166+ def test_clear_output_is_passed (self , clear_output ):
167+ auth_mock = sys .modules ['google.colab' ]
168+
169+ with mock .patch .object (
170+ auth_mock .auth , 'authenticate_user' , return_value = None
171+ ) as mock_authenticate_user :
172+ authenticate_user (clear_output )
173+
174+ mock_authenticate_user .assert_called_with (clear_output = clear_output )
0 commit comments