diff --git a/integration/combination/test_function_with_cwe_dlq_generated.py b/integration/combination/test_function_with_cwe_dlq_generated.py index 52975df02..34296e205 100644 --- a/integration/combination/test_function_with_cwe_dlq_generated.py +++ b/integration/combination/test_function_with_cwe_dlq_generated.py @@ -36,7 +36,7 @@ def test_function_with_cwe(self): # checking policy action actions = dlq_policy_statement["Action"] - action_list = actions if type(actions) == list else [actions] + action_list = actions if isinstance(actions, list) == list else [actions] self.assertEqual(len(action_list), 1, "Only one action must be in dead-letter queue policy") self.assertEqual( action_list[0], "sqs:SendMessage", "Action referenced in dead-letter queue policy must be 'sqs:SendMessage'" diff --git a/integration/combination/test_function_with_policy_templates.py b/integration/combination/test_function_with_policy_templates.py index a73c384d5..e5746ec39 100644 --- a/integration/combination/test_function_with_policy_templates.py +++ b/integration/combination/test_function_with_policy_templates.py @@ -14,7 +14,7 @@ def test_with_policy_templates(self): self.assertEqual(len(sqs_poller_policy), 1, "Only one statement must be in SQS Poller policy") sqs_policy_statement = sqs_poller_policy[0] - self.assertTrue(type(sqs_policy_statement["Resource"]) != list) + self.assertFalse(isinstance(sqs_policy_statement["Resource"], list)) queue_url = self.get_physical_id_by_type("AWS::SQS::Queue") parts = queue_url.split("/") @@ -32,7 +32,7 @@ def test_with_policy_templates(self): self.assertEqual(len(lambda_invoke_policy), 1, "One policies statements should be present") lambda_policy_statement = lambda_invoke_policy[0] - self.assertTrue(type(lambda_policy_statement["Resource"]) != list) + self.assertFalse(isinstance(lambda_policy_statement["Resource"], list)) # NOTE: The resource ARN has "*" suffix to allow for any Lambda function version as well expected_function_suffix = "function:somename*" diff --git a/integration/combination/test_state_machine_with_api.py b/integration/combination/test_state_machine_with_api.py index c75cf5646..19b7cfa4c 100644 --- a/integration/combination/test_state_machine_with_api.py +++ b/integration/combination/test_state_machine_with_api.py @@ -75,7 +75,7 @@ def _test_api_integration_with_state_machine( start_execution_policy_statement = start_execution_policy[0] - self.assertTrue(type(start_execution_policy_statement["Action"]) != list) + self.assertFalse(isinstance(start_execution_policy_statement["Action"], list)) policy_action = start_execution_policy_statement["Action"] self.assertEqual( policy_action, @@ -83,7 +83,7 @@ def _test_api_integration_with_state_machine( "Action referenced in event role policy must be 'states:StartExecution'", ) - self.assertTrue(type(start_execution_policy_statement["Resource"]) != list) + self.assertFalse(isinstance(start_execution_policy_statement["Resource"], list)) referenced_state_machine_arn = start_execution_policy_statement["Resource"] self.assertEqual( referenced_state_machine_arn, diff --git a/integration/combination/test_state_machine_with_cwe.py b/integration/combination/test_state_machine_with_cwe.py index 84e166381..29ab63b6a 100644 --- a/integration/combination/test_state_machine_with_cwe.py +++ b/integration/combination/test_state_machine_with_cwe.py @@ -34,7 +34,7 @@ def test_state_machine_with_cwe(self): start_execution_policy_statement = start_execution_policy[0] - self.assertTrue(type(start_execution_policy_statement["Action"]) != list) + self.assertFalse(isinstance(start_execution_policy_statement["Action"], list)) policy_action = start_execution_policy_statement["Action"] self.assertEqual( policy_action, @@ -42,7 +42,7 @@ def test_state_machine_with_cwe(self): "Action referenced in event role policy must be 'states:StartExecution'", ) - self.assertTrue(type(start_execution_policy_statement["Resource"]) != list) + self.assertFalse(isinstance(start_execution_policy_statement["Resource"], list)) referenced_state_machine_arn = start_execution_policy_statement["Resource"] self.assertEqual( referenced_state_machine_arn, diff --git a/integration/combination/test_state_machine_with_cwe_dlq_generated.py b/integration/combination/test_state_machine_with_cwe_dlq_generated.py index a45638dc0..5ee69ad27 100644 --- a/integration/combination/test_state_machine_with_cwe_dlq_generated.py +++ b/integration/combination/test_state_machine_with_cwe_dlq_generated.py @@ -37,7 +37,7 @@ def test_state_machine_with_cwe(self): start_execution_policy_statement = start_execution_policy[0] - self.assertTrue(type(start_execution_policy_statement["Action"]) != list) + self.assertFalse(isinstance(start_execution_policy_statement["Action"], list)) policy_action = start_execution_policy_statement["Action"] self.assertEqual( policy_action, @@ -45,7 +45,7 @@ def test_state_machine_with_cwe(self): "Action referenced in event role policy must be 'states:StartExecution'", ) - self.assertTrue(type(start_execution_policy_statement["Resource"]) != list) + self.assertFalse(isinstance(start_execution_policy_statement["Resource"], list)) referenced_state_machine_arn = start_execution_policy_statement["Resource"] self.assertEqual( referenced_state_machine_arn, diff --git a/integration/combination/test_state_machine_with_policy_templates.py b/integration/combination/test_state_machine_with_policy_templates.py index 7864f6d7f..b63c69493 100644 --- a/integration/combination/test_state_machine_with_policy_templates.py +++ b/integration/combination/test_state_machine_with_policy_templates.py @@ -22,7 +22,7 @@ def test_with_policy_templates(self): self.assertEqual(len(sqs_poller_policy), 1, "Only one statement must be in SQS Poller policy") sqs_policy_statement = sqs_poller_policy[0] - self.assertTrue(type(sqs_policy_statement["Resource"]) != list) + self.assertFalse(isinstance(sqs_policy_statement["Resource"], list)) queue_url = self.get_physical_id_by_type("AWS::SQS::Queue") parts = queue_url.split("/") @@ -40,7 +40,7 @@ def test_with_policy_templates(self): self.assertEqual(len(lambda_invoke_policy), 1, "One policies statements should be present") lambda_policy_statement = lambda_invoke_policy[0] - self.assertTrue(type(lambda_policy_statement["Resource"]) != list) + self.assertFalse(isinstance(lambda_policy_statement["Resource"], list)) function_name = self.get_physical_id_by_type("AWS::Lambda::Function") # NOTE: The resource ARN has "*" suffix to allow for any Lambda function version as well diff --git a/integration/combination/test_state_machine_with_schedule.py b/integration/combination/test_state_machine_with_schedule.py index 7ca85933a..01fb0612d 100644 --- a/integration/combination/test_state_machine_with_schedule.py +++ b/integration/combination/test_state_machine_with_schedule.py @@ -45,7 +45,7 @@ def test_state_machine_with_schedule(self, template_file_path): start_execution_policy_statement = start_execution_policy[0] - self.assertTrue(type(start_execution_policy_statement["Action"]) != list) + self.assertFalse(isinstance(start_execution_policy_statement["Action"], list)) policy_action = start_execution_policy_statement["Action"] self.assertEqual( policy_action, @@ -53,7 +53,7 @@ def test_state_machine_with_schedule(self, template_file_path): "Action referenced in event role policy must be 'states:StartExecution'", ) - self.assertTrue(type(start_execution_policy_statement["Resource"]) != list) + self.assertFalse(isinstance(start_execution_policy_statement["Resource"], list)) referenced_state_machine_arn = start_execution_policy_statement["Resource"] self.assertEqual( referenced_state_machine_arn, diff --git a/integration/combination/test_state_machine_with_schedule_dlq_and_retry_policy.py b/integration/combination/test_state_machine_with_schedule_dlq_and_retry_policy.py index 5cc1a190c..5ea7309c1 100644 --- a/integration/combination/test_state_machine_with_schedule_dlq_and_retry_policy.py +++ b/integration/combination/test_state_machine_with_schedule_dlq_and_retry_policy.py @@ -46,7 +46,7 @@ def test_state_machine_with_schedule(self): start_execution_policy_statement = start_execution_policy[0] - self.assertTrue(type(start_execution_policy_statement["Action"]) != list) + self.assertFalse(isinstance(start_execution_policy_statement["Action"], list)) policy_action = start_execution_policy_statement["Action"] self.assertEqual( policy_action, @@ -54,7 +54,7 @@ def test_state_machine_with_schedule(self): "Action referenced in event role policy must be 'states:StartExecution'", ) - self.assertTrue(type(start_execution_policy_statement["Resource"]) != list) + self.assertFalse(isinstance(start_execution_policy_statement["Resource"], list)) referenced_state_machine_arn = start_execution_policy_statement["Resource"] self.assertEqual( referenced_state_machine_arn, diff --git a/integration/helpers/resource.py b/integration/helpers/resource.py index e8ecb6ae9..604f31766 100644 --- a/integration/helpers/resource.py +++ b/integration/helpers/resource.py @@ -206,8 +206,7 @@ def _resource_using_s3_events(resource: Dict[str, Any]) -> bool: def _get_all_event_sources(template_dict: Dict[str, Any]) -> Iterator[Dict[str, Any]]: resources = template_dict.get("Resources", {}).values() for resource in resources: - for event in resource.get("Properties", {}).get("Events", {}).values(): - yield event + yield from resource.get("Properties", {}).get("Events", {}).values() def _event_using_sns_filter_policy_scope(event: Dict[str, Any]) -> bool: diff --git a/requirements/dev.txt b/requirements/dev.txt index 15caa7fa6..de81b0cf7 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -4,7 +4,7 @@ pytest-xdist>=2.5,<4 pytest-env>=0.6,<1 pytest-rerunfailures>=9.1,<12 pyyaml~=6.0 -ruff==0.0.284 # loose the requirement once it is more stable +ruff~=0.1.0 # Test requirements pytest>=6.2,<8