Skip to content

Commit

Permalink
Exercising the new function in test
Browse files Browse the repository at this point in the history
  • Loading branch information
rameshraghupathy committed Oct 9, 2024
1 parent e8c8b42 commit 9601177
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions tests/reboot_cause_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,25 @@ def test_reboot_cause_history_dpu(self):
result = runner.invoke(show.cli.commands["reboot-cause"].commands["history"], ["DPU0"])
print(result.output)

# Test 'show reboot-cause history -h'
def test_reboot_cause_history_dpu_help(self):
# Test 'get_all_dpus' function
def test_get_all_dpus(self):
# Mock is_smartswitch to return True
with mock.patch("show.reboot_cause.is_smartswitch", return_value=True):
# Mock the open() call to simulate platform.json contents
mock_platform_data = '{"DPUS": {"dpu0": {}, "dpu1": {}}}'
with mock.patch("builtins.open", mock.mock_open(read_data=mock_platform_data)):
# Mock json.load to return the parsed JSON data
with mock.patch("json.load", return_value=json.loads(mock_platform_data)):
runner = CliRunner()
result = runner.invoke(show.cli.commands["reboot-cause"].commands["history"], ["-h"])
print(result.output)
# Assert that the help message is displayed correctly
# assert result.exit_code == 0, f"Exp 0, got {result.exit_code}. Output: {result.output}"
# assert "Usage" in result.output, f"Output contained Usage: {result.output}"
# Import the actual get_all_dpus function and invoke it
from show.reboot_cause import get_all_dpus
dpu_list = get_all_dpus()

# Assert the returned list contains expected DPUs, 'all', and 'SWITCH'
assert 'DPU0' in dpu_list
assert 'DPU1' in dpu_list
assert 'all' in dpu_list
assert 'SWITCH' in dpu_list


# Test 'show reboot-cause all on smartswitch'
def test_reboot_cause_all(self):
Expand Down

0 comments on commit 9601177

Please sign in to comment.