Skip to content

Commit

Permalink
chore: Enable linting for tests and integration (#2895)
Browse files Browse the repository at this point in the history
  • Loading branch information
aahung authored Feb 11, 2023
1 parent d39192c commit 7cc3003
Show file tree
Hide file tree
Showing 139 changed files with 369 additions and 378 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ init:
pip install -e '.[dev]'

test:
AWS_DEFAULT_REGION=us-east-1 pytest --cov samtranslator --cov-report term-missing --cov-fail-under 95 -n auto tests/*
AWS_DEFAULT_REGION=us-east-1 pytest --cov samtranslator --cov-report term-missing --cov-fail-under 95 -n auto tests/

test-fast:
pytest -x --cov samtranslator --cov-report term-missing --cov-fail-under 95 -n auto tests/*
pytest -x --cov samtranslator --cov-report term-missing --cov-fail-under 95 -n auto tests/

test-cov-report:
pytest --cov samtranslator --cov-report term-missing --cov-report html --cov-fail-under 95 tests/*
pytest --cov samtranslator --cov-report term-missing --cov-report html --cov-fail-under 95 tests/

integ-test:
pytest --no-cov integration/*

black:
black setup.py samtranslator/* tests/* integration/* bin/*.py schema_source
black setup.py samtranslator tests integration bin schema_source
bin/json-format.py --write tests integration samtranslator/policy_templates_data
bin/yaml-format.py --write tests
bin/yaml-format.py --write integration --add-test-metadata
Expand All @@ -29,20 +29,20 @@ black-check:
python -m schema_source.schema --sam-schema .tmp/sam.schema.json --cfn-schema schema_source/cloudformation.schema.json --unified-schema .tmp/schema.json
diff -u schema_source/sam.schema.json .tmp/sam.schema.json
diff -u samtranslator/schema/schema.json .tmp/schema.json
black --check setup.py samtranslator/* tests/* integration/* bin/*.py schema_source
black --check setup.py samtranslator tests integration bin schema_source
bin/json-format.py --check tests integration samtranslator/policy_templates_data
bin/yaml-format.py --check tests
bin/yaml-format.py --check integration --add-test-metadata

lint:
ruff samtranslator bin schema_source
ruff samtranslator bin schema_source integration tests
# mypy performs type check
mypy --strict samtranslator bin schema_source
# cfn-lint to make sure generated CloudFormation makes sense
bin/run_cfn_lint.sh

lint-fix:
ruff --fix samtranslator bin schema_source
ruff --fix samtranslator bin schema_source integration tests

prepare-companion-stack:
pytest -v --no-cov integration/setup -m setup
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_api_settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import hashlib
from unittest.case import skipIf

from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import REST_API
from integration.helpers.resource import current_region_does_not_support

try:
from pathlib import Path
Expand Down
4 changes: 1 addition & 3 deletions integration/combination/test_api_with_authorizer_apikey.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from unittest.case import skipIf

from integration.config.service_names import API_KEY, REST_API
from integration.helpers.base_test import BaseTest
from integration.helpers.deployer.utils.retry import retry
from integration.helpers.exception import StatusCodeError


from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import REST_API, API_KEY


@skipIf(current_region_does_not_support([REST_API, API_KEY]), "RestApi/ApiKey is not supported in this testing region")
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_api_with_authorizers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from unittest.case import skipIf

from integration.config.service_names import API_KEY, COGNITO, REST_API
from integration.helpers.base_test import BaseTest
from integration.helpers.deployer.utils.retry import retry
from integration.helpers.exception import StatusCodeError
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import API_KEY, COGNITO, REST_API


@skipIf(
Expand Down
8 changes: 3 additions & 5 deletions integration/combination/test_api_with_cors.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from integration.helpers.base_test import BaseTest
import requests
from unittest.case import skipIf

from parameterized import parameterized

from integration.config.service_names import REST_API
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import REST_API
from integration.helpers.deployer.utils.retry import retry
from parameterized import parameterized

ALL_METHODS = "DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from unittest.case import skipIf

from parameterized import parameterized

from integration.config.service_names import REST_API
from integration.helpers.base_test import BaseTest


from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import REST_API


@skipIf(current_region_does_not_support([REST_API]), "RestApi is not supported in this testing region")
Expand Down Expand Up @@ -41,7 +40,7 @@ def test_end_point_configuration(self, file_name, disable_value):
("combination/api_with_disable_execute_api_endpoint_openapi_3", False),
]
)
def test_end_point_configuration(self, file_name, disable_value):
def test_end_point_configuration_openapi(self, file_name, disable_value):
parameters = [
{
"ParameterKey": "DisableExecuteApiEndpointValue",
Expand Down
3 changes: 2 additions & 1 deletion integration/combination/test_api_with_fail_on_warnings.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from unittest.case import skipIf

from parameterized import parameterized

from integration.config.service_names import REST_API
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import REST_API


@skipIf(current_region_does_not_support([REST_API]), "RestApi is not supported in this testing region")
Expand Down
4 changes: 2 additions & 2 deletions integration/combination/test_api_with_gateway_responses.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logging
from unittest.case import skipIf

from tenacity import stop_after_attempt, retry_if_exception_type, after_log, wait_exponential, retry, wait_random
from tenacity import after_log, retry, retry_if_exception_type, stop_after_attempt, wait_exponential, wait_random

from integration.config.service_names import GATEWAY_RESPONSES, REST_API
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import GATEWAY_RESPONSES, REST_API

LOG = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_api_with_resource_policies.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
from unittest.case import skipIf

from integration.config.service_names import REST_API
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import REST_API


@skipIf(current_region_does_not_support([REST_API]), "Rest API is not supported in this testing region")
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_api_with_usage_plan.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.case import skipIf

from integration.config.service_names import REST_API, USAGE_PLANS
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import USAGE_PLANS, REST_API


@skipIf(current_region_does_not_support([USAGE_PLANS, REST_API]), "UsagePlans is not supported in this testing region")
Expand Down
6 changes: 3 additions & 3 deletions integration/combination/test_connectors.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from time import sleep
from unittest import SkipTest

from parameterized import parameterized
from tenacity import retry, stop_after_attempt, retry_if_exception
from tenacity import retry, retry_if_exception, stop_after_attempt

from integration.conftest import clean_bucket
from integration.helpers.base_test import S3_BUCKET_PREFIX, BaseTest
from integration.helpers.resource import generate_suffix
Expand Down Expand Up @@ -93,7 +95,6 @@ def test_connector_by_sync_execute_an_state_machine(self, template_file_path):

state_machine_arn = self.get_physical_id_by_logical_id("TriggerStateMachine")
sfn_client = self.client_provider.sfn_client
s3_client = self.client_provider.s3_client

response = sfn_client.start_sync_execution(
stateMachineArn=state_machine_arn,
Expand Down Expand Up @@ -149,7 +150,6 @@ def test_connector_by_execute_a_s3_bucket(self, template_file_path):

lambda_function_name = self.get_physical_id_by_logical_id("TriggerFunction")
lambda_client = self.client_provider.lambda_client
s3_client = self.client_provider.s3_client

request_params = {
"FunctionName": lambda_function_name,
Expand Down
6 changes: 3 additions & 3 deletions integration/combination/test_function_with_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from unittest.case import skipIf

from botocore.exceptions import ClientError
from integration.helpers.base_test import BaseTest, LOG

from integration.config.service_names import REST_API
from integration.helpers.base_test import LOG, BaseTest
from integration.helpers.common_api import get_function_versions
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import REST_API


class TestFunctionWithAlias(BaseTest):
Expand Down Expand Up @@ -73,7 +74,6 @@ def test_updating_version_by_changing_property_value_additional_properties(self)

def test_alias_deletion_must_retain_version(self):
self.create_and_verify_stack("combination/function_with_alias")
alias_name = "Live"
function_name = self.get_physical_id_by_type("AWS::Lambda::Function")
version_ids = self.get_function_version_by_name(function_name)
self.assertEqual(["1"], version_ids)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.case import skipIf

from integration.config.service_names import IOT, SCHEDULE_EVENT
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support, generate_suffix
from integration.config.service_names import IOT, SCHEDULE_EVENT


@skipIf(
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_function_with_api.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.case import skipIf

from integration.config.service_names import REST_API
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import REST_API


@skipIf(current_region_does_not_support([REST_API]), "Rest API is not supported in this testing region")
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_function_with_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from botocore.exceptions import ClientError

from integration.config.service_names import SERVERLESS_REPO
from integration.helpers.base_test import BaseTest
from integration.helpers.deployer.exceptions.exceptions import ThrottlingError
from integration.helpers.deployer.utils.retry import retry_with_exponential_backoff_and_jitter
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import SERVERLESS_REPO


class TestFunctionWithApplication(BaseTest):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.case import skipIf

from integration.config.service_names import CWE_CWS_DLQ
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import CWE_CWS_DLQ


@skipIf(current_region_does_not_support([CWE_CWS_DLQ]), "CweCwsDlq is not supported in this testing region")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import json
from unittest.case import skipIf

from integration.config.service_names import CWE_CWS_DLQ
from integration.helpers.base_test import BaseTest
from integration.helpers.common_api import get_queue_policy
from integration.helpers.resource import first_item_in_dict, current_region_does_not_support
from integration.config.service_names import CWE_CWS_DLQ
from integration.helpers.resource import current_region_does_not_support, first_item_in_dict


@skipIf(current_region_does_not_support([CWE_CWS_DLQ]), "CweCwsDlq is not supported in this testing region")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.case import skipIf

from integration.config.service_names import CODE_DEPLOY
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support, generate_suffix
from integration.config.service_names import CODE_DEPLOY

CODEDEPLOY_APPLICATION_LOGICAL_ID = "ServerlessDeploymentApplication"
LAMBDA_FUNCTION_NAME = "MyLambdaFunction"
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_function_with_dynamoDB.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.case import skipIf

from integration.config.service_names import DYNAMO_DB
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import DYNAMO_DB


@skipIf(current_region_does_not_support([DYNAMO_DB]), "DynamoDB is not supported in this testing region")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest.case import skipIf

import pytest

from integration.config.service_names import EFS
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_function_with_http_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import pytest

from integration.config.service_names import HTTP_API
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import HTTP_API

LOG = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.case import skipIf

from integration.config.service_names import REST_API
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import REST_API


@skipIf(current_region_does_not_support([REST_API]), "Rest API is not supported in this testing region")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.case import skipIf

from integration.config.service_names import HTTP_API
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import HTTP_API


@skipIf(current_region_does_not_support([HTTP_API]), "HttpApi is not supported in this testing region")
Expand Down
4 changes: 2 additions & 2 deletions integration/combination/test_function_with_kinesis.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.case import skipIf
from parameterized import parameterized

from integration.config.service_names import KINESIS
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import KINESIS


@skipIf(current_region_does_not_support([KINESIS]), "Kinesis is not supported in this testing region")
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_function_with_layers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.case import skipIf

from integration.config.service_names import LAYERS
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import LAYERS


@skipIf(current_region_does_not_support([LAYERS]), "Layers is not supported in this testing region")
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_function_with_mq.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import pytest
from parameterized import parameterized

from integration.config.service_names import MQ
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support, generate_suffix
from integration.config.service_names import MQ


@skipIf(current_region_does_not_support([MQ]), "MQ is not supported in this testing region")
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_function_with_msk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import pytest

from integration.config.service_names import MSK
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support, generate_suffix
from integration.config.service_names import MSK


@skipIf(current_region_does_not_support([MSK]), "MSK is not supported in this testing region")
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_function_with_s3_bucket.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.case import skipIf

from integration.config.service_names import S3_EVENTS
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support
from integration.config.service_names import S3_EVENTS


@skipIf(current_region_does_not_support([S3_EVENTS]), "S3 Events feature is not supported in this testing region")
Expand Down
2 changes: 1 addition & 1 deletion integration/combination/test_function_with_schedule.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from unittest.case import skipIf

from integration.config.service_names import SCHEDULE_EVENT
from integration.helpers.base_test import BaseTest
from integration.helpers.resource import current_region_does_not_support, generate_suffix
from integration.config.service_names import SCHEDULE_EVENT


@skipIf(current_region_does_not_support([SCHEDULE_EVENT]), "ScheduleEvent is not supported in this testing region")
Expand Down
Loading

0 comments on commit 7cc3003

Please sign in to comment.