1717import os
1818import sys
1919import unittest
20- from unittest .mock import patch
2120
2221# Conditional import for StringIO
2322try :
2928from core .src .bootstrap .Constants import Constants
3029from core .tests .library .RuntimeCompositor import RuntimeCompositor
3130
32-
3331class TestDnfPackageManager (unittest .TestCase ):
3432 def setUp (self ):
3533 self .runtime = RuntimeCompositor (ArgumentComposer ().get_composed_arguments (), True , Constants .DNF )
@@ -38,20 +36,11 @@ def setUp(self):
3836 def tearDown (self ):
3937 self .runtime .stop ()
4038
41- def mock_run_command_output_return_dnf (self , cmd , no_output = False , chk_err = True ):
42- """ Mock for run_command_output to return dnf """
43- return 0 , "3.5.8-3\n "
44-
45- def mock_run_command_output_return_1 (self , cmd , no_output = False , chk_err = True ):
46- """ Mock for run_command_output to return None """
47- return 1 , "No output available\n "
48-
4939 def __assert_std_io (self , captured_output , expected_output = '' ):
5040 output = captured_output .getvalue ()
5141 self .assertTrue (expected_output in output )
5242
53- # region Mocks
54- def mock_do_processes_require_restart_raise_exception (self ):
43+ def mock_write_with_retry_raise_exception (self , file_path_or_handle , data , mode = 'a+' ):
5544 raise Exception
5645
5746 def test_refresh_repo (self ):
@@ -466,36 +455,6 @@ def __assert_reverted_automatic_patch_configuration_settings(
466455 override_content = self .runtime .env_layer .file_system .read_with_retry (override_file )
467456 self .assertTrue (override_content is not None )
468457
469- # download_updates assertions
470- if "download_updates = yes" in config_value_expected :
471- # self.assertTrue("--downloadupdates" in override_content)
472- self .assertFalse ("--no-downloadupdates" in override_content )
473-
474- elif "download_updates = no" in config_value_expected :
475- # "no" or empty both mean we should not have the positive flag
476- self .assertTrue ("--downloadupdates" not in override_content )
477-
478- else :
479- self .assertTrue (
480- "--downloadupdates" not in override_content and
481- "--no-downloadupdates" not in override_content
482- )
483-
484- # apply_updates assertions
485- if "apply_updates = yes" in config_value_expected :
486- # self.assertTrue("--installupdates" in override_content)
487- self .assertFalse ("--no-installupdates" in override_content )
488-
489- elif "apply_updates = no" in config_value_expected :
490- # "no" or empty both mean we should not have the positive flag
491- self .assertTrue ("--installupdates" not in override_content )
492-
493- else :
494- self .assertTrue (
495- "--installupdates" not in override_content and
496- "--no-installupdates" not in override_content
497- )
498-
499458 @staticmethod
500459 def __capture_std_io ():
501460 # arrange capture std IO
@@ -613,6 +572,13 @@ def test_is_reboot_pending_dnf5(self):
613572 self .assertTrue (package_manager is not None )
614573 self .assertFalse (package_manager .is_reboot_pending ())
615574
575+ # Exception Path
576+ self .runtime .set_legacy_test_type ('HappyPath' )
577+ package_manager = self .container .get ('package_manager' )
578+ self .assertTrue (package_manager is not None )
579+ self .runtime .env_layer .file_system .write_with_retry = self .mock_write_with_retry_raise_exception
580+ self .assertRaises (Exception , package_manager .is_reboot_pending ())
581+
616582 def test_get_current_auto_os_patch_state_disabled_dnf5 (self ):
617583 self .runtime .set_legacy_test_type ('SadPath' )
618584
@@ -945,20 +911,47 @@ def test_set_dnf5_automatic_execstart_flags_exception_handling(self):
945911 """Test exception handling when override file write fails"""
946912 self .runtime .set_legacy_test_type ('HappyPath' )
947913 package_manager = self .container .get ('package_manager' )
914+ # Mock file_system.write_with_retry to raise exception
915+ self .runtime .env_layer .file_system .write_with_retry = self .mock_write_with_retry_raise_exception
916+ self .assertRaises (Exception , package_manager ._Dnf5PackageManager__set_dnf5_automatic_execstart_flags ,)
917+
918+ def test_update_os_patch_configuration_sub_setting_exception_handling (self ):
919+ """Test exception handling when override file write fails"""
920+ self .runtime .set_legacy_test_type ('HappyPath' )
921+ package_manager = self .container .get ('package_manager' )
922+ # Mock file_system.write_with_retry to raise exception
923+ self .runtime .env_layer .file_system .write_with_retry = self .mock_write_with_retry_raise_exception
924+ self .assertRaises (Exception , package_manager .update_os_patch_configuration_sub_setting , )
948925
926+ def test_backup_image_default_patch_configuration_if_not_exists_exception_handling (self ):
927+ """Test exception handling when override file write fails"""
928+ self .runtime .set_legacy_test_type ('HappyPath' )
929+ package_manager = self .container .get ('package_manager' )
949930 # Mock file_system.write_with_retry to raise exception
950- with patch . object ( package_manager .env_layer .file_system , ' write_with_retry' ) as mock_write :
951- mock_write . side_effect = IOError ( "Permission denied" )
931+ self . runtime .env_layer .file_system . write_with_retry = self . mock_write_with_retry_raise_exception
932+ self . assertRaises ( Exception , package_manager . backup_image_default_patch_configuration_if_not_exists , )
952933
953- # Should raise exception caught by outer try-except
954- self .assertRaises (Exception , package_manager ._Dnf5PackageManager__set_dnf5_automatic_execstart_flags ,
955- download_updates = False , apply_updates = False )
956934
957935 def test_get_package_install_expected_avg_time_in_seconds (self ):
958936 self .runtime .set_legacy_test_type ('HappyPath' )
959937 package_manager = self .container .get ('package_manager' )
960938 self .assertTrue (package_manager .get_package_install_expected_avg_time_in_seconds (), 90 )
961939
940+ def test_no_op_methods (self ):
941+ """Test all no-op methods execute without error"""
942+ self .runtime .set_legacy_test_type ('HappyPath' )
943+ package_manager = self .container .get ('package_manager' )
944+
945+ # These should all execute without raising exceptions
946+ package_manager .do_processes_require_restart ()
947+ package_manager .set_max_patch_publish_date ()
948+ package_manager .add_arch_dependencies (package_manager , "pkg" , "1.0" , [], [], [], [])
949+ package_manager .set_security_esm_package_status ("op" , [])
950+ package_manager .separate_out_esm_packages ([], [])
951+
952+ self .assertTrue (True )
953+
954+
962955if __name__ == '__main__' :
963956 unittest .main ()
964957
0 commit comments