Skip to content

Commit

Permalink
Precommit and fix tests for Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-harvey-z3q committed Jun 23, 2024
1 parent f1727d8 commit 7f8810f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
5 changes: 4 additions & 1 deletion sceptre/cli/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def update_command(

for status in list(statuses.values()):
# Exit if change set fails to create
if status not in (StackChangeSetStatus.READY, StackChangeSetStatus.NO_CHANGES):
if status not in (
StackChangeSetStatus.READY,
StackChangeSetStatus.NO_CHANGES,
):
write("Failed to create change set", context.output_format)
exit(1)

Expand Down
19 changes: 9 additions & 10 deletions sceptre/plan/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,18 +925,17 @@ def _get_cs_status(self, change_set_name):
] and cs_exec_status in ["UNAVAILABLE", "AVAILABLE"]:
return StackChangeSetStatus.PENDING
elif (
cs_status == "FAILED" and
cs_reason is not None and
self.change_set_creation_failed_due_to_no_changes(cs_reason)
cs_status == "FAILED"
and cs_reason is not None
and self.change_set_creation_failed_due_to_no_changes(cs_reason)
):
return StackChangeSetStatus.NO_CHANGES
elif (
cs_status in ["DELETE_COMPLETE", "FAILED"] or
cs_exec_status in [
"EXECUTE_IN_PROGRESS", "EXECUTE_COMPLETE",
"EXECUTE_FAILED", "OBSOLETE"
]
):
elif cs_status in ["DELETE_COMPLETE", "FAILED"] or cs_exec_status in [
"EXECUTE_IN_PROGRESS",
"EXECUTE_COMPLETE",
"EXECUTE_FAILED",
"OBSOLETE",
]:
return StackChangeSetStatus.DEFUNCT
else: # pragma: no cover
raise Exception("This else should not be reachable.")
Expand Down
8 changes: 3 additions & 5 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,12 +1169,10 @@ def test_get_cs_status_handles_all_statuses(self, mock_describe_change_set):
mock_describe_change_set.return_value = {
"Status": "FAILED",
"StatusReason": "The submitted information didn't contain changes. "
"Submit different information to create a change set.",
"ExecutionStatus": "UNAVAILABLE"
"Submit different information to create a change set.",
"ExecutionStatus": "UNAVAILABLE",
}
response = self.actions._get_cs_status(
sentinel.change_set_name
)
response = self.actions._get_cs_status(sentinel.change_set_name)
assert response == scss.NO_CHANGES

for status in return_values["Status"]:
Expand Down
26 changes: 15 additions & 11 deletions tests/test_cli/test_cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,8 @@ def test_stack_commands(self, command, success, yes_flag, exit_code):
assert result.exit_code == exit_code

@pytest.mark.parametrize(
"change_set_status,yes_flag,exit_code,verbose_flag", [
"change_set_status,yes_flag,exit_code,verbose_flag",
[
(StackChangeSetStatus.READY, True, 0, True),
(StackChangeSetStatus.READY, True, 0, False),
(StackChangeSetStatus.READY, False, 0, True),
Expand All @@ -528,9 +529,11 @@ def test_stack_commands(self, command, success, yes_flag, exit_code):
(StackChangeSetStatus.DEFUNCT, False, 1, False),
(StackChangeSetStatus.DEFUNCT, True, 1, False),
(StackChangeSetStatus.DEFUNCT, False, 1, True),
]
],
)
def test_update_with_change_set(self, change_set_status, yes_flag, exit_code, verbose_flag):
def test_update_with_change_set(
self, change_set_status, yes_flag, exit_code, verbose_flag
):
create_command = self.mock_stack_actions.create_change_set
wait_command = self.mock_stack_actions.wait_for_cs_completion
execute_command = self.mock_stack_actions.execute_change_set
Expand All @@ -556,10 +559,10 @@ def test_update_with_change_set(self, change_set_status, yes_flag, exit_code, ve
"Replacement": "Replacement",
"ResourceType": "ResourceType",
"Scope": "Scope",
"VerboseProperty": "VerboseProperty"
"VerboseProperty": "VerboseProperty",
}
}
]
],
}

if not verbose_flag:
Expand All @@ -581,14 +584,14 @@ def test_update_with_change_set(self, change_set_status, yes_flag, exit_code, ve
result = self.runner.invoke(cli, **kwargs)

change_set_name = create_command.call_args[0][0]
assert 'change-set' in change_set_name
assert "change-set" in change_set_name

assert wait_command.called_with(change_set_name)
assert delete_command.called_with(change_set_name)
wait_command.assert_called_once_with(change_set_name)
delete_command.assert_called_once_with(change_set_name)

if change_set_status == StackChangeSetStatus.READY:
assert execute_command.called_with(change_set_name)
assert describe_command.called_with(change_set_name)
execute_command.assert_called_once_with(change_set_name)
describe_command.assert_called_once_with(change_set_name)
output = result.output.splitlines()[0]
assert yaml.safe_load(output) == response

Expand All @@ -601,7 +604,8 @@ def test_update_with_change_set(self, change_set_status, yes_flag, exit_code, ve
assert result.exit_code == exit_code

@pytest.mark.parametrize(
"command, ignore_dependencies", [
"command, ignore_dependencies",
[
("create", True),
("create", False),
("delete", True),
Expand Down

0 comments on commit 7f8810f

Please sign in to comment.