Skip to content

Commit

Permalink
fix the mock patch function
Browse files Browse the repository at this point in the history
  • Loading branch information
sujinmkang committed Aug 17, 2022
1 parent 7c8003d commit 53ad7cd
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions tests/determine-reboot-cause_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,33 +119,33 @@ def test_get_reboot_cause_dict_kernel_panic(self):
assert reboot_cause_dict == EXPECTED_KERNEL_PANIC_REBOOT_CAUSE_DICT

def test_determine_reboot_cause_hardware(self):
with mock.patch("determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value="Unknown"):
with mock.patch("determine_reboot_cause.find_software_reboot_cause", return_value="Power Cycle"):
with mock.patch("determine_reboot_cause.find_hardware_reboot_cause", return_value="Unknown"):
with mock.patch("determine_reboot_cause.determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value="Unknown"):
with mock.patch("determine_reboot_cause.determine_reboot_cause.find_software_reboot_cause", return_value="Power Cycle"):
with mock.patch("determine_reboot_cause.determine_reboot_cause.find_hardware_reboot_cause", return_value="Unknown"):
previous_reboot_cause, additional_info = determine_reboot_cause.determine_reboot_cause()
assert previous_reboot_cause == "Power Cycle"
assert additional_info == "N/A"

def test_determine_reboot_cause_software(self):
with mock.patch("determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value="Unknown"):
with mock.patch("determine_reboot_cause.find_software_reboot_cause", return_value=EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER):
with mock.patch("determine_reboot_cause.find_hardware_reboot_cause", return_value="Unknown"):
with mock.patch("determine_reboot_cause.determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value="Unknown"):
with mock.patch("determine_reboot_cause.determine_reboot_cause.find_software_reboot_cause", return_value=EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER):
with mock.patch("determine_reboot_cause.determine_reboot_cause.find_hardware_reboot_cause", return_value="Unknown"):
previous_reboot_cause, additional_info = determine_reboot_cause.determine_reboot_cause()
assert previous_reboot_cause == EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER
assert additional_info == "N/A"

def test_determine_reboot_cause_cmdline(self):
with mock.patch("determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value=EXPECTED_PARSE_WARMFAST_REBOOT_FROM_PROC_CMDLINE):
with mock.patch("determine_reboot_cause.find_software_reboot_cause", return_value=EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER):
with mock.patch("determine_reboot_cause.find_hardware_reboot_cause", return_value="Unknown"):
with mock.patch("determine_reboot_cause.determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value=EXPECTED_PARSE_WARMFAST_REBOOT_FROM_PROC_CMDLINE):
with mock.patch("determine_reboot_cause.determine_reboot_cause.find_software_reboot_cause", return_value=EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER):
with mock.patch("determine_reboot_cause.determine_reboot_cause.find_hardware_reboot_cause", return_value="Unknown"):
previous_reboot_cause, additional_info = determine_reboot_cause.determine_reboot_cause()
assert previous_reboot_cause == EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER
assert additional_info == "N/A"

def test_determine_reboot_cause_cmdline_hardware(self):
with mock.patch("determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value=EXPECTED_PARSE_WARMFAST_REBOOT_FROM_PROC_CMDLINE):
with mock.patch("determine_reboot_cause.find_software_reboot_cause", return_value=EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER):
with mock.patch("determine_reboot_cause.find_hardware_reboot_cause", return_value=REBOOT_CAUSE_WATCHDOG):
with mock.patch("determine_reboot_cause.determine_reboot_cause.find_proc_cmdline_reboot_cause", return_value=EXPECTED_PARSE_WARMFAST_REBOOT_FROM_PROC_CMDLINE):
with mock.patch("determine_reboot_cause.determine_reboot_cause.find_software_reboot_cause", return_value=EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER):
with mock.patch("determine_reboot_cause.determine_reboot_cause.find_hardware_reboot_cause", return_value=REBOOT_CAUSE_WATCHDOG):
previous_reboot_cause, additional_info = determine_reboot_cause.determine_reboot_cause()
assert previous_reboot_cause == REBOOT_CAUSE_WATCHDOG
assert additional_info == EXPECTED_FIND_SOFTWARE_REBOOT_CAUSE_USER
Expand Down

0 comments on commit 53ad7cd

Please sign in to comment.