@@ -233,17 +233,21 @@ def test_project_create_w_parameters_from_file(self):
233233 self .m_client .create .assert_called_once_with (project_id , data = test_data )
234234
235235 @mock .patch ("gerritclient.common.utils.file_exists" , mock .Mock (return_value = True ))
236- def test_project_create_w_parameters_from_bad_file_format_fail (self ):
236+ @mock .patch ("sys.stderr" )
237+ def test_project_create_w_parameters_from_bad_file_format_fail (self , mocked_stderr ):
237238 project_id = "fakes/fake-project"
238239 test_data = {}
239240 expected_path = "/tmp/fakes/bad_file.format"
240241 args = f"project create { project_id } --file { expected_path } "
241242
242243 m_open = mock .mock_open (read_data = json .dumps (test_data ))
243244 with mock .patch ("gerritclient.common.utils.open" , m_open , create = True ):
244- self .assertRaisesRegex (
245- ValueError , "Unsupported data format" , self .exec_command , args
245+ result = self .exec_command (args )
246+ self .assertEqual (1 , result )
247+ stderr_output = "" .join (
248+ call [0 ][0 ] for call in mocked_stderr .write .call_args_list
246249 )
250+ self .assertIn ("Unsupported data format" , stderr_output )
247251
248252 @mock .patch ("sys.stderr" )
249253 def test_project_create_fail (self , mocked_stderr ):
@@ -651,17 +655,21 @@ def test_project_configuration_set(self):
651655 self .m_client .set_config .assert_called_once_with (project_name , data = test_data )
652656
653657 @mock .patch ("gerritclient.common.utils.file_exists" , mock .Mock (return_value = True ))
654- def test_project_configuration_set_from_bad_file_format_fail (self ):
658+ @mock .patch ("sys.stderr" )
659+ def test_project_configuration_set_from_bad_file_format_fail (self , mocked_stderr ):
655660 project_name = "fakes/fake-project"
656661 test_data = {}
657662 expected_path = "/tmp/fakes/bad_file.format"
658663 args = f"project configuration set { project_name } --file { expected_path } "
659664
660665 m_open = mock .mock_open (read_data = json .dumps (test_data ))
661666 with mock .patch ("gerritclient.common.utils.open" , m_open , create = True ):
662- self .assertRaisesRegex (
663- ValueError , "Unsupported data format" , self .exec_command , args
667+ result = self .exec_command (args )
668+ self .assertEqual (1 , result )
669+ stderr_output = "" .join (
670+ call [0 ][0 ] for call in mocked_stderr .write .call_args_list
664671 )
672+ self .assertIn ("Unsupported data format" , stderr_output )
665673
666674 @mock .patch ("sys.stderr" )
667675 def test_project_configuration_set_fail (self , mocked_stderr ):
0 commit comments