From 66515dcdd4409ea9fc9e376f244961f178a4327a Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 08:57:47 -0700 Subject: [PATCH 01/42] Remove Py2 support --- setup.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 77265e87df..9c118def11 100644 --- a/setup.py +++ b/setup.py @@ -43,8 +43,8 @@ def read_version(): license="Apache License 2.0", packages=find_packages(exclude=["tests.*", "tests"]), keywords="AWS SAM CLI", - # Support Python 2.7 and 3.6 or greater - python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*", + # Support Python 3.6 or greater + python_requires=">=3.6, <=4.0, !=4.0", entry_points={"console_scripts": ["{}=samcli.cli.main:cli".format(cmd_name)]}, install_requires=read_requirements("base.txt"), extras_require={"dev": read_requirements("dev.txt")}, @@ -58,7 +58,6 @@ def read_version(): "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Internet", From c72e7f4f87f9cedfc294bec05bec89ac711e2c01 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 08:58:45 -0700 Subject: [PATCH 02/42] Remove dependecies needed for Py2 --- requirements/base.txt | 2 -- samcli/cli/global_config.py | 5 +---- samcli/commands/_utils/template.py | 6 +----- samcli/commands/build/build_context.py | 6 +----- samcli/commands/local/cli_common/invoke_context.py | 9 +-------- samcli/commands/local/cli_common/options.py | 6 +----- samcli/lib/build/app_builder.py | 6 +----- samcli/local/common/runtime_template.py | 6 +----- samcli/local/docker/lambda_build_container.py | 6 +----- samcli/local/docker/lambda_image.py | 6 +----- samcli/local/docker/utils.py | 6 +----- samcli/local/lambdafn/zip.py | 6 +----- samcli/local/layers/layer_downloader.py | 6 +----- tests/functional/commands/cli/test_global_config.py | 6 +----- tests/integration/buildcmd/build_integ_base.py | 6 +----- tests/integration/buildcmd/test_build_cmd.py | 6 +----- tests/integration/local/invoke/invoke_integ_base.py | 6 +----- tests/integration/local/invoke/layer_utils.py | 6 +----- .../local/invoke/runtimes/test_with_runtime_zips.py | 6 +----- tests/integration/local/invoke/test_integrations_cli.py | 5 +---- .../integration/local/start_api/start_api_integ_base.py | 6 +----- .../local/start_lambda/start_lambda_api_integ_base.py | 5 +---- tests/integration/publish/publish_app_integ_base.py | 6 +----- tests/integration/telemetry/integ_base.py | 6 +----- tests/unit/cli/test_global_config.py | 6 +----- tests/unit/lib/build_module/test_app_builder.py | 7 +------ .../lib/intrinsic_resolver/test_intrinsic_resolver.py | 6 +----- tests/unit/lib/utils/test_codeuri.py | 5 +---- tests/unit/local/docker/test_lambda_build_container.py | 6 +----- tests/unit/local/layers/test_download_layers.py | 6 +----- 30 files changed, 29 insertions(+), 147 deletions(-) diff --git a/requirements/base.txt b/requirements/base.txt index 39a0699fdf..026dd43d0e 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,7 +1,6 @@ six~=1.11.0 chevron~=0.12 click~=7.0 -enum34~=1.1.6; python_version<"3.4" Flask~=1.0.2 boto3~=1.9, >=1.9.56 PyYAML~=5.1 @@ -10,7 +9,6 @@ aws-sam-translator==1.15.1 docker~=4.0 dateparser~=0.7 python-dateutil~=2.6 -pathlib2~=2.3.2; python_version<"3.4" requests==2.22.0 serverlessrepo==0.1.9 aws_lambda_builders==0.5.0 diff --git a/samcli/cli/global_config.py b/samcli/cli/global_config.py index 539aa2c1a0..b8628eef40 100644 --- a/samcli/cli/global_config.py +++ b/samcli/cli/global_config.py @@ -6,13 +6,10 @@ import logging import uuid import os +from pathlib import Path import click -try: - from pathlib import Path -except ImportError: # pragma: no cover - from pathlib2 import Path # pragma: no cover LOG = logging.getLogger(__name__) diff --git a/samcli/commands/_utils/template.py b/samcli/commands/_utils/template.py index 2b45e2e41e..b395c1d1e4 100644 --- a/samcli/commands/_utils/template.py +++ b/samcli/commands/_utils/template.py @@ -5,11 +5,7 @@ import os import six import yaml - -try: - import pathlib -except ImportError: - import pathlib2 as pathlib +import pathlib from samcli.yamlhelper import yaml_parse, yaml_dump diff --git a/samcli/commands/build/build_context.py b/samcli/commands/build/build_context.py index 5892b8a6f8..4c1f7bd88d 100644 --- a/samcli/commands/build/build_context.py +++ b/samcli/commands/build/build_context.py @@ -5,11 +5,7 @@ import logging import os import shutil - -try: - import pathlib -except ImportError: - import pathlib2 as pathlib +import pathlib from samcli.local.docker.manager import ContainerManager from samcli.commands.local.lib.sam_function_provider import SamFunctionProvider diff --git a/samcli/commands/local/cli_common/invoke_context.py b/samcli/commands/local/cli_common/invoke_context.py index 8d870dbea0..a0894b0453 100644 --- a/samcli/commands/local/cli_common/invoke_context.py +++ b/samcli/commands/local/cli_common/invoke_context.py @@ -17,14 +17,7 @@ from samcli.local.layers.layer_downloader import LayerDownloader from .user_exceptions import InvokeContextException, DebugContextException from ..lib.sam_function_provider import SamFunctionProvider - -# This is an attempt to do a controlled import. pathlib is in the -# Python standard library starting at 3.4. This will import pathlib2, -# which is a backport of the Python Standard Library pathlib -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path class InvokeContext(object): diff --git a/samcli/commands/local/cli_common/options.py b/samcli/commands/local/cli_common/options.py index 4d92c6dffc..84e39d58c7 100644 --- a/samcli/commands/local/cli_common/options.py +++ b/samcli/commands/local/cli_common/options.py @@ -4,11 +4,7 @@ import click from samcli.commands._utils.options import template_click_option, docker_click_options, parameter_override_click_option - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path def get_application_dir(): diff --git a/samcli/lib/build/app_builder.py b/samcli/lib/build/app_builder.py index 3ca2056769..00bdbd8271 100644 --- a/samcli/lib/build/app_builder.py +++ b/samcli/lib/build/app_builder.py @@ -6,11 +6,7 @@ import io import json import logging - -try: - import pathlib -except ImportError: - import pathlib2 as pathlib +import pathlib import docker diff --git a/samcli/local/common/runtime_template.py b/samcli/local/common/runtime_template.py index b76c0ae9a9..02110671e9 100644 --- a/samcli/local/common/runtime_template.py +++ b/samcli/local/common/runtime_template.py @@ -4,11 +4,7 @@ import itertools import os - -try: - import pathlib -except ImportError: - import pathlib2 as pathlib +import pathlib _init_path = str(pathlib.Path(os.path.dirname(__file__)).parent) _templates = os.path.join(_init_path, "init", "templates") diff --git a/samcli/local/docker/lambda_build_container.py b/samcli/local/docker/lambda_build_container.py index ed86f4fb87..3298941cd5 100644 --- a/samcli/local/docker/lambda_build_container.py +++ b/samcli/local/docker/lambda_build_container.py @@ -4,11 +4,7 @@ import json import logging - -try: - import pathlib -except ImportError: - import pathlib2 as pathlib +import pathlib from .container import Container diff --git a/samcli/local/docker/lambda_image.py b/samcli/local/docker/lambda_image.py index 5a991f85fe..7cacc4e008 100644 --- a/samcli/local/docker/lambda_image.py +++ b/samcli/local/docker/lambda_image.py @@ -10,11 +10,7 @@ from samcli.commands.local.cli_common.user_exceptions import ImageBuildException from samcli.lib.utils.tar import create_tarball - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path LOG = logging.getLogger(__name__) diff --git a/samcli/local/docker/utils.py b/samcli/local/docker/utils.py index 2fadc38aa6..a67bc9e9fe 100644 --- a/samcli/local/docker/utils.py +++ b/samcli/local/docker/utils.py @@ -5,11 +5,7 @@ import os import re import posixpath - -try: - import pathlib -except ImportError: - import pathlib2 as pathlib +import pathlib def to_posix_path(code_path): diff --git a/samcli/local/lambdafn/zip.py b/samcli/local/lambdafn/zip.py index 130e9569f7..b9a42c77a4 100644 --- a/samcli/local/lambdafn/zip.py +++ b/samcli/local/lambdafn/zip.py @@ -10,11 +10,7 @@ import requests from samcli.lib.utils.progressbar import progressbar - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path LOG = logging.getLogger(__name__) diff --git a/samcli/local/layers/layer_downloader.py b/samcli/local/layers/layer_downloader.py index 2744582c5b..e88440b7c6 100644 --- a/samcli/local/layers/layer_downloader.py +++ b/samcli/local/layers/layer_downloader.py @@ -10,11 +10,7 @@ from samcli.lib.utils.codeuri import resolve_code_path from samcli.local.lambdafn.zip import unzip_from_uri from samcli.commands.local.cli_common.user_exceptions import CredentialsRequired, ResourceNotFound - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path LOG = logging.getLogger(__name__) diff --git a/tests/functional/commands/cli/test_global_config.py b/tests/functional/commands/cli/test_global_config.py index c4c92bcf58..e156a2e872 100644 --- a/tests/functional/commands/cli/test_global_config.py +++ b/tests/functional/commands/cli/test_global_config.py @@ -6,11 +6,7 @@ from unittest import TestCase from json import JSONDecodeError from samcli.cli.global_config import GlobalConfig - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path class TestGlobalConfig(TestCase): diff --git a/tests/integration/buildcmd/build_integ_base.py b/tests/integration/buildcmd/build_integ_base.py index 8b69f94726..8a393d8dca 100644 --- a/tests/integration/buildcmd/build_integ_base.py +++ b/tests/integration/buildcmd/build_integ_base.py @@ -9,11 +9,7 @@ from unittest import TestCase import docker - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path from samcli.yamlhelper import yaml_parse from tests.testing_utils import IS_WINDOWS diff --git a/tests/integration/buildcmd/test_build_cmd.py b/tests/integration/buildcmd/test_build_cmd.py index fef5a26dea..5bc05fe315 100644 --- a/tests/integration/buildcmd/test_build_cmd.py +++ b/tests/integration/buildcmd/test_build_cmd.py @@ -3,11 +3,7 @@ import subprocess import logging from unittest import skipIf - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path from parameterized import parameterized from .build_integ_base import BuildIntegBase diff --git a/tests/integration/local/invoke/invoke_integ_base.py b/tests/integration/local/invoke/invoke_integ_base.py index fe13436acb..c941967ae4 100644 --- a/tests/integration/local/invoke/invoke_integ_base.py +++ b/tests/integration/local/invoke/invoke_integ_base.py @@ -1,10 +1,6 @@ import os from unittest import TestCase - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path class InvokeIntegBase(TestCase): diff --git a/tests/integration/local/invoke/layer_utils.py b/tests/integration/local/invoke/layer_utils.py index eb9f135002..0743cd7084 100644 --- a/tests/integration/local/invoke/layer_utils.py +++ b/tests/integration/local/invoke/layer_utils.py @@ -4,11 +4,7 @@ import boto3 from tests.integration.local.invoke.invoke_integ_base import InvokeIntegBase - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path class LayerUtils(object): diff --git a/tests/integration/local/invoke/runtimes/test_with_runtime_zips.py b/tests/integration/local/invoke/runtimes/test_with_runtime_zips.py index 0f1290c711..97227c05a8 100644 --- a/tests/integration/local/invoke/runtimes/test_with_runtime_zips.py +++ b/tests/integration/local/invoke/runtimes/test_with_runtime_zips.py @@ -8,11 +8,7 @@ import pytest from tests.integration.local.invoke.invoke_integ_base import InvokeIntegBase - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path class TestWithDifferentLambdaRuntimeZips(InvokeIntegBase): diff --git a/tests/integration/local/invoke/test_integrations_cli.py b/tests/integration/local/invoke/test_integrations_cli.py index 2042e5cf95..203ebb7797 100644 --- a/tests/integration/local/invoke/test_integrations_cli.py +++ b/tests/integration/local/invoke/test_integrations_cli.py @@ -19,10 +19,7 @@ # This is to restrict layers tests to run outside of Travis and when the branch is not master. SKIP_LAYERS_TESTS = RUNNING_ON_CI and RUNNING_TEST_FOR_MASTER_ON_CI -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path class TestSamPython36HelloWorldIntegration(InvokeIntegBase): diff --git a/tests/integration/local/start_api/start_api_integ_base.py b/tests/integration/local/start_api/start_api_integ_base.py index a212eb1036..e4b32610a7 100644 --- a/tests/integration/local/start_api/start_api_integ_base.py +++ b/tests/integration/local/start_api/start_api_integ_base.py @@ -4,11 +4,7 @@ import time import os import random - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path class StartApiIntegBaseClass(TestCase): diff --git a/tests/integration/local/start_lambda/start_lambda_api_integ_base.py b/tests/integration/local/start_lambda/start_lambda_api_integ_base.py index 7fd5099f0a..e0a72ec82a 100644 --- a/tests/integration/local/start_lambda/start_lambda_api_integ_base.py +++ b/tests/integration/local/start_lambda/start_lambda_api_integ_base.py @@ -5,10 +5,7 @@ import os import random -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path class StartLambdaIntegBaseClass(TestCase): diff --git a/tests/integration/publish/publish_app_integ_base.py b/tests/integration/publish/publish_app_integ_base.py index a937149a41..1b430a2375 100644 --- a/tests/integration/publish/publish_app_integ_base.py +++ b/tests/integration/publish/publish_app_integ_base.py @@ -7,11 +7,7 @@ from unittest import TestCase import boto3 - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path class PublishAppIntegBase(TestCase): diff --git a/tests/integration/telemetry/integ_base.py b/tests/integration/telemetry/integ_base.py index 314da3b181..f991afa3b0 100644 --- a/tests/integration/telemetry/integ_base.py +++ b/tests/integration/telemetry/integ_base.py @@ -12,11 +12,7 @@ from threading import Thread from collections import deque from unittest import TestCase - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path from samcli.cli.global_config import GlobalConfig from samcli.cli.main import TELEMETRY_PROMPT diff --git a/tests/unit/cli/test_global_config.py b/tests/unit/cli/test_global_config.py index 776952dbfd..43a394bbb0 100644 --- a/tests/unit/cli/test_global_config.py +++ b/tests/unit/cli/test_global_config.py @@ -2,11 +2,7 @@ from unittest import TestCase from parameterized import parameterized from samcli.cli.global_config import GlobalConfig - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path class TestGlobalConfig(TestCase): diff --git a/tests/unit/lib/build_module/test_app_builder.py b/tests/unit/lib/build_module/test_app_builder.py index cb617ebfa5..5bf9994833 100644 --- a/tests/unit/lib/build_module/test_app_builder.py +++ b/tests/unit/lib/build_module/test_app_builder.py @@ -4,12 +4,7 @@ from unittest import TestCase from mock import Mock, call, patch - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path - +from pathlib import Path from samcli.lib.build.app_builder import ( ApplicationBuilder, diff --git a/tests/unit/lib/intrinsic_resolver/test_intrinsic_resolver.py b/tests/unit/lib/intrinsic_resolver/test_intrinsic_resolver.py index 0c80e84eab..c262838608 100644 --- a/tests/unit/lib/intrinsic_resolver/test_intrinsic_resolver.py +++ b/tests/unit/lib/intrinsic_resolver/test_intrinsic_resolver.py @@ -1,11 +1,7 @@ import json from collections import OrderedDict from copy import deepcopy - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path from unittest import TestCase from mock import patch diff --git a/tests/unit/lib/utils/test_codeuri.py b/tests/unit/lib/utils/test_codeuri.py index 45052da423..c5682bbe8d 100644 --- a/tests/unit/lib/utils/test_codeuri.py +++ b/tests/unit/lib/utils/test_codeuri.py @@ -2,10 +2,7 @@ from unittest import TestCase from parameterized import parameterized -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path from samcli.lib.utils.codeuri import resolve_code_path diff --git a/tests/unit/local/docker/test_lambda_build_container.py b/tests/unit/local/docker/test_lambda_build_container.py index 037d1450d3..5ae72d0087 100644 --- a/tests/unit/local/docker/test_lambda_build_container.py +++ b/tests/unit/local/docker/test_lambda_build_container.py @@ -3,11 +3,7 @@ """ import json - -try: - import pathlib -except ImportError: - import pathlib2 as pathlib +import pathlib from unittest import TestCase from mock import patch diff --git a/tests/unit/local/layers/test_download_layers.py b/tests/unit/local/layers/test_download_layers.py index 288252bfbe..9315d4f5c3 100644 --- a/tests/unit/local/layers/test_download_layers.py +++ b/tests/unit/local/layers/test_download_layers.py @@ -2,11 +2,7 @@ from mock import patch, Mock, call from botocore.exceptions import NoCredentialsError, ClientError - -try: - from pathlib import Path -except ImportError: - from pathlib2 import Path +from pathlib import Path from samcli.local.layers.layer_downloader import LayerDownloader From 0ab2caeabf49191eec39166d8a34eca0f9b9deb8 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 12:43:44 -0700 Subject: [PATCH 03/42] Upgrade dev dependencies --- requirements/dev.txt | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 029324c901..c9c01dd471 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,20 +1,9 @@ -coverage==4.3.4 -pytest-cov==2.4.0 -# astroid > 2.0.4 is not compatible with pylint1.7 -astroid>=1.5.8,<2.1.0 -pylint==1.7.2 +coverage==4.5.4 +pytest-cov==2.7.1 +pylint==2.3.1 # Test requirements -pytest==3.6.0 -py==1.5.1 -pluggy==0.6.0 -mock==2.0.0 -parameterized==0.6.1 -pathlib2==2.3.2; python_version<"3.4" -futures==3.2.0; python_version<"3.2.3" -# Py3.2 backport -backports.tempfile==1.0 -pytest-xdist==1.20.0 -pytest-forked==1.0.2 -pytest-timeout==1.3.3 -pytest-rerunfailures==5.0 +pytest==5.1.2 +#mock==2.0.0 # mock is now part of the Python standard library, available as unittest.mock in Python 3.3 onwards. +parameterized==0.7.0 +pytest-xdist==1.29.0 From 533218e8dfbbf829cb3f39086a1c3367b00bccf4 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 12:48:10 -0700 Subject: [PATCH 04/42] Handle Unnecessary pass statement --- samcli/commands/build/exceptions.py | 1 - .../local/cli_common/user_exceptions.py | 17 ----------------- samcli/commands/local/generate_event/cli.py | 1 - samcli/commands/local/lib/exceptions.py | 4 ---- samcli/commands/local/local.py | 1 - samcli/commands/validate/lib/exceptions.py | 2 -- samcli/local/lambdafn/exceptions.py | 2 -- 7 files changed, 28 deletions(-) diff --git a/samcli/commands/build/exceptions.py b/samcli/commands/build/exceptions.py index 783a928803..8da0d4aa55 100644 --- a/samcli/commands/build/exceptions.py +++ b/samcli/commands/build/exceptions.py @@ -7,4 +7,3 @@ class InvalidBuildDirException(UserException): """ Value provided to --build-dir is invalid """ - pass diff --git a/samcli/commands/local/cli_common/user_exceptions.py b/samcli/commands/local/cli_common/user_exceptions.py index 7f474859a7..0db8d94823 100644 --- a/samcli/commands/local/cli_common/user_exceptions.py +++ b/samcli/commands/local/cli_common/user_exceptions.py @@ -10,23 +10,18 @@ class InvokeContextException(UserException): Something went wrong invoking the function. """ - pass - class InvalidSamTemplateException(UserException): """ The template provided was invalid and not able to transform into a Standard CloudFormation Template """ - pass - class SamTemplateNotFoundException(UserException): """ The SAM Template provided could not be found """ - pass class DebugContextException(UserException): @@ -34,44 +29,32 @@ class DebugContextException(UserException): Something went wrong when creating the DebugContext """ - pass - class ImageBuildException(UserException): """ Image failed to build """ - pass - class CredentialsRequired(UserException): """ Credentials were not given when Required """ - pass - class ResourceNotFound(UserException): """ The Resource requested was not found """ - pass - class InvalidLayerVersionArn(UserException): """ The LayerVersion Arn given in the template is Invalid """ - pass - class UnsupportedIntrinsic(UserException): """ Value from a template has an Intrinsic that is unsupported """ - - pass diff --git a/samcli/commands/local/generate_event/cli.py b/samcli/commands/local/generate_event/cli.py index 89f911a661..2533d34715 100644 --- a/samcli/commands/local/generate_event/cli.py +++ b/samcli/commands/local/generate_event/cli.py @@ -32,4 +32,3 @@ def cli(self): """ Generate an event for one of the services listed below: """ - pass # pragma: no cover diff --git a/samcli/commands/local/lib/exceptions.py b/samcli/commands/local/lib/exceptions.py index ea5e9e9a31..e33a85bcad 100644 --- a/samcli/commands/local/lib/exceptions.py +++ b/samcli/commands/local/lib/exceptions.py @@ -8,16 +8,12 @@ class NoApisDefined(Exception): Raised when there are no APIs defined in the template """ - pass - class OverridesNotWellDefinedError(Exception): """ Raised when the overrides file is invalid """ - pass - class InvalidLayerReference(Exception): """ diff --git a/samcli/commands/local/local.py b/samcli/commands/local/local.py index c24a54923f..663c1c4d87 100644 --- a/samcli/commands/local/local.py +++ b/samcli/commands/local/local.py @@ -16,7 +16,6 @@ def cli(): """ Run your Serverless application locally for quick development & testing """ - pass # pragma: no cover # Add individual commands under this group diff --git a/samcli/commands/validate/lib/exceptions.py b/samcli/commands/validate/lib/exceptions.py index b6afd4b0f4..96aa3f6008 100644 --- a/samcli/commands/validate/lib/exceptions.py +++ b/samcli/commands/validate/lib/exceptions.py @@ -7,5 +7,3 @@ class InvalidSamDocumentException(Exception): """ Exception for Invalid Sam Documents """ - - pass diff --git a/samcli/local/lambdafn/exceptions.py b/samcli/local/lambdafn/exceptions.py index 0fee680f43..438c331c3c 100644 --- a/samcli/local/lambdafn/exceptions.py +++ b/samcli/local/lambdafn/exceptions.py @@ -7,5 +7,3 @@ class FunctionNotFound(Exception): """ Raised when the requested Lambda function is not found """ - - pass From 6833ff7314b50ed146f2594338b66afec32ecfb1 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 13:03:14 -0700 Subject: [PATCH 05/42] Handle useless-object-inheritance --- samcli/cli/context.py | 2 +- samcli/cli/global_config.py | 2 +- samcli/commands/build/build_context.py | 2 +- samcli/commands/local/cli_common/invoke_context.py | 2 +- samcli/commands/local/lib/api_collector.py | 2 +- samcli/commands/local/lib/cfn_base_api_provider.py | 2 +- samcli/commands/local/lib/debug_context.py | 2 +- .../commands/local/lib/generated_sample_events/events.py | 2 +- samcli/commands/local/lib/local_api_service.py | 2 +- samcli/commands/local/lib/local_lambda.py | 2 +- samcli/commands/local/lib/local_lambda_service.py | 2 +- samcli/commands/local/lib/provider.py | 8 ++++---- samcli/commands/local/lib/sam_base_provider.py | 2 +- samcli/commands/local/lib/swagger/integration_uri.py | 2 +- samcli/commands/local/lib/swagger/parser.py | 2 +- samcli/commands/local/lib/swagger/reader.py | 2 +- samcli/commands/logs/logs_context.py | 2 +- samcli/commands/validate/lib/sam_template_validator.py | 2 +- samcli/lib/build/app_builder.py | 2 +- samcli/lib/build/workflow_config.py | 2 +- .../lib/intrinsic_resolver/intrinsic_property_resolver.py | 2 +- samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py | 2 +- samcli/lib/logs/event.py | 2 +- samcli/lib/logs/fetcher.py | 2 +- samcli/lib/logs/formatter.py | 8 ++++---- samcli/lib/logs/provider.py | 2 +- samcli/lib/samlib/resource_metadata_normalizer.py | 2 +- samcli/lib/samlib/wrapper.py | 4 ++-- samcli/lib/telemetry/telemetry.py | 2 +- samcli/lib/utils/colors.py | 2 +- samcli/lib/utils/sam_logging.py | 2 +- samcli/lib/utils/stream_writer.py | 2 +- samcli/local/apigw/local_apigw_service.py | 2 +- samcli/local/apigw/path_converter.py | 2 +- samcli/local/apigw/service_error_responses.py | 2 +- samcli/local/docker/container.py | 2 +- samcli/local/docker/lambda_debug_entrypoint.py | 2 +- samcli/local/docker/lambda_image.py | 2 +- samcli/local/docker/manager.py | 2 +- samcli/local/events/api_event.py | 6 +++--- samcli/local/lambda_service/lambda_error_responses.py | 2 +- samcli/local/lambdafn/config.py | 2 +- samcli/local/lambdafn/env_vars.py | 2 +- samcli/local/lambdafn/runtime.py | 2 +- samcli/local/layers/layer_downloader.py | 2 +- samcli/local/services/base_local_service.py | 4 ++-- 46 files changed, 56 insertions(+), 56 deletions(-) diff --git a/samcli/cli/context.py b/samcli/cli/context.py index c50fefa8fe..aab43b0c73 100644 --- a/samcli/cli/context.py +++ b/samcli/cli/context.py @@ -8,7 +8,7 @@ import click -class Context(object): +class Context: """ Top level context object for the CLI. Exposes common functionality required by a CLI, including logging, environment config parsing, debug logging etc. diff --git a/samcli/cli/global_config.py b/samcli/cli/global_config.py index b8628eef40..dc0f208c9e 100644 --- a/samcli/cli/global_config.py +++ b/samcli/cli/global_config.py @@ -18,7 +18,7 @@ TELEMETRY_ENABLED_KEY = "telemetryEnabled" -class GlobalConfig(object): +class GlobalConfig: """ Contains helper methods for global configuration files and values. Handles configuration file creation, updates, and fetching in a platform-neutral way. diff --git a/samcli/commands/build/build_context.py b/samcli/commands/build/build_context.py index 4c1f7bd88d..71adfddd81 100644 --- a/samcli/commands/build/build_context.py +++ b/samcli/commands/build/build_context.py @@ -17,7 +17,7 @@ LOG = logging.getLogger(__name__) -class BuildContext(object): +class BuildContext: # Build directories need not be world writable. # This is usually a optimal permission for directories diff --git a/samcli/commands/local/cli_common/invoke_context.py b/samcli/commands/local/cli_common/invoke_context.py index a0894b0453..69b5953221 100644 --- a/samcli/commands/local/cli_common/invoke_context.py +++ b/samcli/commands/local/cli_common/invoke_context.py @@ -20,7 +20,7 @@ from pathlib import Path -class InvokeContext(object): +class InvokeContext: """ Sets up a context to invoke Lambda functions locally by parsing all command line arguments necessary for the invoke. diff --git a/samcli/commands/local/lib/api_collector.py b/samcli/commands/local/lib/api_collector.py index 98fd2861c7..775fc36d10 100644 --- a/samcli/commands/local/lib/api_collector.py +++ b/samcli/commands/local/lib/api_collector.py @@ -14,7 +14,7 @@ LOG = logging.getLogger(__name__) -class ApiCollector(object): +class ApiCollector: def __init__(self): # Route properties stored per resource. self._route_per_resource = defaultdict(list) diff --git a/samcli/commands/local/lib/cfn_base_api_provider.py b/samcli/commands/local/lib/cfn_base_api_provider.py index d0a769e703..47bdf1ddf4 100644 --- a/samcli/commands/local/lib/cfn_base_api_provider.py +++ b/samcli/commands/local/lib/cfn_base_api_provider.py @@ -7,7 +7,7 @@ LOG = logging.getLogger(__name__) -class CfnBaseApiProvider(object): +class CfnBaseApiProvider: RESOURCE_TYPE = "Type" def extract_resources(self, resources, collector, cwd=None): diff --git a/samcli/commands/local/lib/debug_context.py b/samcli/commands/local/lib/debug_context.py index 26bb692452..053b580255 100644 --- a/samcli/commands/local/lib/debug_context.py +++ b/samcli/commands/local/lib/debug_context.py @@ -3,7 +3,7 @@ """ -class DebugContext(object): +class DebugContext: def __init__(self, debug_port=None, debugger_path=None, debug_args=None): self.debug_port = debug_port diff --git a/samcli/commands/local/lib/generated_sample_events/events.py b/samcli/commands/local/lib/generated_sample_events/events.py index a5d929401d..9afb858bcb 100644 --- a/samcli/commands/local/lib/generated_sample_events/events.py +++ b/samcli/commands/local/lib/generated_sample_events/events.py @@ -10,7 +10,7 @@ from chevron import renderer -class Events(object): +class Events: """ Events library class that loads and customizes event json files diff --git a/samcli/commands/local/lib/local_api_service.py b/samcli/commands/local/lib/local_api_service.py index d1ed8f7bca..e892bb847e 100644 --- a/samcli/commands/local/lib/local_api_service.py +++ b/samcli/commands/local/lib/local_api_service.py @@ -12,7 +12,7 @@ LOG = logging.getLogger(__name__) -class LocalApiService(object): +class LocalApiService: """ Implementation of Local API service that is capable of serving API defined in a configuration file that invoke a Lambda function. diff --git a/samcli/commands/local/lib/local_lambda.py b/samcli/commands/local/lib/local_lambda.py index 58a1eebb98..d189bcb8be 100644 --- a/samcli/commands/local/lib/local_lambda.py +++ b/samcli/commands/local/lib/local_lambda.py @@ -15,7 +15,7 @@ LOG = logging.getLogger(__name__) -class LocalLambdaRunner(object): +class LocalLambdaRunner: """ Runs Lambda functions locally. This class is a wrapper around the `samcli.local` library which takes care of actually running the function on a Docker container. diff --git a/samcli/commands/local/lib/local_lambda_service.py b/samcli/commands/local/lib/local_lambda_service.py index 45d3eb407b..07d11f78f0 100644 --- a/samcli/commands/local/lib/local_lambda_service.py +++ b/samcli/commands/local/lib/local_lambda_service.py @@ -8,7 +8,7 @@ LOG = logging.getLogger(__name__) -class LocalLambdaService(object): +class LocalLambdaService: """ Implementation of Local Lambda Invoke Service that is capable of serving the invoke path to your Lambda Functions that are defined in a SAM file. diff --git a/samcli/commands/local/lib/provider.py b/samcli/commands/local/lib/provider.py index 8aefb71107..12aa1be5b4 100644 --- a/samcli/commands/local/lib/provider.py +++ b/samcli/commands/local/lib/provider.py @@ -37,7 +37,7 @@ ) -class LayerVersion(object): +class LayerVersion: """ Represents the LayerVersion Resource for AWS Lambda """ @@ -171,7 +171,7 @@ def __eq__(self, other): return False -class FunctionProvider(object): +class FunctionProvider: """ Abstract base class of the function provider. """ @@ -194,7 +194,7 @@ def get_all(self): raise NotImplementedError("not implemented") -class Api(object): +class Api: def __init__(self, routes=None): if routes is None: routes = [] @@ -259,7 +259,7 @@ def cors_to_headers(cors): return {h_key: h_value for h_key, h_value in headers.items() if h_value is not None} -class AbstractApiProvider(object): +class AbstractApiProvider: """ Abstract base class to return APIs and the functions they route to """ diff --git a/samcli/commands/local/lib/sam_base_provider.py b/samcli/commands/local/lib/sam_base_provider.py index 293724c640..268402d713 100644 --- a/samcli/commands/local/lib/sam_base_provider.py +++ b/samcli/commands/local/lib/sam_base_provider.py @@ -12,7 +12,7 @@ LOG = logging.getLogger(__name__) -class SamBaseProvider(object): +class SamBaseProvider: """ Base class for SAM Template providers """ diff --git a/samcli/commands/local/lib/swagger/integration_uri.py b/samcli/commands/local/lib/swagger/integration_uri.py index 437e8d6ed7..edda321027 100644 --- a/samcli/commands/local/lib/swagger/integration_uri.py +++ b/samcli/commands/local/lib/swagger/integration_uri.py @@ -12,7 +12,7 @@ LOG = logging.getLogger(__name__) -class LambdaUri(object): +class LambdaUri: """ Purely static class that helps you parse Lambda Function Integration URI ARN """ diff --git a/samcli/commands/local/lib/swagger/parser.py b/samcli/commands/local/lib/swagger/parser.py index 9f5363570f..a0ea9fa436 100644 --- a/samcli/commands/local/lib/swagger/parser.py +++ b/samcli/commands/local/lib/swagger/parser.py @@ -8,7 +8,7 @@ LOG = logging.getLogger(__name__) -class SwaggerParser(object): +class SwaggerParser: _INTEGRATION_KEY = "x-amazon-apigateway-integration" _ANY_METHOD_EXTENSION_KEY = "x-amazon-apigateway-any-method" _BINARY_MEDIA_TYPES_EXTENSION_KEY = "x-amazon-apigateway-binary-media-types" # pylint: disable=C0103 diff --git a/samcli/commands/local/lib/swagger/reader.py b/samcli/commands/local/lib/swagger/reader.py index 3ef417e858..03a1a07e72 100644 --- a/samcli/commands/local/lib/swagger/reader.py +++ b/samcli/commands/local/lib/swagger/reader.py @@ -57,7 +57,7 @@ def parse_aws_include_transform(data): return location -class SwaggerReader(object): +class SwaggerReader: """ Class to read and parse Swagger document from a variety of sources. This class accepts the same data formats as available in Serverless::Api SAM resource diff --git a/samcli/commands/logs/logs_context.py b/samcli/commands/logs/logs_context.py index b2cd8d5138..2159e92d1a 100644 --- a/samcli/commands/logs/logs_context.py +++ b/samcli/commands/logs/logs_context.py @@ -16,7 +16,7 @@ LOG = logging.getLogger(__name__) -class LogsCommandContext(object): +class LogsCommandContext: """ Sets up a context to run the Logs command by parsing the CLI arguments and creating necessary objects to be able to fetch and display logs diff --git a/samcli/commands/validate/lib/sam_template_validator.py b/samcli/commands/validate/lib/sam_template_validator.py index 6117273083..7ed8bada05 100644 --- a/samcli/commands/validate/lib/sam_template_validator.py +++ b/samcli/commands/validate/lib/sam_template_validator.py @@ -14,7 +14,7 @@ LOG = logging.getLogger(__name__) -class SamTemplateValidator(object): +class SamTemplateValidator: def __init__(self, sam_template, managed_policy_loader): """ Construct a SamTemplateValidator diff --git a/samcli/lib/build/app_builder.py b/samcli/lib/build/app_builder.py index 00bdbd8271..6c7e75fb2a 100644 --- a/samcli/lib/build/app_builder.py +++ b/samcli/lib/build/app_builder.py @@ -37,7 +37,7 @@ class BuildError(Exception): pass -class ApplicationBuilder(object): +class ApplicationBuilder: """ Class to build an entire application. Currently, this class builds Lambda functions only, but there is nothing that is stopping this class from supporting other resource types. Building in context of Lambda functions refer to diff --git a/samcli/lib/build/workflow_config.py b/samcli/lib/build/workflow_config.py index 475e036594..d649b80375 100644 --- a/samcli/lib/build/workflow_config.py +++ b/samcli/lib/build/workflow_config.py @@ -162,7 +162,7 @@ def _key(c): return True, None -class BasicWorkflowSelector(object): +class BasicWorkflowSelector: """ Basic workflow selector that returns the first available configuration in the given list of configurations """ diff --git a/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py b/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py index 0e99e90914..32ab4c89cc 100644 --- a/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py +++ b/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py @@ -27,7 +27,7 @@ LOG = logging.getLogger(__name__) -class IntrinsicResolver(object): +class IntrinsicResolver: AWS_INCLUDE = "AWS::Include" SUPPORTED_MACRO_TRANSFORMATIONS = [AWS_INCLUDE] _PSEUDO_REGEX = r"AWS::.*?" diff --git a/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py b/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py index 036deef72c..748698c397 100644 --- a/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py +++ b/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py @@ -12,7 +12,7 @@ LOG = logging.getLogger(__name__) -class IntrinsicsSymbolTable(object): +class IntrinsicsSymbolTable: AWS_ACCOUNT_ID = "AWS::AccountId" AWS_NOTIFICATION_ARN = "AWS::NotificationArn" AWS_PARTITION = "AWS::Partition" diff --git a/samcli/lib/logs/event.py b/samcli/lib/logs/event.py index ea95757252..73a2edf278 100644 --- a/samcli/lib/logs/event.py +++ b/samcli/lib/logs/event.py @@ -9,7 +9,7 @@ LOG = logging.getLogger(__name__) -class LogEvent(object): +class LogEvent: """ Data object representing a CloudWatch Log Event """ diff --git a/samcli/lib/logs/fetcher.py b/samcli/lib/logs/fetcher.py index 239fc01a65..1468eca98d 100644 --- a/samcli/lib/logs/fetcher.py +++ b/samcli/lib/logs/fetcher.py @@ -12,7 +12,7 @@ LOG = logging.getLogger(__name__) -class LogsFetcher(object): +class LogsFetcher: """ Fetch logs from a CloudWatch Logs group with the ability to scope to a particular time, filter by a pattern, and in the future possibly multiplex from from multiple streams together. diff --git a/samcli/lib/logs/formatter.py b/samcli/lib/logs/formatter.py index 09f15dc9a0..a5aab56b78 100644 --- a/samcli/lib/logs/formatter.py +++ b/samcli/lib/logs/formatter.py @@ -15,7 +15,7 @@ from builtins import map as imap -class LogsFormatter(object): +class LogsFormatter: """ Formats log messages returned by CloudWatch Logs service. """ @@ -121,7 +121,7 @@ def _pretty_print_event(event, colored): return " ".join([event.log_stream_name, event.timestamp, event.message]) -class LambdaLogMsgFormatters(object): +class LambdaLogMsgFormatters: """ Format logs printed by AWS Lambda functions. @@ -145,7 +145,7 @@ def colorize_errors(event, colored): return event -class KeywordHighlighter(object): +class KeywordHighlighter: """ Highlight certain keywords in the log line """ @@ -164,7 +164,7 @@ def highlight_keywords(self, event, colored): return event -class JSONMsgFormatter(object): +class JSONMsgFormatter: """ Pretty print JSONs within a message """ diff --git a/samcli/lib/logs/provider.py b/samcli/lib/logs/provider.py index 4a6d898e8e..90893e5238 100644 --- a/samcli/lib/logs/provider.py +++ b/samcli/lib/logs/provider.py @@ -3,7 +3,7 @@ """ -class LogGroupProvider(object): +class LogGroupProvider: """ Resolve the name of log group given the name of the resource """ diff --git a/samcli/lib/samlib/resource_metadata_normalizer.py b/samcli/lib/samlib/resource_metadata_normalizer.py index 541652cddf..0505103924 100644 --- a/samcli/lib/samlib/resource_metadata_normalizer.py +++ b/samcli/lib/samlib/resource_metadata_normalizer.py @@ -13,7 +13,7 @@ LOG = logging.getLogger(__name__) -class ResourceMetadataNormalizer(object): +class ResourceMetadataNormalizer: @staticmethod def normalize(template_dict): """ diff --git a/samcli/lib/samlib/wrapper.py b/samcli/lib/samlib/wrapper.py index 3a31e2c16e..141f1aeb0a 100644 --- a/samcli/lib/samlib/wrapper.py +++ b/samcli/lib/samlib/wrapper.py @@ -32,7 +32,7 @@ from .local_uri_plugin import SupportLocalUriPlugin -class SamTranslatorWrapper(object): +class SamTranslatorWrapper: _thisdir = os.path.dirname(os.path.abspath(__file__)) _DEFAULT_MANAGED_POLICIES_FILE = os.path.join(_thisdir, "default_managed_policies.json") @@ -116,7 +116,7 @@ def __managed_policy_map(self): raise ex -class _SamParserReimplemented(object): +class _SamParserReimplemented: """ Re-implementation (almost copy) of Parser class from SAM Translator """ diff --git a/samcli/lib/telemetry/telemetry.py b/samcli/lib/telemetry/telemetry.py index 9d25d08a5a..1c3a85eb72 100644 --- a/samcli/lib/telemetry/telemetry.py +++ b/samcli/lib/telemetry/telemetry.py @@ -17,7 +17,7 @@ LOG = logging.getLogger(__name__) -class Telemetry(object): +class Telemetry: def __init__(self, url=None): """ Initialize the Telemetry object. diff --git a/samcli/lib/utils/colors.py b/samcli/lib/utils/colors.py index 19c7550494..84e3cbdbd7 100644 --- a/samcli/lib/utils/colors.py +++ b/samcli/lib/utils/colors.py @@ -5,7 +5,7 @@ import click -class Colored(object): +class Colored: """ Helper class to add ANSI colors and decorations to text. Given a string, ANSI colors are added with special prefix and suffix characters that are specially interpreted by Terminals to display colors. diff --git a/samcli/lib/utils/sam_logging.py b/samcli/lib/utils/sam_logging.py index 069933f10a..bf40d2ccaf 100644 --- a/samcli/lib/utils/sam_logging.py +++ b/samcli/lib/utils/sam_logging.py @@ -4,7 +4,7 @@ import logging -class SamCliLogger(object): +class SamCliLogger: @staticmethod def configure_logger(logger, formatter, level): """ diff --git a/samcli/lib/utils/stream_writer.py b/samcli/lib/utils/stream_writer.py index a931452e1e..da82625ce5 100644 --- a/samcli/lib/utils/stream_writer.py +++ b/samcli/lib/utils/stream_writer.py @@ -3,7 +3,7 @@ """ -class StreamWriter(object): +class StreamWriter: def __init__(self, stream, auto_flush=False): """ Instatiates new StreamWriter to the specified stream diff --git a/samcli/local/apigw/local_apigw_service.py b/samcli/local/apigw/local_apigw_service.py index db647ba6ff..4a3507bc9c 100644 --- a/samcli/local/apigw/local_apigw_service.py +++ b/samcli/local/apigw/local_apigw_service.py @@ -18,7 +18,7 @@ LOG = logging.getLogger(__name__) -class Route(object): +class Route: ANY_HTTP_METHODS = ["GET", "DELETE", "PUT", "POST", "HEAD", "OPTIONS", "PATCH"] def __init__(self, function_name, path, methods): diff --git a/samcli/local/apigw/path_converter.py b/samcli/local/apigw/path_converter.py index 274f4a9907..821657ef36 100644 --- a/samcli/local/apigw/path_converter.py +++ b/samcli/local/apigw/path_converter.py @@ -31,7 +31,7 @@ FLASK_TO_APIGW_REGEX = re.compile(FLASK_CAPTURE_ALL_PATH_REGEX) -class PathConverter(object): +class PathConverter: @staticmethod def convert_path_to_flask(path): """ diff --git a/samcli/local/apigw/service_error_responses.py b/samcli/local/apigw/service_error_responses.py index e32f6ec23a..e2214dada1 100644 --- a/samcli/local/apigw/service_error_responses.py +++ b/samcli/local/apigw/service_error_responses.py @@ -3,7 +3,7 @@ from flask import jsonify, make_response -class ServiceErrorResponses(object): +class ServiceErrorResponses: _NO_LAMBDA_INTEGRATION = {"message": "No function defined for resource method"} _MISSING_AUTHENTICATION = {"message": "Missing Authentication Token"} diff --git a/samcli/local/docker/container.py b/samcli/local/docker/container.py index d2910a936c..a2ffc15e77 100644 --- a/samcli/local/docker/container.py +++ b/samcli/local/docker/container.py @@ -14,7 +14,7 @@ LOG = logging.getLogger(__name__) -class Container(object): +class Container: """ Represents an instance of a Docker container with a specific configuration. The container is not actually created or executed until the appropriate methods are called. Each container instance is uniquely identified by an ID that diff --git a/samcli/local/docker/lambda_debug_entrypoint.py b/samcli/local/docker/lambda_debug_entrypoint.py index 17154e5394..4424942f6f 100644 --- a/samcli/local/docker/lambda_debug_entrypoint.py +++ b/samcli/local/docker/lambda_debug_entrypoint.py @@ -11,7 +11,7 @@ class DebuggingNotSupported(Exception): pass -class LambdaDebugEntryPoint(object): +class LambdaDebugEntryPoint: @staticmethod def get_entry_point(debug_port, debug_args_list, runtime, options): diff --git a/samcli/local/docker/lambda_image.py b/samcli/local/docker/lambda_image.py index 7cacc4e008..ddcc6c1eff 100644 --- a/samcli/local/docker/lambda_image.py +++ b/samcli/local/docker/lambda_image.py @@ -43,7 +43,7 @@ def has_value(cls, value): return any(value == item.value for item in cls) -class LambdaImage(object): +class LambdaImage: _LAYERS_DIR = "/opt" _DOCKER_LAMBDA_REPO_NAME = "lambci/lambda" _SAM_CLI_REPO_NAME = "samcli/lambda" diff --git a/samcli/local/docker/manager.py b/samcli/local/docker/manager.py index 0fb07c0391..ac99de4544 100644 --- a/samcli/local/docker/manager.py +++ b/samcli/local/docker/manager.py @@ -13,7 +13,7 @@ LOG = logging.getLogger(__name__) -class ContainerManager(object): +class ContainerManager: """ This class knows how to interface with Docker to create, execute and manage the container's life cycle. It can run multiple containers in parallel, and also comes with the ability to reuse existing containers in order to diff --git a/samcli/local/events/api_event.py b/samcli/local/events/api_event.py index e17f125780..fa077e22f7 100644 --- a/samcli/local/events/api_event.py +++ b/samcli/local/events/api_event.py @@ -1,7 +1,7 @@ """Holds Classes for API Gateway to Lambda Events""" -class ContextIdentity(object): +class ContextIdentity: def __init__( self, api_key=None, @@ -62,7 +62,7 @@ def to_dict(self): return json_dict -class RequestContext(object): +class RequestContext: def __init__( self, resource_id="123456", @@ -128,7 +128,7 @@ def to_dict(self): return json_dict -class ApiGatewayLambdaEvent(object): +class ApiGatewayLambdaEvent: def __init__( self, http_method=None, diff --git a/samcli/local/lambda_service/lambda_error_responses.py b/samcli/local/lambda_service/lambda_error_responses.py index d003980042..49ee2c253f 100644 --- a/samcli/local/lambda_service/lambda_error_responses.py +++ b/samcli/local/lambda_service/lambda_error_responses.py @@ -6,7 +6,7 @@ from samcli.local.services.base_local_service import BaseLocalService -class LambdaErrorResponses(object): +class LambdaErrorResponses: # The content type of the Invoke request body is not JSON. UnsupportedMediaTypeException = ("UnsupportedMediaType", 415) diff --git a/samcli/local/lambdafn/config.py b/samcli/local/lambdafn/config.py index b7df4b5466..e438ab9355 100644 --- a/samcli/local/lambdafn/config.py +++ b/samcli/local/lambdafn/config.py @@ -5,7 +5,7 @@ from .env_vars import EnvironmentVariables -class FunctionConfig(object): +class FunctionConfig: """ Data class to store function configuration. This class is a flavor of function configuration passed to AWS Lambda APIs on the cloud. It is limited to properties that make sense in a local testing environment. diff --git a/samcli/local/lambdafn/env_vars.py b/samcli/local/lambdafn/env_vars.py index cf63bc35aa..3c2f6cabd2 100644 --- a/samcli/local/lambdafn/env_vars.py +++ b/samcli/local/lambdafn/env_vars.py @@ -5,7 +5,7 @@ import sys -class EnvironmentVariables(object): +class EnvironmentVariables: """ Use this class to get the environment variables necessary to run the Lambda function. It returns the AWS specific variables (credentials, regions, etc) along with any environment variables configured on the function. diff --git a/samcli/local/lambdafn/runtime.py b/samcli/local/lambdafn/runtime.py index 0557fa781d..9e7a835df0 100644 --- a/samcli/local/lambdafn/runtime.py +++ b/samcli/local/lambdafn/runtime.py @@ -16,7 +16,7 @@ LOG = logging.getLogger(__name__) -class LambdaRuntime(object): +class LambdaRuntime: """ This class represents a Local Lambda runtime. It can run the Lambda function code locally in a Docker container and return results. Public methods exposed by this class are similar to the AWS Lambda APIs, for convenience only. diff --git a/samcli/local/layers/layer_downloader.py b/samcli/local/layers/layer_downloader.py index e88440b7c6..2d0885ebb6 100644 --- a/samcli/local/layers/layer_downloader.py +++ b/samcli/local/layers/layer_downloader.py @@ -16,7 +16,7 @@ LOG = logging.getLogger(__name__) -class LayerDownloader(object): +class LayerDownloader: def __init__(self, layer_cache, cwd, lambda_client=None): """ diff --git a/samcli/local/services/base_local_service.py b/samcli/local/services/base_local_service.py index c0cea55a7d..0bdfd682b8 100644 --- a/samcli/local/services/base_local_service.py +++ b/samcli/local/services/base_local_service.py @@ -9,7 +9,7 @@ LOG = logging.getLogger(__name__) -class BaseLocalService(object): +class BaseLocalService: def __init__(self, is_debugging, port, host): """ Creates a BaseLocalService class @@ -78,7 +78,7 @@ def service_response(body, headers, status_code): return response -class LambdaOutputParser(object): +class LambdaOutputParser: @staticmethod def get_lambda_output(stdout_stream): """ From 134dba805a4085779755a4cb15d69242e1883a0d Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 13:09:56 -0700 Subject: [PATCH 06/42] Handle wrong-import-order --- samcli/commands/_utils/template.py | 2 +- samcli/commands/local/cli_common/invoke_context.py | 2 +- samcli/commands/local/cli_common/options.py | 3 ++- samcli/commands/validate/lib/sam_template_validator.py | 5 +++-- samcli/lib/build/app_builder.py | 6 +++--- samcli/local/docker/lambda_image.py | 4 ++-- samcli/local/lambdafn/zip.py | 4 ++-- samcli/local/layers/layer_downloader.py | 2 +- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/samcli/commands/_utils/template.py b/samcli/commands/_utils/template.py index b395c1d1e4..5232732e6a 100644 --- a/samcli/commands/_utils/template.py +++ b/samcli/commands/_utils/template.py @@ -3,9 +3,9 @@ """ import os +import pathlib import six import yaml -import pathlib from samcli.yamlhelper import yaml_parse, yaml_dump diff --git a/samcli/commands/local/cli_common/invoke_context.py b/samcli/commands/local/cli_common/invoke_context.py index 69b5953221..1ef4d0dc17 100644 --- a/samcli/commands/local/cli_common/invoke_context.py +++ b/samcli/commands/local/cli_common/invoke_context.py @@ -5,6 +5,7 @@ import errno import json import os +from pathlib import Path import samcli.lib.utils.osutils as osutils from samcli.lib.utils.stream_writer import StreamWriter @@ -17,7 +18,6 @@ from samcli.local.layers.layer_downloader import LayerDownloader from .user_exceptions import InvokeContextException, DebugContextException from ..lib.sam_function_provider import SamFunctionProvider -from pathlib import Path class InvokeContext: diff --git a/samcli/commands/local/cli_common/options.py b/samcli/commands/local/cli_common/options.py index 84e39d58c7..d98633a418 100644 --- a/samcli/commands/local/cli_common/options.py +++ b/samcli/commands/local/cli_common/options.py @@ -1,10 +1,11 @@ """ Common CLI options for invoke command """ +from pathlib import Path import click + from samcli.commands._utils.options import template_click_option, docker_click_options, parameter_override_click_option -from pathlib import Path def get_application_dir(): diff --git a/samcli/commands/validate/lib/sam_template_validator.py b/samcli/commands/validate/lib/sam_template_validator.py index 7ed8bada05..46cbae6cd7 100644 --- a/samcli/commands/validate/lib/sam_template_validator.py +++ b/samcli/commands/validate/lib/sam_template_validator.py @@ -3,12 +3,13 @@ """ import logging import functools + +import six from samtranslator.public.exceptions import InvalidDocumentException from samtranslator.parser import parser from samtranslator.translator.translator import Translator -from samcli.yamlhelper import yaml_dump -import six +from samcli.yamlhelper import yaml_dump from .exceptions import InvalidSamDocumentException LOG = logging.getLogger(__name__) diff --git a/samcli/lib/build/app_builder.py b/samcli/lib/build/app_builder.py index 6c7e75fb2a..1067da52ff 100644 --- a/samcli/lib/build/app_builder.py +++ b/samcli/lib/build/app_builder.py @@ -9,12 +9,12 @@ import pathlib import docker - -import samcli.lib.utils.osutils as osutils -from samcli.local.docker.lambda_build_container import LambdaBuildContainer from aws_lambda_builders.builder import LambdaBuilder from aws_lambda_builders.exceptions import LambdaBuilderError from aws_lambda_builders import RPC_PROTOCOL_VERSION as lambda_builders_protocol_version + +import samcli.lib.utils.osutils as osutils +from samcli.local.docker.lambda_build_container import LambdaBuildContainer from .workflow_config import get_workflow_config, supports_build_in_container diff --git a/samcli/local/docker/lambda_image.py b/samcli/local/docker/lambda_image.py index ddcc6c1eff..a8d9d418ed 100644 --- a/samcli/local/docker/lambda_image.py +++ b/samcli/local/docker/lambda_image.py @@ -1,16 +1,16 @@ """ Generates a Docker Image to be used for invoking a function locally """ -from enum import Enum import uuid import logging import hashlib +from enum import Enum +from pathlib import Path import docker from samcli.commands.local.cli_common.user_exceptions import ImageBuildException from samcli.lib.utils.tar import create_tarball -from pathlib import Path LOG = logging.getLogger(__name__) diff --git a/samcli/local/lambdafn/zip.py b/samcli/local/lambdafn/zip.py index b9a42c77a4..b421451e6d 100644 --- a/samcli/local/lambdafn/zip.py +++ b/samcli/local/lambdafn/zip.py @@ -4,13 +4,13 @@ """ import os -import zipfile import logging +import zipfile +from pathlib import Path import requests from samcli.lib.utils.progressbar import progressbar -from pathlib import Path LOG = logging.getLogger(__name__) diff --git a/samcli/local/layers/layer_downloader.py b/samcli/local/layers/layer_downloader.py index 2d0885ebb6..83b22d3505 100644 --- a/samcli/local/layers/layer_downloader.py +++ b/samcli/local/layers/layer_downloader.py @@ -3,6 +3,7 @@ """ import logging +from pathlib import Path import boto3 from botocore.exceptions import NoCredentialsError, ClientError @@ -10,7 +11,6 @@ from samcli.lib.utils.codeuri import resolve_code_path from samcli.local.lambdafn.zip import unzip_from_uri from samcli.commands.local.cli_common.user_exceptions import CredentialsRequired, ResourceNotFound -from pathlib import Path LOG = logging.getLogger(__name__) From f3970922c669af074065891dab66ac5d9e50dbe7 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 13:20:22 -0700 Subject: [PATCH 07/42] Handle inconsistent-return-statements --- samcli/cli/command.py | 6 +++--- samcli/cli/context.py | 4 ++++ samcli/commands/local/lib/cfn_api_provider.py | 2 ++ samcli/commands/local/lib/local_api_service.py | 2 ++ samcli/commands/local/lib/swagger/integration_uri.py | 1 + samcli/commands/local/lib/swagger/parser.py | 2 ++ samcli/commands/local/lib/swagger/reader.py | 12 +++++++----- samcli/commands/logs/logs_context.py | 2 +- samcli/lib/telemetry/telemetry.py | 2 ++ .../lambda_service/local_lambda_invoke_service.py | 2 ++ samcli/local/lambdafn/runtime.py | 1 + 11 files changed, 27 insertions(+), 9 deletions(-) diff --git a/samcli/cli/command.py b/samcli/cli/command.py index e7fca789ce..d5aa0c87b6 100644 --- a/samcli/cli/command.py +++ b/samcli/cli/command.py @@ -109,7 +109,7 @@ def get_command(self, ctx, cmd_name): """ if cmd_name not in self._commands: logger.error("Command %s not available", cmd_name) - return + return None pkg_name = self._commands[cmd_name] @@ -117,10 +117,10 @@ def get_command(self, ctx, cmd_name): mod = importlib.import_module(pkg_name) except ImportError: logger.exception("Command '%s' is not configured correctly. Unable to import '%s'", cmd_name, pkg_name) - return + return None if not hasattr(mod, "cli"): logger.error("Command %s is not configured correctly. It must expose an function called 'cli'", cmd_name) - return + return None return mod.cli diff --git a/samcli/cli/context.py b/samcli/cli/context.py index aab43b0c73..f1d220598e 100644 --- a/samcli/cli/context.py +++ b/samcli/cli/context.py @@ -98,6 +98,8 @@ def command_path(self): if click_core_ctx: return click_core_ctx.command_path + return None + @staticmethod def get_current_context(): """ @@ -129,6 +131,8 @@ def my_command_handler(ctx): if click_core_ctx: return click_core_ctx.find_object(Context) or click_core_ctx.ensure_object(Context) + return None + def _refresh_session(self): """ Update boto3's default session by creating a new session based on values set in the context. Some properties of diff --git a/samcli/commands/local/lib/cfn_api_provider.py b/samcli/commands/local/lib/cfn_api_provider.py index e844464eee..70ae3cbd43 100644 --- a/samcli/commands/local/lib/cfn_api_provider.py +++ b/samcli/commands/local/lib/cfn_api_provider.py @@ -211,3 +211,5 @@ def _get_integration_function_name(integration): if integration and isinstance(integration, dict): # Integration must be "aws_proxy" otherwise we don't care about it return LambdaUri.get_function_name(integration.get("Uri")) + + return None diff --git a/samcli/commands/local/lib/local_api_service.py b/samcli/commands/local/lib/local_api_service.py index e892bb847e..8af4f784e5 100644 --- a/samcli/commands/local/lib/local_api_service.py +++ b/samcli/commands/local/lib/local_api_service.py @@ -129,3 +129,5 @@ def _make_static_dir_path(cwd, static_dir): if os.path.exists(static_dir_path): LOG.info("Mounting static files from %s at /", static_dir_path) return static_dir_path + + return None diff --git a/samcli/commands/local/lib/swagger/integration_uri.py b/samcli/commands/local/lib/swagger/integration_uri.py index edda321027..22a6f1e3cf 100644 --- a/samcli/commands/local/lib/swagger/integration_uri.py +++ b/samcli/commands/local/lib/swagger/integration_uri.py @@ -167,6 +167,7 @@ def _get_function_name_from_arn(function_arn): # Some unknown format LOG.debug("Ignoring integration ARN. Unable to parse Function Name from function arn %s", function_arn) + return None @staticmethod def _resolve_fn_sub(uri_data): diff --git a/samcli/commands/local/lib/swagger/parser.py b/samcli/commands/local/lib/swagger/parser.py index a0ea9fa436..f5488aee4f 100644 --- a/samcli/commands/local/lib/swagger/parser.py +++ b/samcli/commands/local/lib/swagger/parser.py @@ -114,3 +114,5 @@ def _get_integration_function_name(self, method_config): if integration and isinstance(integration, dict) and integration.get("type") == IntegrationType.aws_proxy.value: # Integration must be "aws_proxy" otherwise we don't care about it return LambdaUri.get_function_name(integration.get("uri")) + + return None diff --git a/samcli/commands/local/lib/swagger/reader.py b/samcli/commands/local/lib/swagger/reader.py index 03a1a07e72..264899db4e 100644 --- a/samcli/commands/local/lib/swagger/reader.py +++ b/samcli/commands/local/lib/swagger/reader.py @@ -43,10 +43,10 @@ def parse_aws_include_transform(data): """ if not data: - return + return None if _FN_TRANSFORM not in data: - return + return None transform_data = data[_FN_TRANSFORM] @@ -56,6 +56,8 @@ def parse_aws_include_transform(data): LOG.debug("Successfully parsed location from AWS::Include transform: %s", location) return location + return None + class SwaggerReader: """ @@ -152,7 +154,7 @@ def _download_swagger(self, location): """ if not location: - return + return None bucket, key, version = self._parse_s3_location(location) if bucket and key: @@ -163,7 +165,7 @@ def _download_swagger(self, location): if not isinstance(location, string_types): # This is not a string and not a S3 Location dictionary. Probably something invalid LOG.debug("Unable to download Swagger file. Invalid location: %s", location) - return + return None # ``location`` is a string and not a S3 path. It is probably a local path. Let's resolve relative path if any filepath = location @@ -173,7 +175,7 @@ def _download_swagger(self, location): if not os.path.exists(filepath): LOG.debug("Unable to download Swagger file. File not found at location %s", filepath) - return + return None LOG.debug("Reading Swagger document from local file at %s", filepath) with open(filepath, "r") as fp: diff --git a/samcli/commands/logs/logs_context.py b/samcli/commands/logs/logs_context.py index 2159e92d1a..ef059eddf0 100644 --- a/samcli/commands/logs/logs_context.py +++ b/samcli/commands/logs/logs_context.py @@ -209,7 +209,7 @@ def _parse_time(time_str, property_name): If the string cannot be parsed as a timestamp """ if not time_str: - return + return None parsed = parse_date(time_str) if not parsed: diff --git a/samcli/lib/telemetry/telemetry.py b/samcli/lib/telemetry/telemetry.py index 1c3a85eb72..40a8f7cc7a 100644 --- a/samcli/lib/telemetry/telemetry.py +++ b/samcli/lib/telemetry/telemetry.py @@ -109,6 +109,8 @@ def _default_session_id(self): if ctx: return ctx.session_id + return None + def _get_execution_environment(self): """ Returns the environment in which SAM CLI is running. Possible options are: diff --git a/samcli/local/lambda_service/local_lambda_invoke_service.py b/samcli/local/lambda_service/local_lambda_invoke_service.py index b41072e606..30c8aa9477 100644 --- a/samcli/local/lambda_service/local_lambda_invoke_service.py +++ b/samcli/local/lambda_service/local_lambda_invoke_service.py @@ -110,6 +110,8 @@ def validate_request(): "invocation-type: {} is not supported. RequestResponse is only supported.".format(invocation_type) ) + return None + def _construct_error_handling(self): """ Updates the Flask app with Error Handlers for different Error Codes diff --git a/samcli/local/lambdafn/runtime.py b/samcli/local/lambdafn/runtime.py index 9e7a835df0..05da88868c 100644 --- a/samcli/local/lambdafn/runtime.py +++ b/samcli/local/lambdafn/runtime.py @@ -137,6 +137,7 @@ def signal_handler(sig, frame): if is_debugging: LOG.debug("Setting up SIGTERM interrupt handler") signal.signal(signal.SIGTERM, signal_handler) + return None else: # Start a timer, we'll use this to abort the function if it runs beyond the specified timeout LOG.debug("Starting a timer for %s seconds for function '%s'", timeout, function_name) From 8870014424b42b4f97b0ddfc5a8440d3bd0dcd2c Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 13:22:24 -0700 Subject: [PATCH 08/42] Handle keyword-arg-before-vararg --- samcli/cli/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samcli/cli/command.py b/samcli/cli/command.py index d5aa0c87b6..ca1fdee333 100644 --- a/samcli/cli/command.py +++ b/samcli/cli/command.py @@ -53,7 +53,7 @@ class BaseCommand(click.MultiCommand): will produce a command name "baz". """ - def __init__(self, cmd_packages=None, *args, **kwargs): + def __init__(self, *args, cmd_packages=None, **kwargs): """ Initializes the class, optionally with a list of available commands From af4ba9a3fce38fb8bf2f35313a14484e21a3db60 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 13:26:06 -0700 Subject: [PATCH 09/42] Handle raising-format-tuple --- samcli/commands/build/build_context.py | 2 +- samcli/commands/local/lib/local_lambda.py | 2 +- samcli/local/apigw/local_apigw_service.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samcli/commands/build/build_context.py b/samcli/commands/build/build_context.py index 71adfddd81..8d4a166fdb 100644 --- a/samcli/commands/build/build_context.py +++ b/samcli/commands/build/build_context.py @@ -146,7 +146,7 @@ def functions_to_build(self): available_function_message = "{} not found. Possible options in your template: {}" \ .format(self._function_identifier, all_functions) LOG.info(available_function_message) - raise FunctionNotFound("Unable to find a Function with name '%s'", self._function_identifier) + raise FunctionNotFound("Unable to find a Function with name '{}'".format(self._function_identifier)) return [function] diff --git a/samcli/commands/local/lib/local_lambda.py b/samcli/commands/local/lib/local_lambda.py index d189bcb8be..199f253a95 100644 --- a/samcli/commands/local/lib/local_lambda.py +++ b/samcli/commands/local/lib/local_lambda.py @@ -86,7 +86,7 @@ def invoke(self, function_name, event, stdout=None, stderr=None): function_name, all_functions ) LOG.info(available_function_message) - raise FunctionNotFound("Unable to find a Function with name '%s'", function_name) + raise FunctionNotFound("Unable to find a Function with name '{}'".format(function_name)) LOG.debug("Found one Lambda function with name '%s'", function_name) diff --git a/samcli/local/apigw/local_apigw_service.py b/samcli/local/apigw/local_apigw_service.py index 4a3507bc9c..e11191ec31 100644 --- a/samcli/local/apigw/local_apigw_service.py +++ b/samcli/local/apigw/local_apigw_service.py @@ -260,7 +260,7 @@ def _parse_lambda_output(lambda_output, binary_types, flask_request): json_output = json.loads(lambda_output) if not isinstance(json_output, dict): - raise TypeError("Lambda returned %{s} instead of dict", type(json_output)) + raise TypeError("Lambda returned {} instead of dict".format(type(json_output))) status_code = json_output.get("statusCode") or 200 headers = LocalApigwService._merge_response_headers( From 21e3e9bc6c6fc07651847a7a39dcbbf3abfd196f Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 13:29:59 -0700 Subject: [PATCH 10/42] Handle no-else-return --- samcli/commands/local/cli_common/invoke_context.py | 4 ++-- samcli/commands/local/lib/api_provider.py | 3 ++- samcli/commands/local/lib/swagger/integration_uri.py | 2 +- samcli/lib/build/app_builder.py | 5 ++--- .../intrinsic_property_resolver.py | 3 ++- samcli/local/lambdafn/runtime.py | 12 ++++++------ 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/samcli/commands/local/cli_common/invoke_context.py b/samcli/commands/local/cli_common/invoke_context.py index 1ef4d0dc17..b9f41465cf 100644 --- a/samcli/commands/local/cli_common/invoke_context.py +++ b/samcli/commands/local/cli_common/invoke_context.py @@ -343,8 +343,8 @@ def _get_debug_context(debug_port, debug_args, debugger_path): except OSError as error: if error.errno == errno.ENOENT: raise DebugContextException("'{}' could not be found.".format(debugger_path)) - else: - raise error + + raise error # We turn off pylint here due to https://github.com/PyCQA/pylint/issues/1660 if not debugger.is_dir(): # pylint: disable=no-member diff --git a/samcli/commands/local/lib/api_provider.py b/samcli/commands/local/lib/api_provider.py index 6e074bda02..dd244f6d7c 100644 --- a/samcli/commands/local/lib/api_provider.py +++ b/samcli/commands/local/lib/api_provider.py @@ -87,7 +87,8 @@ def find_api_provider(resources): for _, resource in resources.items(): if resource.get(CfnBaseApiProvider.RESOURCE_TYPE) in SamApiProvider.TYPES: return SamApiProvider() - elif resource.get(CfnBaseApiProvider.RESOURCE_TYPE) in CfnApiProvider.TYPES: + + if resource.get(CfnBaseApiProvider.RESOURCE_TYPE) in CfnApiProvider.TYPES: return CfnApiProvider() return SamApiProvider() diff --git a/samcli/commands/local/lib/swagger/integration_uri.py b/samcli/commands/local/lib/swagger/integration_uri.py index 22a6f1e3cf..cab183bfb8 100644 --- a/samcli/commands/local/lib/swagger/integration_uri.py +++ b/samcli/commands/local/lib/swagger/integration_uri.py @@ -161,7 +161,7 @@ def _get_function_name_from_arn(function_arn): LOG.debug("Stage variables are not supported. Ignoring integration with function ARN %s", function_arn) return None - elif re.match(LambdaUri._REGEX_VALID_FUNCTION_NAME, maybe_function_name): + if re.match(LambdaUri._REGEX_VALID_FUNCTION_NAME, maybe_function_name): # Yes, this is a real function name return maybe_function_name diff --git a/samcli/lib/build/app_builder.py b/samcli/lib/build/app_builder.py index 1067da52ff..186814f6bd 100644 --- a/samcli/lib/build/app_builder.py +++ b/samcli/lib/build/app_builder.py @@ -318,8 +318,7 @@ def _parse_builder_response(stdout_data, image_name): LOG.debug("Builder library does not support the supplied method") raise UnsupportedBuilderLibraryVersionError(image_name, msg) - else: - LOG.debug("Builder crashed") - raise ValueError(msg) + LOG.debug("Builder crashed") + raise ValueError(msg) return response diff --git a/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py b/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py index 32ab4c89cc..110d998448 100644 --- a/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py +++ b/samcli/lib/intrinsic_resolver/intrinsic_property_resolver.py @@ -206,7 +206,8 @@ def intrinsic_property_resolver(self, intrinsic, ignore_errors, parent_function= if key in self.intrinsic_key_function_map: intrinsic_value = intrinsic.get(key) return self.intrinsic_key_function_map.get(key)(intrinsic_value, ignore_errors) - elif key in self.conditional_key_function_map: + + if key in self.conditional_key_function_map: intrinsic_value = intrinsic.get(key) return self.conditional_key_function_map.get(key)(intrinsic_value, ignore_errors) diff --git a/samcli/local/lambdafn/runtime.py b/samcli/local/lambdafn/runtime.py index 05da88868c..cc9116d522 100644 --- a/samcli/local/lambdafn/runtime.py +++ b/samcli/local/lambdafn/runtime.py @@ -138,12 +138,12 @@ def signal_handler(sig, frame): LOG.debug("Setting up SIGTERM interrupt handler") signal.signal(signal.SIGTERM, signal_handler) return None - else: - # Start a timer, we'll use this to abort the function if it runs beyond the specified timeout - LOG.debug("Starting a timer for %s seconds for function '%s'", timeout, function_name) - timer = threading.Timer(timeout, timer_handler, ()) - timer.start() - return timer + + # Start a timer, we'll use this to abort the function if it runs beyond the specified timeout + LOG.debug("Starting a timer for %s seconds for function '%s'", timeout, function_name) + timer = threading.Timer(timeout, timer_handler, ()) + timer.start() + return timer @contextmanager def _get_code_dir(self, code_path): From 65f72c45d9079323bdf872d942249a1459407998 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 13:36:38 -0700 Subject: [PATCH 11/42] Handle consider-using-in --- samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py b/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py index 748698c397..3a3725f0ef 100644 --- a/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py +++ b/samcli/lib/intrinsic_resolver/intrinsics_symbol_table.py @@ -286,7 +286,7 @@ def get_translation(self, logical_id, resource_attributes=IntrinsicResolver.REF) """ logical_id_item = self.logical_id_translator.get(logical_id, {}) if any(isinstance(logical_id_item, object_type) for object_type in [string_types, list, bool, int]): - if resource_attributes != IntrinsicResolver.REF and resource_attributes != "": + if resource_attributes not in (IntrinsicResolver.REF, ""): return None return logical_id_item From ac77973454290885e8f4138ff9ca7b7e0e0b72c1 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 13:39:05 -0700 Subject: [PATCH 12/42] Handle onsider-using-set-comprehension --- samcli/local/common/runtime_template.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/samcli/local/common/runtime_template.py b/samcli/local/common/runtime_template.py index 02110671e9..a9e28025f2 100644 --- a/samcli/local/common/runtime_template.py +++ b/samcli/local/common/runtime_template.py @@ -74,13 +74,12 @@ ], } -SUPPORTED_DEP_MANAGERS = set( - [ +SUPPORTED_DEP_MANAGERS = { c["dependency_manager"] for c in list(itertools.chain(*(RUNTIME_DEP_TEMPLATE_MAPPING.values()))) if c["dependency_manager"] - ] -) + } + RUNTIMES = set( itertools.chain(*[c["runtimes"] for c in list(itertools.chain(*(RUNTIME_DEP_TEMPLATE_MAPPING.values())))]) ) From 9204ae2cb6f54cdf555edf3c4e5e7711a876ea56 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 14:00:29 -0700 Subject: [PATCH 13/42] move from 'from mock' to 'from unittest.mock' since mock is now in the std --- .../commands/cli/test_global_config.py | 2 +- .../local/lib/test_local_api_service.py | 2 +- .../commands/local/lib/test_local_lambda.py | 2 +- .../lib/test_sam_template_validator.py | 2 +- .../local/apigw/test_local_apigw_service.py | 2 +- .../test_local_lambda_invoke.py | 2 +- .../telemetry/test_installed_metric.py | 2 +- tests/unit/cli/test_command.py | 2 +- tests/unit/cli/test_context.py | 2 +- tests/unit/cli/test_global_config.py | 2 +- tests/unit/cli/test_main.py | 26 +++++++++---------- tests/unit/cli/test_types.py | 2 +- tests/unit/commands/_utils/test_options.py | 2 +- tests/unit/commands/_utils/test_template.py | 2 +- .../commands/buildcmd/test_build_context.py | 2 +- tests/unit/commands/buildcmd/test_command.py | 2 +- tests/unit/commands/init/test_cli.py | 2 +- .../local/cli_common/test_invoke_context.py | 2 +- .../generate_event/test_event_generation.py | 3 +-- tests/unit/commands/local/invoke/test_cli.py | 2 +- .../commands/local/lib/swagger/test_parser.py | 2 +- .../commands/local/lib/swagger/test_reader.py | 2 +- .../commands/local/lib/test_api_provider.py | 2 +- .../local/lib/test_cfn_api_provider.py | 2 +- .../local/lib/test_local_api_service.py | 2 +- .../commands/local/lib/test_local_lambda.py | 2 +- .../local/lib/test_local_lambda_service.py | 2 +- .../local/lib/test_sam_api_provider.py | 2 +- .../local/lib/test_sam_base_provider.py | 2 +- .../local/lib/test_sam_function_provider.py | 2 +- .../unit/commands/local/start_api/test_cli.py | 2 +- .../commands/local/start_lambda/test_cli.py | 2 +- tests/unit/commands/logs/test_command.py | 2 +- tests/unit/commands/logs/test_logs_context.py | 2 +- tests/unit/commands/publish/test_command.py | 2 +- tests/unit/commands/test_deploy.py | 2 +- tests/unit/commands/test_package.py | 2 +- .../lib/test_sam_template_validator.py | 2 +- tests/unit/commands/validate/test_cli.py | 2 +- .../unit/lib/build_module/test_app_builder.py | 2 +- .../lib/build_module/test_workflow_config.py | 2 +- .../test_intrinsics_symbol_table.py | 2 +- tests/unit/lib/logs/test_fetcher.py | 2 +- tests/unit/lib/logs/test_formatter.py | 2 +- .../lib/samlib/test_cloudformation_command.py | 2 +- tests/unit/lib/telemetry/test_metrics.py | 2 +- tests/unit/lib/telemetry/test_telemetry.py | 2 +- tests/unit/lib/utils/test_progressbar.py | 2 +- tests/unit/lib/utils/test_sam_logging.py | 2 +- tests/unit/lib/utils/test_stream_writer.py | 2 +- tests/unit/lib/utils/test_tar.py | 2 +- .../local/apigw/test_local_apigw_service.py | 2 +- .../apigw/test_service_error_responses.py | 2 +- tests/unit/local/docker/test_container.py | 2 +- .../docker/test_lambda_build_container.py | 2 +- .../local/docker/test_lambda_container.py | 2 +- tests/unit/local/docker/test_lambda_image.py | 2 +- tests/unit/local/docker/test_manager.py | 2 +- tests/unit/local/docker/test_utils.py | 3 +-- tests/unit/local/events/test_api_event.py | 2 +- tests/unit/local/init/test_init.py | 2 +- .../test_lambda_error_responses.py | 2 +- .../test_local_lambda_invoke_service.py | 2 +- tests/unit/local/lambdafn/test_config.py | 2 +- tests/unit/local/lambdafn/test_runtime.py | 2 +- tests/unit/local/lambdafn/test_zip.py | 2 +- .../unit/local/layers/test_download_layers.py | 2 +- .../local/services/test_base_local_service.py | 2 +- 68 files changed, 80 insertions(+), 82 deletions(-) diff --git a/tests/functional/commands/cli/test_global_config.py b/tests/functional/commands/cli/test_global_config.py index e156a2e872..ed550f762a 100644 --- a/tests/functional/commands/cli/test_global_config.py +++ b/tests/functional/commands/cli/test_global_config.py @@ -2,7 +2,7 @@ import tempfile import shutil -from mock import mock_open, patch +from unittest.mock import mock_open, patch from unittest import TestCase from json import JSONDecodeError from samcli.cli.global_config import GlobalConfig diff --git a/tests/functional/commands/local/lib/test_local_api_service.py b/tests/functional/commands/local/lib/test_local_api_service.py index 50131b2f1c..35077aab07 100644 --- a/tests/functional/commands/local/lib/test_local_api_service.py +++ b/tests/functional/commands/local/lib/test_local_api_service.py @@ -22,7 +22,7 @@ from tests.functional.function_code import nodejs_lambda, API_GATEWAY_ECHO_EVENT from unittest import TestCase -from mock import Mock, patch +from unittest.mock import Mock, patch logging.basicConfig(level=logging.INFO) diff --git a/tests/functional/commands/local/lib/test_local_lambda.py b/tests/functional/commands/local/lib/test_local_lambda.py index 19d1c1569a..55fa875c18 100644 --- a/tests/functional/commands/local/lib/test_local_lambda.py +++ b/tests/functional/commands/local/lib/test_local_lambda.py @@ -18,7 +18,7 @@ from tests.functional.function_code import nodejs_lambda, GET_ENV_VAR from unittest import TestCase -from mock import Mock +from unittest.mock import Mock logging.basicConfig(level=logging.INFO) diff --git a/tests/functional/commands/validate/lib/test_sam_template_validator.py b/tests/functional/commands/validate/lib/test_sam_template_validator.py index f421a0d4ec..a9610e46e8 100644 --- a/tests/functional/commands/validate/lib/test_sam_template_validator.py +++ b/tests/functional/commands/validate/lib/test_sam_template_validator.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import Mock +from unittest.mock import Mock from parameterized import parameterized import samcli.yamlhelper as yamlhelper diff --git a/tests/functional/local/apigw/test_local_apigw_service.py b/tests/functional/local/apigw/test_local_apigw_service.py index 78b9c6b47a..38bd9b3cfe 100644 --- a/tests/functional/local/apigw/test_local_apigw_service.py +++ b/tests/functional/local/apigw/test_local_apigw_service.py @@ -7,7 +7,7 @@ import requests import random -from mock import Mock +from unittest.mock import Mock from samcli.local.apigw.local_apigw_service import Route, LocalApigwService from tests.functional.function_code import ( diff --git a/tests/functional/local/lambda_service/test_local_lambda_invoke.py b/tests/functional/local/lambda_service/test_local_lambda_invoke.py index 4c4489f1df..a4db580f55 100644 --- a/tests/functional/local/lambda_service/test_local_lambda_invoke.py +++ b/tests/functional/local/lambda_service/test_local_lambda_invoke.py @@ -1,7 +1,7 @@ import threading import shutil import random -from mock import Mock +from unittest.mock import Mock import time from unittest import TestCase import os diff --git a/tests/integration/telemetry/test_installed_metric.py b/tests/integration/telemetry/test_installed_metric.py index bc1518bf21..fa4d3b679b 100644 --- a/tests/integration/telemetry/test_installed_metric.py +++ b/tests/integration/telemetry/test_installed_metric.py @@ -1,6 +1,6 @@ import platform -from mock import ANY +from unittest.mock import ANY from .integ_base import IntegBase, TelemetryServer, EXPECTED_TELEMETRY_PROMPT from samcli import __version__ as SAM_CLI_VERSION diff --git a/tests/unit/cli/test_command.py b/tests/unit/cli/test_command.py index 082af8bc8c..4c51d35c0f 100644 --- a/tests/unit/cli/test_command.py +++ b/tests/unit/cli/test_command.py @@ -1,7 +1,7 @@ import click from unittest import TestCase -from mock import Mock, patch, call +from unittest.mock import Mock, patch, call from samcli.cli.command import BaseCommand diff --git a/tests/unit/cli/test_context.py b/tests/unit/cli/test_context.py index 7bd04e4ca9..403df2539b 100644 --- a/tests/unit/cli/test_context.py +++ b/tests/unit/cli/test_context.py @@ -2,7 +2,7 @@ import logging from unittest import TestCase -from mock import patch +from unittest.mock import patch from samcli.cli.context import Context diff --git a/tests/unit/cli/test_global_config.py b/tests/unit/cli/test_global_config.py index 43a394bbb0..5432488303 100644 --- a/tests/unit/cli/test_global_config.py +++ b/tests/unit/cli/test_global_config.py @@ -1,4 +1,4 @@ -from mock import mock_open, patch, Mock +from unittest.mock import mock_open, patch, Mock from unittest import TestCase from parameterized import parameterized from samcli.cli.global_config import GlobalConfig diff --git a/tests/unit/cli/test_main.py b/tests/unit/cli/test_main.py index 486d4154f1..3a94bc000e 100644 --- a/tests/unit/cli/test_main.py +++ b/tests/unit/cli/test_main.py @@ -1,4 +1,4 @@ -import mock +from unittest.mock import patch, Mock, PropertyMock from unittest import TestCase from click.testing import CliRunner @@ -11,8 +11,8 @@ def test_cli_base(self): Just invoke the CLI without any commands and assert that help text was printed :return: """ - mock_cfg = mock.Mock() - with mock.patch("samcli.cli.main.global_cfg", mock_cfg): + mock_cfg = Mock() + with patch("samcli.cli.main.global_cfg", mock_cfg): runner = CliRunner() result = runner.invoke(cli, []) self.assertEqual(result.exit_code, 0) @@ -21,24 +21,24 @@ def test_cli_base(self): def test_cli_some_command(self): - mock_cfg = mock.Mock() - with mock.patch("samcli.cli.main.global_cfg", mock_cfg): + mock_cfg = Mock() + with patch("samcli.cli.main.global_cfg", mock_cfg): runner = CliRunner() result = runner.invoke(cli, ["local", "generate-event", "s3"]) self.assertEqual(result.exit_code, 0) def test_cli_with_debug(self): - mock_cfg = mock.Mock() - with mock.patch("samcli.cli.main.global_cfg", mock_cfg): + mock_cfg = Mock() + with patch("samcli.cli.main.global_cfg", mock_cfg): runner = CliRunner() result = runner.invoke(cli, ["local", "generate-event", "s3", "put", "--debug"]) self.assertEqual(result.exit_code, 0) - @mock.patch("samcli.cli.main.send_installed_metric") + @patch("samcli.cli.main.send_installed_metric") def test_cli_enable_telemetry_with_prompt(self, send_installed_metric_mock): - with mock.patch( - "samcli.cli.global_config.GlobalConfig.telemetry_enabled", new_callable=mock.PropertyMock + with patch( + "samcli.cli.global_config.GlobalConfig.telemetry_enabled", new_callable=PropertyMock ) as mock_flag: mock_flag.return_value = None runner = CliRunner() @@ -48,10 +48,10 @@ def test_cli_enable_telemetry_with_prompt(self, send_installed_metric_mock): # If telemetry is enabled, this should be called send_installed_metric_mock.assert_called_once() - @mock.patch("samcli.cli.main.send_installed_metric") + @patch("samcli.cli.main.send_installed_metric") def test_prompt_skipped_when_value_set(self, send_installed_metric_mock): - with mock.patch( - "samcli.cli.global_config.GlobalConfig.telemetry_enabled", new_callable=mock.PropertyMock + with patch( + "samcli.cli.global_config.GlobalConfig.telemetry_enabled", new_callable=PropertyMock ) as mock_flag: mock_flag.return_value = True runner = CliRunner() diff --git a/tests/unit/cli/test_types.py b/tests/unit/cli/test_types.py index a46b72f9d1..1251392c88 100644 --- a/tests/unit/cli/test_types.py +++ b/tests/unit/cli/test_types.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import Mock, ANY +from unittest.mock import Mock, ANY from nose_parameterized import parameterized from samcli.cli.types import CfnParameterOverridesType diff --git a/tests/unit/commands/_utils/test_options.py b/tests/unit/commands/_utils/test_options.py index 44bad654fb..43276c824c 100644 --- a/tests/unit/commands/_utils/test_options.py +++ b/tests/unit/commands/_utils/test_options.py @@ -5,7 +5,7 @@ import os from unittest import TestCase -from mock import patch +from unittest.mock import patch from samcli.commands._utils.options import get_or_default_template_file_name, _TEMPLATE_OPTION_DEFAULT_VALUE diff --git a/tests/unit/commands/_utils/test_template.py b/tests/unit/commands/_utils/test_template.py index 6d1b8575e6..04cd9b0b5c 100644 --- a/tests/unit/commands/_utils/test_template.py +++ b/tests/unit/commands/_utils/test_template.py @@ -3,7 +3,7 @@ import yaml from unittest import TestCase -from mock import patch, mock_open +from unittest.mock import patch, mock_open from parameterized import parameterized, param from samcli.commands._utils.template import ( diff --git a/tests/unit/commands/buildcmd/test_build_context.py b/tests/unit/commands/buildcmd/test_build_context.py index 7d087336b7..10be5be039 100644 --- a/tests/unit/commands/buildcmd/test_build_context.py +++ b/tests/unit/commands/buildcmd/test_build_context.py @@ -1,6 +1,6 @@ import os from unittest import TestCase -from mock import patch, Mock +from unittest.mock import patch, Mock from samcli.commands.build.build_context import BuildContext from samcli.commands.build.exceptions import InvalidBuildDirException diff --git a/tests/unit/commands/buildcmd/test_command.py b/tests/unit/commands/buildcmd/test_command.py index b609ad0402..d6880955c6 100644 --- a/tests/unit/commands/buildcmd/test_command.py +++ b/tests/unit/commands/buildcmd/test_command.py @@ -2,7 +2,7 @@ import click from unittest import TestCase -from mock import Mock, patch +from unittest.mock import Mock, patch from parameterized import parameterized from samcli.commands.build.command import do_cli, _get_mode_value_from_envvar diff --git a/tests/unit/commands/init/test_cli.py b/tests/unit/commands/init/test_cli.py index 4034d5b10d..2754fe6352 100644 --- a/tests/unit/commands/init/test_cli.py +++ b/tests/unit/commands/init/test_cli.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import patch +from unittest.mock import patch from samcli.commands.init import do_cli as init_cli from samcli.local.init.exceptions import GenerateProjectFailedError diff --git a/tests/unit/commands/local/cli_common/test_invoke_context.py b/tests/unit/commands/local/cli_common/test_invoke_context.py index 14e60e9030..ccc95d112b 100644 --- a/tests/unit/commands/local/cli_common/test_invoke_context.py +++ b/tests/unit/commands/local/cli_common/test_invoke_context.py @@ -8,7 +8,7 @@ from samcli.commands.local.cli_common.invoke_context import InvokeContext from unittest import TestCase -from mock import Mock, PropertyMock, patch, ANY, mock_open +from unittest.mock import Mock, PropertyMock, patch, ANY, mock_open class TestInvokeContext__enter__(TestCase): diff --git a/tests/unit/commands/local/generate_event/test_event_generation.py b/tests/unit/commands/local/generate_event/test_event_generation.py index 1b5a5ea730..d719fb45db 100644 --- a/tests/unit/commands/local/generate_event/test_event_generation.py +++ b/tests/unit/commands/local/generate_event/test_event_generation.py @@ -1,8 +1,7 @@ import os from unittest import TestCase -from mock import Mock -from mock import patch +from unittest.mock import Mock, patch from samcli.commands.local.lib.generated_sample_events import events from samcli.commands.local.generate_event.event_generation import ServiceCommand diff --git a/tests/unit/commands/local/invoke/test_cli.py b/tests/unit/commands/local/invoke/test_cli.py index a15448833b..d38e12b338 100644 --- a/tests/unit/commands/local/invoke/test_cli.py +++ b/tests/unit/commands/local/invoke/test_cli.py @@ -3,7 +3,7 @@ """ from unittest import TestCase -from mock import patch, Mock +from unittest.mock import patch, Mock from parameterized import parameterized, param from samcli.local.lambdafn.exceptions import FunctionNotFound diff --git a/tests/unit/commands/local/lib/swagger/test_parser.py b/tests/unit/commands/local/lib/swagger/test_parser.py index f5cf36bce9..6468332db8 100644 --- a/tests/unit/commands/local/lib/swagger/test_parser.py +++ b/tests/unit/commands/local/lib/swagger/test_parser.py @@ -3,7 +3,7 @@ """ from unittest import TestCase -from mock import patch, Mock +from unittest.mock import patch, Mock from parameterized import parameterized, param from samcli.commands.local.lib.swagger.parser import SwaggerParser diff --git a/tests/unit/commands/local/lib/swagger/test_reader.py b/tests/unit/commands/local/lib/swagger/test_reader.py index 9e71ce7bdc..81d52561bd 100644 --- a/tests/unit/commands/local/lib/swagger/test_reader.py +++ b/tests/unit/commands/local/lib/swagger/test_reader.py @@ -5,7 +5,7 @@ from unittest import TestCase from parameterized import parameterized, param -from mock import Mock, patch +from unittest.mock import Mock, patch from samcli.commands.local.lib.swagger.reader import parse_aws_include_transform, SwaggerReader diff --git a/tests/unit/commands/local/lib/test_api_provider.py b/tests/unit/commands/local/lib/test_api_provider.py index 426fa37d05..3fcc0404ed 100644 --- a/tests/unit/commands/local/lib/test_api_provider.py +++ b/tests/unit/commands/local/lib/test_api_provider.py @@ -1,7 +1,7 @@ from collections import OrderedDict from unittest import TestCase -from mock import patch +from unittest.mock import patch from samcli.commands.local.lib.provider import Api from samcli.commands.local.lib.api_provider import ApiProvider diff --git a/tests/unit/commands/local/lib/test_cfn_api_provider.py b/tests/unit/commands/local/lib/test_cfn_api_provider.py index cbf5d40d2e..d81822bb01 100644 --- a/tests/unit/commands/local/lib/test_cfn_api_provider.py +++ b/tests/unit/commands/local/lib/test_cfn_api_provider.py @@ -3,7 +3,7 @@ from collections import OrderedDict from unittest import TestCase -from mock import patch +from unittest.mock import patch from six import assertCountEqual from samcli.commands.local.lib.api_provider import ApiProvider diff --git a/tests/unit/commands/local/lib/test_local_api_service.py b/tests/unit/commands/local/lib/test_local_api_service.py index 758007c6c5..d695d4ca9d 100644 --- a/tests/unit/commands/local/lib/test_local_api_service.py +++ b/tests/unit/commands/local/lib/test_local_api_service.py @@ -4,7 +4,7 @@ from unittest import TestCase -from mock import Mock, patch +from unittest.mock import Mock, patch from samcli.commands.local.lib.provider import Api from samcli.commands.local.lib.api_collector import ApiCollector diff --git a/tests/unit/commands/local/lib/test_local_lambda.py b/tests/unit/commands/local/lib/test_local_lambda.py index ee9f5ced3f..9a81491980 100644 --- a/tests/unit/commands/local/lib/test_local_lambda.py +++ b/tests/unit/commands/local/lib/test_local_lambda.py @@ -2,7 +2,7 @@ Testing local lambda runner """ from unittest import TestCase -from mock import Mock, patch +from unittest.mock import Mock, patch from parameterized import parameterized, param from samcli.commands.local.lib.local_lambda import LocalLambdaRunner diff --git a/tests/unit/commands/local/lib/test_local_lambda_service.py b/tests/unit/commands/local/lib/test_local_lambda_service.py index f4efd8a148..da28d4711f 100644 --- a/tests/unit/commands/local/lib/test_local_lambda_service.py +++ b/tests/unit/commands/local/lib/test_local_lambda_service.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import Mock, patch +from unittest.mock import Mock, patch from samcli.commands.local.lib.local_lambda_service import LocalLambdaService diff --git a/tests/unit/commands/local/lib/test_sam_api_provider.py b/tests/unit/commands/local/lib/test_sam_api_provider.py index 7530dcb6bf..4dc1655dfe 100644 --- a/tests/unit/commands/local/lib/test_sam_api_provider.py +++ b/tests/unit/commands/local/lib/test_sam_api_provider.py @@ -3,7 +3,7 @@ from collections import OrderedDict from unittest import TestCase -from mock import patch +from unittest.mock import patch from nose_parameterized import parameterized from six import assertCountEqual diff --git a/tests/unit/commands/local/lib/test_sam_base_provider.py b/tests/unit/commands/local/lib/test_sam_base_provider.py index 0eebe68522..2123aac4c8 100644 --- a/tests/unit/commands/local/lib/test_sam_base_provider.py +++ b/tests/unit/commands/local/lib/test_sam_base_provider.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import Mock, patch +from unittest.mock import Mock, patch from samcli.commands.local.lib.sam_base_provider import SamBaseProvider from samcli.lib.intrinsic_resolver.intrinsic_property_resolver import IntrinsicResolver diff --git a/tests/unit/commands/local/lib/test_sam_function_provider.py b/tests/unit/commands/local/lib/test_sam_function_provider.py index 6973356e0d..9b8e679159 100644 --- a/tests/unit/commands/local/lib/test_sam_function_provider.py +++ b/tests/unit/commands/local/lib/test_sam_function_provider.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import patch +from unittest.mock import patch from parameterized import parameterized from samcli.commands.local.cli_common.user_exceptions import InvalidLayerVersionArn diff --git a/tests/unit/commands/local/start_api/test_cli.py b/tests/unit/commands/local/start_api/test_cli.py index b9d514e434..e904944437 100644 --- a/tests/unit/commands/local/start_api/test_cli.py +++ b/tests/unit/commands/local/start_api/test_cli.py @@ -3,7 +3,7 @@ """ from unittest import TestCase -from mock import patch, Mock +from unittest.mock import patch, Mock from parameterized import parameterized diff --git a/tests/unit/commands/local/start_lambda/test_cli.py b/tests/unit/commands/local/start_lambda/test_cli.py index 91e46689ce..5dff100199 100644 --- a/tests/unit/commands/local/start_lambda/test_cli.py +++ b/tests/unit/commands/local/start_lambda/test_cli.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import patch, Mock +from unittest.mock import patch, Mock from parameterized import parameterized diff --git a/tests/unit/commands/logs/test_command.py b/tests/unit/commands/logs/test_command.py index a1938a141c..b895428f19 100644 --- a/tests/unit/commands/logs/test_command.py +++ b/tests/unit/commands/logs/test_command.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import Mock, patch, call +from unittest.mock import Mock, patch, call from samcli.commands.logs.command import do_cli diff --git a/tests/unit/commands/logs/test_logs_context.py b/tests/unit/commands/logs/test_logs_context.py index 630a1413dd..fe37d4e1c7 100644 --- a/tests/unit/commands/logs/test_logs_context.py +++ b/tests/unit/commands/logs/test_logs_context.py @@ -2,7 +2,7 @@ from botocore.stub import Stubber from unittest import TestCase -from mock import Mock, patch, ANY +from unittest.mock import Mock, patch, ANY from samcli.commands.logs.logs_context import LogsCommandContext from samcli.commands.exceptions import UserException diff --git a/tests/unit/commands/publish/test_command.py b/tests/unit/commands/publish/test_command.py index 743ac4e4fc..0225d9f42f 100644 --- a/tests/unit/commands/publish/test_command.py +++ b/tests/unit/commands/publish/test_command.py @@ -1,7 +1,7 @@ """Test sam publish CLI.""" import json from unittest import TestCase -from mock import patch, call, Mock +from unittest.mock import patch, call, Mock from serverlessrepo.exceptions import ServerlessRepoError, InvalidS3UriError from serverlessrepo.publish import CREATE_APPLICATION, UPDATE_APPLICATION diff --git a/tests/unit/commands/test_deploy.py b/tests/unit/commands/test_deploy.py index 119a7ddd2c..90387d5095 100644 --- a/tests/unit/commands/test_deploy.py +++ b/tests/unit/commands/test_deploy.py @@ -3,7 +3,7 @@ """ from unittest import TestCase -from mock import patch +from unittest.mock import patch from samcli.commands.deploy import do_cli as deploy_cli diff --git a/tests/unit/commands/test_package.py b/tests/unit/commands/test_package.py index a603b10a66..2e368f4d80 100644 --- a/tests/unit/commands/test_package.py +++ b/tests/unit/commands/test_package.py @@ -3,7 +3,7 @@ """ from unittest import TestCase -from mock import patch +from unittest.mock import patch from samcli.commands.package import do_cli as package_cli diff --git a/tests/unit/commands/validate/lib/test_sam_template_validator.py b/tests/unit/commands/validate/lib/test_sam_template_validator.py index 6a53ee2d87..5a1c0b156a 100644 --- a/tests/unit/commands/validate/lib/test_sam_template_validator.py +++ b/tests/unit/commands/validate/lib/test_sam_template_validator.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import Mock, patch +from unittest.mock import Mock, patch from samtranslator.public.exceptions import InvalidDocumentException diff --git a/tests/unit/commands/validate/test_cli.py b/tests/unit/commands/validate/test_cli.py index 156a614619..5f9cac7a9a 100644 --- a/tests/unit/commands/validate/test_cli.py +++ b/tests/unit/commands/validate/test_cli.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import Mock, patch +from unittest.mock import Mock, patch from botocore.exceptions import NoCredentialsError diff --git a/tests/unit/lib/build_module/test_app_builder.py b/tests/unit/lib/build_module/test_app_builder.py index 5bf9994833..fb8e2def92 100644 --- a/tests/unit/lib/build_module/test_app_builder.py +++ b/tests/unit/lib/build_module/test_app_builder.py @@ -3,7 +3,7 @@ import json from unittest import TestCase -from mock import Mock, call, patch +from unittest.mock import Mock, call, patch from pathlib import Path from samcli.lib.build.app_builder import ( diff --git a/tests/unit/lib/build_module/test_workflow_config.py b/tests/unit/lib/build_module/test_workflow_config.py index 14a29fee2f..eab6393b7a 100644 --- a/tests/unit/lib/build_module/test_workflow_config.py +++ b/tests/unit/lib/build_module/test_workflow_config.py @@ -1,6 +1,6 @@ from unittest import TestCase from parameterized import parameterized -from mock import patch +from unittest.mock import patch from samcli.lib.build.workflow_config import get_workflow_config, UnsupportedRuntimeException diff --git a/tests/unit/lib/intrinsic_resolver/test_intrinsics_symbol_table.py b/tests/unit/lib/intrinsic_resolver/test_intrinsics_symbol_table.py index 6d03cb16ed..49a7147b6e 100644 --- a/tests/unit/lib/intrinsic_resolver/test_intrinsics_symbol_table.py +++ b/tests/unit/lib/intrinsic_resolver/test_intrinsics_symbol_table.py @@ -1,6 +1,6 @@ from unittest import TestCase -from mock import patch +from unittest.mock import patch from samcli.lib.intrinsic_resolver.invalid_intrinsic_exception import InvalidSymbolException from samcli.lib.intrinsic_resolver.intrinsic_property_resolver import IntrinsicResolver diff --git a/tests/unit/lib/logs/test_fetcher.py b/tests/unit/lib/logs/test_fetcher.py index 96fb69d2b5..c0b634c008 100644 --- a/tests/unit/lib/logs/test_fetcher.py +++ b/tests/unit/lib/logs/test_fetcher.py @@ -3,7 +3,7 @@ import botocore.session from unittest import TestCase -from mock import Mock, patch, call, ANY +from unittest.mock import Mock, patch, call, ANY from botocore.stub import Stubber from samcli.lib.logs.fetcher import LogsFetcher diff --git a/tests/unit/lib/logs/test_formatter.py b/tests/unit/lib/logs/test_formatter.py index 5fe1828b59..79f5e85a35 100644 --- a/tests/unit/lib/logs/test_formatter.py +++ b/tests/unit/lib/logs/test_formatter.py @@ -1,7 +1,7 @@ import json from unittest import TestCase -from mock import Mock, patch, call +from unittest.mock import Mock, patch, call from nose_parameterized import parameterized from samcli.lib.logs.formatter import LogsFormatter, LambdaLogMsgFormatters, KeywordHighlighter, JSONMsgFormatter diff --git a/tests/unit/lib/samlib/test_cloudformation_command.py b/tests/unit/lib/samlib/test_cloudformation_command.py index d5ce254ebc..e846570c96 100644 --- a/tests/unit/lib/samlib/test_cloudformation_command.py +++ b/tests/unit/lib/samlib/test_cloudformation_command.py @@ -6,7 +6,7 @@ from subprocess import CalledProcessError, PIPE from unittest import TestCase -from mock import patch, call, ANY +from unittest.mock import patch, call, ANY from samcli.lib.samlib.cloudformation_command import execute_command, find_executable diff --git a/tests/unit/lib/telemetry/test_metrics.py b/tests/unit/lib/telemetry/test_metrics.py index 3ea872014c..1ca602512f 100644 --- a/tests/unit/lib/telemetry/test_metrics.py +++ b/tests/unit/lib/telemetry/test_metrics.py @@ -2,7 +2,7 @@ import time from unittest import TestCase -from mock import patch, Mock, ANY, call +from unittest.mock import patch, Mock, ANY, call from samcli.lib.telemetry.metrics import send_installed_metric, track_command from samcli.commands.exceptions import UserException diff --git a/tests/unit/lib/telemetry/test_telemetry.py b/tests/unit/lib/telemetry/test_telemetry.py index 9d57eafde0..e9ab045508 100644 --- a/tests/unit/lib/telemetry/test_telemetry.py +++ b/tests/unit/lib/telemetry/test_telemetry.py @@ -1,7 +1,7 @@ import platform import requests -from mock import patch, Mock, ANY +from unittest.mock import patch, Mock, ANY from unittest import TestCase from samcli.lib.telemetry.telemetry import Telemetry diff --git a/tests/unit/lib/utils/test_progressbar.py b/tests/unit/lib/utils/test_progressbar.py index d082d770d8..6305ea12da 100644 --- a/tests/unit/lib/utils/test_progressbar.py +++ b/tests/unit/lib/utils/test_progressbar.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import patch, Mock +from unittest.mock import patch, Mock from samcli.lib.utils.progressbar import progressbar diff --git a/tests/unit/lib/utils/test_sam_logging.py b/tests/unit/lib/utils/test_sam_logging.py index 44fb2a63b2..b2fb1654ce 100644 --- a/tests/unit/lib/utils/test_sam_logging.py +++ b/tests/unit/lib/utils/test_sam_logging.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import patch, Mock +from unittest.mock import patch, Mock from samcli.lib.utils.sam_logging import SamCliLogger diff --git a/tests/unit/lib/utils/test_stream_writer.py b/tests/unit/lib/utils/test_stream_writer.py index d882857488..cb48955850 100644 --- a/tests/unit/lib/utils/test_stream_writer.py +++ b/tests/unit/lib/utils/test_stream_writer.py @@ -6,7 +6,7 @@ from samcli.lib.utils.stream_writer import StreamWriter -from mock import Mock +from unittest.mock import Mock class TestStreamWriter(TestCase): diff --git a/tests/unit/lib/utils/test_tar.py b/tests/unit/lib/utils/test_tar.py index 2781362106..d5df37240b 100644 --- a/tests/unit/lib/utils/test_tar.py +++ b/tests/unit/lib/utils/test_tar.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import Mock, patch, call +from unittest.mock import Mock, patch, call from samcli.lib.utils.tar import create_tarball diff --git a/tests/unit/local/apigw/test_local_apigw_service.py b/tests/unit/local/apigw/test_local_apigw_service.py index dfb3003c78..bd05a66b4c 100644 --- a/tests/unit/local/apigw/test_local_apigw_service.py +++ b/tests/unit/local/apigw/test_local_apigw_service.py @@ -3,7 +3,7 @@ import json from unittest import TestCase -from mock import Mock, patch, ANY, MagicMock +from unittest.mock import Mock, patch, ANY, MagicMock from parameterized import parameterized, param from werkzeug.datastructures import Headers diff --git a/tests/unit/local/apigw/test_service_error_responses.py b/tests/unit/local/apigw/test_service_error_responses.py index 433ff30241..f42314e0aa 100644 --- a/tests/unit/local/apigw/test_service_error_responses.py +++ b/tests/unit/local/apigw/test_service_error_responses.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import patch, Mock +from unittest.mock import patch, Mock from samcli.local.apigw.service_error_responses import ServiceErrorResponses diff --git a/tests/unit/local/docker/test_container.py b/tests/unit/local/docker/test_container.py index ce07dc7abf..e38ff04486 100644 --- a/tests/unit/local/docker/test_container.py +++ b/tests/unit/local/docker/test_container.py @@ -3,7 +3,7 @@ """ from docker.errors import NotFound, APIError from unittest import TestCase -from mock import Mock, call, patch +from unittest.mock import Mock, call, patch from samcli.local.docker.container import Container diff --git a/tests/unit/local/docker/test_lambda_build_container.py b/tests/unit/local/docker/test_lambda_build_container.py index 5ae72d0087..8a3da6a30b 100644 --- a/tests/unit/local/docker/test_lambda_build_container.py +++ b/tests/unit/local/docker/test_lambda_build_container.py @@ -6,7 +6,7 @@ import pathlib from unittest import TestCase -from mock import patch +from unittest.mock import patch from parameterized import parameterized diff --git a/tests/unit/local/docker/test_lambda_container.py b/tests/unit/local/docker/test_lambda_container.py index cd7afdcd33..30db16c83a 100644 --- a/tests/unit/local/docker/test_lambda_container.py +++ b/tests/unit/local/docker/test_lambda_container.py @@ -3,7 +3,7 @@ """ from unittest import TestCase -from mock import patch, Mock +from unittest.mock import patch, Mock from parameterized import parameterized, param from samcli.commands.local.lib.debug_context import DebugContext diff --git a/tests/unit/local/docker/test_lambda_image.py b/tests/unit/local/docker/test_lambda_image.py index a9d3972c6d..7a194b10c6 100644 --- a/tests/unit/local/docker/test_lambda_image.py +++ b/tests/unit/local/docker/test_lambda_image.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import patch, Mock, mock_open +from unittest.mock import patch, Mock, mock_open from docker.errors import ImageNotFound, BuildError, APIError diff --git a/tests/unit/local/docker/test_manager.py b/tests/unit/local/docker/test_manager.py index 835631300f..444437e153 100644 --- a/tests/unit/local/docker/test_manager.py +++ b/tests/unit/local/docker/test_manager.py @@ -7,7 +7,7 @@ import requests -from mock import Mock +from unittest.mock import Mock from docker.errors import APIError, ImageNotFound from samcli.local.docker.manager import ContainerManager, DockerImagePullFailedException diff --git a/tests/unit/local/docker/test_utils.py b/tests/unit/local/docker/test_utils.py index 2e4af7ca02..09ab511e55 100644 --- a/tests/unit/local/docker/test_utils.py +++ b/tests/unit/local/docker/test_utils.py @@ -4,8 +4,7 @@ import os from unittest import TestCase - -from mock import patch +from unittest.mock import patch from samcli.local.docker.utils import to_posix_path diff --git a/tests/unit/local/events/test_api_event.py b/tests/unit/local/events/test_api_event.py index c2c425dab9..aa106f5ebd 100644 --- a/tests/unit/local/events/test_api_event.py +++ b/tests/unit/local/events/test_api_event.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import Mock +from unittest.mock import Mock from samcli.local.events.api_event import ContextIdentity, RequestContext, ApiGatewayLambdaEvent diff --git a/tests/unit/local/init/test_init.py b/tests/unit/local/init/test_init.py index b4d29c3979..a799640e94 100644 --- a/tests/unit/local/init/test_init.py +++ b/tests/unit/local/init/test_init.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import patch +from unittest.mock import patch from cookiecutter.exceptions import CookiecutterException from samcli.local.init import generate_project diff --git a/tests/unit/local/lambda_service/test_lambda_error_responses.py b/tests/unit/local/lambda_service/test_lambda_error_responses.py index 699e70371f..47190f0ea4 100644 --- a/tests/unit/local/lambda_service/test_lambda_error_responses.py +++ b/tests/unit/local/lambda_service/test_lambda_error_responses.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import patch +from unittest.mock import patch from samcli.local.lambda_service.lambda_error_responses import LambdaErrorResponses diff --git a/tests/unit/local/lambda_service/test_local_lambda_invoke_service.py b/tests/unit/local/lambda_service/test_local_lambda_invoke_service.py index ae92926c4c..14efa11e5c 100644 --- a/tests/unit/local/lambda_service/test_local_lambda_invoke_service.py +++ b/tests/unit/local/lambda_service/test_local_lambda_invoke_service.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import Mock, patch, ANY, call +from unittest.mock import Mock, patch, ANY, call from samcli.local.lambda_service.local_lambda_invoke_service import LocalLambdaInvokeService from samcli.local.lambdafn.exceptions import FunctionNotFound diff --git a/tests/unit/local/lambdafn/test_config.py b/tests/unit/local/lambdafn/test_config.py index d53e7d3ee3..07b240459b 100644 --- a/tests/unit/local/lambdafn/test_config.py +++ b/tests/unit/local/lambdafn/test_config.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import Mock +from unittest.mock import Mock from samcli.local.lambdafn.config import FunctionConfig diff --git a/tests/unit/local/lambdafn/test_runtime.py b/tests/unit/local/lambdafn/test_runtime.py index 688219cd61..74e585b42c 100644 --- a/tests/unit/local/lambdafn/test_runtime.py +++ b/tests/unit/local/lambdafn/test_runtime.py @@ -3,7 +3,7 @@ """ from unittest import TestCase -from mock import Mock, patch, MagicMock, ANY +from unittest.mock import Mock, patch, MagicMock, ANY from parameterized import parameterized from samcli.local.lambdafn.runtime import LambdaRuntime, _unzip_file diff --git a/tests/unit/local/lambdafn/test_zip.py b/tests/unit/local/lambdafn/test_zip.py index 5f36b6023f..ade9cd8da0 100644 --- a/tests/unit/local/lambdafn/test_zip.py +++ b/tests/unit/local/lambdafn/test_zip.py @@ -8,7 +8,7 @@ from unittest import TestCase from unittest import skipIf -from mock import Mock, patch +from unittest.mock import Mock, patch from nose_parameterized import parameterized, param from samcli.local.lambdafn.zip import unzip, unzip_from_uri, _override_permissions diff --git a/tests/unit/local/layers/test_download_layers.py b/tests/unit/local/layers/test_download_layers.py index 9315d4f5c3..3c49f34207 100644 --- a/tests/unit/local/layers/test_download_layers.py +++ b/tests/unit/local/layers/test_download_layers.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import patch, Mock, call +from unittest.mock import Mock, call, patch from botocore.exceptions import NoCredentialsError, ClientError from pathlib import Path diff --git a/tests/unit/local/services/test_base_local_service.py b/tests/unit/local/services/test_base_local_service.py index adb53989fc..8ba46c7aa2 100644 --- a/tests/unit/local/services/test_base_local_service.py +++ b/tests/unit/local/services/test_base_local_service.py @@ -1,5 +1,5 @@ from unittest import TestCase -from mock import Mock, patch +from unittest.mock import Mock, patch from parameterized import parameterized, param From 40d4b8b2253e834875d4c40df920cbbc9b51133a Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 15:27:13 -0700 Subject: [PATCH 14/42] Use std's assertCountEqual instead of six's --- .../local/lib/test_cfn_api_provider.py | 30 ++++++-------- .../local/lib/test_sam_api_provider.py | 41 +++++++++---------- 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/tests/unit/commands/local/lib/test_cfn_api_provider.py b/tests/unit/commands/local/lib/test_cfn_api_provider.py index d81822bb01..c0cda6959a 100644 --- a/tests/unit/commands/local/lib/test_cfn_api_provider.py +++ b/tests/unit/commands/local/lib/test_cfn_api_provider.py @@ -4,7 +4,6 @@ from unittest import TestCase from unittest.mock import patch -from six import assertCountEqual from samcli.commands.local.lib.api_provider import ApiProvider from samcli.commands.local.lib.cfn_api_provider import CfnApiProvider @@ -36,7 +35,7 @@ def test_with_inline_swagger_apis(self): } provider = ApiProvider(template) - assertCountEqual(self, self.input_routes, provider.routes) + self.assertCountEqual(self.input_routes, provider.routes) def test_with_swagger_as_local_file(self): with tempfile.NamedTemporaryFile(mode="w", delete=False) as fp: @@ -52,7 +51,7 @@ def test_with_swagger_as_local_file(self): } provider = ApiProvider(template) - assertCountEqual(self, self.input_routes, provider.routes) + self.assertCountEqual(self.input_routes, provider.routes) def test_body_with_swagger_as_local_file_expect_fail(self): with tempfile.NamedTemporaryFile(mode="w", delete=False) as fp: @@ -81,7 +80,7 @@ def test_with_swagger_as_both_body_and_uri_called(self, SwaggerReaderMock): cwd = "foo" provider = ApiProvider(template, cwd=cwd) - assertCountEqual(self, self.input_routes, provider.routes) + self.assertCountEqual(self.input_routes, provider.routes) SwaggerReaderMock.assert_called_with(definition_body=body, definition_uri=filename, working_dir=cwd) def test_swagger_with_any_method(self): @@ -100,7 +99,7 @@ def test_swagger_with_any_method(self): } provider = ApiProvider(template) - assertCountEqual(self, expected_routes, provider.routes) + self.assertCountEqual(expected_routes, provider.routes) def test_with_binary_media_types(self): template = { @@ -120,8 +119,8 @@ def test_with_binary_media_types(self): ] provider = ApiProvider(template) - assertCountEqual(self, expected_apis, provider.routes) - assertCountEqual(self, provider.api.binary_media_types, expected_binary_types) + self.assertCountEqual(expected_apis, provider.routes) + self.assertCountEqual(provider.api.binary_media_types, expected_binary_types) def test_with_binary_media_types_in_swagger_and_on_resource(self): input_routes = [Route(path="/path", methods=["OPTIONS"], function_name="SamFunc1")] @@ -143,8 +142,8 @@ def test_with_binary_media_types_in_swagger_and_on_resource(self): expected_routes = [Route(path="/path", methods=["OPTIONS"], function_name="SamFunc1")] provider = ApiProvider(template) - assertCountEqual(self, expected_routes, provider.routes) - assertCountEqual(self, provider.api.binary_media_types, expected_binary_types) + self.assertCountEqual(expected_routes, provider.routes) + self.assertCountEqual(provider.api.binary_media_types, expected_binary_types) class TestCloudFormationStageValues(TestCase): @@ -377,8 +376,7 @@ def test_resolve_correct_multi_parent_resource_path(self): } provider = ApiProvider(template) - assertCountEqual( - self, + self.assertCountEqual( provider.routes, [ Route(path="/root/v1/beta", methods=["POST"], function_name=None), @@ -401,8 +399,7 @@ def test_resource_with_method_correct_routes(self): } } provider = ApiProvider(template) - assertCountEqual( - self, + self.assertCountEqual( provider.routes, [ Route( @@ -475,8 +472,7 @@ def test_method_integration_uri(self): } provider = ApiProvider(template) - assertCountEqual( - self, + self.assertCountEqual( provider.routes, [ Route(path="/root/v1/beta", methods=["POST"], function_name="AWSLambdaFunction"), @@ -550,7 +546,7 @@ def test_binary_media_types_method(self): } provider = ApiProvider(template) - assertCountEqual(self, provider.api.binary_media_types, ["image/png", "image/jpg"]) + self.assertCountEqual(provider.api.binary_media_types, ["image/png", "image/jpg"]) def test_cdk(self): template = { @@ -668,4 +664,4 @@ def test_cdk(self): provider = ApiProvider(template) proxy_paths = [Route(path="/{proxy+}", methods=Route.ANY_HTTP_METHODS, function_name="HelloHandler2E4FBA4D")] root_paths = [Route(path="/", methods=Route.ANY_HTTP_METHODS, function_name="HelloHandler2E4FBA4D")] - assertCountEqual(self, provider.routes, proxy_paths + root_paths) + self.assertCountEqual(provider.routes, proxy_paths + root_paths) diff --git a/tests/unit/commands/local/lib/test_sam_api_provider.py b/tests/unit/commands/local/lib/test_sam_api_provider.py index 4dc1655dfe..612724d637 100644 --- a/tests/unit/commands/local/lib/test_sam_api_provider.py +++ b/tests/unit/commands/local/lib/test_sam_api_provider.py @@ -5,7 +5,6 @@ from unittest.mock import patch from nose_parameterized import parameterized -from six import assertCountEqual from samcli.commands.validate.lib.exceptions import InvalidSamDocumentException from samcli.commands.local.lib.api_provider import ApiProvider @@ -224,7 +223,7 @@ def test_provider_must_support_binary_media_types(self): self.assertEqual(len(provider.routes), 1) self.assertEqual(list(provider.routes)[0], Route(path="/path", methods=["GET"], function_name="SamFunc1")) - assertCountEqual(self, provider.api.binary_media_types, ["image/gif", "image/png"]) + self.assertCountEqual(provider.api.binary_media_types, ["image/gif", "image/png"]) self.assertEqual(provider.api.stage_name, "Prod") def test_provider_must_support_binary_media_types_with_any_method(self): @@ -255,8 +254,8 @@ def test_provider_must_support_binary_media_types_with_any_method(self): provider = ApiProvider(template) - assertCountEqual(self, provider.routes, expected_routes) - assertCountEqual(self, provider.api.binary_media_types, binary) + self.assertCountEqual(provider.routes, expected_routes) + self.assertCountEqual(provider.api.binary_media_types, binary) class TestSamApiProviderWithExplicitApis(TestCase): @@ -287,7 +286,7 @@ def test_with_inline_swagger_routes(self): } provider = ApiProvider(template) - assertCountEqual(self, self.input_routes, provider.routes) + self.assertCountEqual(self.input_routes, provider.routes) def test_with_swagger_as_local_file(self): with tempfile.NamedTemporaryFile(mode="w", delete=False) as fp: @@ -307,7 +306,7 @@ def test_with_swagger_as_local_file(self): } provider = ApiProvider(template) - assertCountEqual(self, self.input_routes, provider.routes) + self.assertCountEqual(self.input_routes, provider.routes) @patch("samcli.commands.local.lib.cfn_base_api_provider.SwaggerReader") def test_with_swagger_as_both_body_and_uri_called(self, SwaggerReaderMock): @@ -327,7 +326,7 @@ def test_with_swagger_as_both_body_and_uri_called(self, SwaggerReaderMock): cwd = "foo" provider = ApiProvider(template, cwd=cwd) - assertCountEqual(self, self.input_routes, provider.routes) + self.assertCountEqual(self.input_routes, provider.routes) SwaggerReaderMock.assert_called_with(definition_body=body, definition_uri=filename, working_dir=cwd) def test_swagger_with_any_method(self): @@ -351,7 +350,7 @@ def test_swagger_with_any_method(self): } provider = ApiProvider(template) - assertCountEqual(self, expected_routes, provider.routes) + self.assertCountEqual(expected_routes, provider.routes) def test_with_binary_media_types(self): template = { @@ -374,8 +373,8 @@ def test_with_binary_media_types(self): ] provider = ApiProvider(template) - assertCountEqual(self, expected_routes, provider.routes) - assertCountEqual(self, provider.api.binary_media_types, expected_binary_types) + self.assertCountEqual(expected_routes, provider.routes) + self.assertCountEqual(provider.api.binary_media_types, expected_binary_types) def test_with_binary_media_types_in_swagger_and_on_resource(self): input_routes = [Route(path="/path", methods=["OPTIONS"], function_name="SamFunc1")] @@ -398,8 +397,8 @@ def test_with_binary_media_types_in_swagger_and_on_resource(self): expected_routes = [Route(path="/path", methods=["OPTIONS"], function_name="SamFunc1")] provider = ApiProvider(template) - assertCountEqual(self, expected_routes, provider.routes) - assertCountEqual(self, provider.api.binary_media_types, expected_binary_types) + self.assertCountEqual(expected_routes, provider.routes) + self.assertCountEqual(provider.api.binary_media_types, expected_binary_types) class TestSamApiProviderWithExplicitAndImplicitApis(TestCase): @@ -445,7 +444,7 @@ def test_must_union_implicit_and_explicit(self): ] provider = ApiProvider(self.template) - assertCountEqual(self, expected_routes, provider.routes) + self.assertCountEqual(expected_routes, provider.routes) def test_must_prefer_implicit_api_over_explicit(self): implicit_routes = { @@ -473,7 +472,7 @@ def test_must_prefer_implicit_api_over_explicit(self): ] provider = ApiProvider(self.template) - assertCountEqual(self, expected_routes, provider.routes) + self.assertCountEqual(expected_routes, provider.routes) def test_must_prefer_implicit_with_any_method(self): implicit_routes = { @@ -505,7 +504,7 @@ def test_must_prefer_implicit_with_any_method(self): ] provider = ApiProvider(self.template) - assertCountEqual(self, expected_routes, provider.routes) + self.assertCountEqual(expected_routes, provider.routes) def test_with_any_method_on_both(self): implicit_routes = { @@ -547,7 +546,7 @@ def test_with_any_method_on_both(self): ] provider = ApiProvider(self.template) - assertCountEqual(self, expected_routes, provider.routes) + self.assertCountEqual(expected_routes, provider.routes) def test_must_add_explicit_api_when_ref_with_rest_api_id(self): events = { @@ -583,7 +582,7 @@ def test_must_add_explicit_api_when_ref_with_rest_api_id(self): ] provider = ApiProvider(self.template) - assertCountEqual(self, expected_routes, provider.routes) + self.assertCountEqual(expected_routes, provider.routes) def test_both_routes_must_get_binary_media_types(self): events = { @@ -613,8 +612,8 @@ def test_both_routes_must_get_binary_media_types(self): ] provider = ApiProvider(self.template) - assertCountEqual(self, expected_routes, provider.routes) - assertCountEqual(self, provider.api.binary_media_types, expected_explicit_binary_types) + self.assertCountEqual(expected_routes, provider.routes) + self.assertCountEqual(provider.api.binary_media_types, expected_explicit_binary_types) def test_binary_media_types_with_rest_api_id_reference(self): events = { @@ -650,8 +649,8 @@ def test_binary_media_types_with_rest_api_id_reference(self): ] provider = ApiProvider(self.template) - assertCountEqual(self, expected_routes, provider.routes) - assertCountEqual(self, provider.api.binary_media_types, expected_explicit_binary_types) + self.assertCountEqual(expected_routes, provider.routes) + self.assertCountEqual(provider.api.binary_media_types, expected_explicit_binary_types) class TestSamStageValues(TestCase): From 7078124857566d5106ab3c7649b63b3915bc066c Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 19:52:53 -0700 Subject: [PATCH 15/42] removed six and six usage --- pytest.ini | 4 ++-- requirements/base.txt | 1 - samcli/commands/_utils/template.py | 3 +-- samcli/commands/local/lib/provider.py | 4 +--- samcli/commands/local/lib/sam_function_provider.py | 5 ++--- samcli/commands/validate/lib/sam_template_validator.py | 3 +-- samcli/yamlhelper.py | 4 +--- 7 files changed, 8 insertions(+), 16 deletions(-) diff --git a/pytest.ini b/pytest.ini index 926a10d096..d42cc7e27f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,5 @@ [pytest] env = AWS_DEFAULT_REGION = ap-southeast-1 -filterwarnings = - error +#filterwarnings = +# error diff --git a/requirements/base.txt b/requirements/base.txt index 026dd43d0e..0c4dac42ca 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,4 +1,3 @@ -six~=1.11.0 chevron~=0.12 click~=7.0 Flask~=1.0.2 diff --git a/samcli/commands/_utils/template.py b/samcli/commands/_utils/template.py index 5232732e6a..370fac617d 100644 --- a/samcli/commands/_utils/template.py +++ b/samcli/commands/_utils/template.py @@ -4,7 +4,6 @@ import os import pathlib -import six import yaml from samcli.yamlhelper import yaml_parse, yaml_dump @@ -214,7 +213,7 @@ def _resolve_relative_to(path, original_root, new_root): Updated path if the given path is a relative path. None, if the path is not a relative path. """ - if not isinstance(path, six.string_types) or path.startswith("s3://") or os.path.isabs(path): + if not isinstance(path, str) or path.startswith("s3://") or os.path.isabs(path): # Value is definitely NOT a relative path. It is either a S3 URi or Absolute path or not a string at all return None diff --git a/samcli/commands/local/lib/provider.py b/samcli/commands/local/lib/provider.py index 12aa1be5b4..b2b2eab1b3 100644 --- a/samcli/commands/local/lib/provider.py +++ b/samcli/commands/local/lib/provider.py @@ -5,8 +5,6 @@ import hashlib from collections import namedtuple -import six - from samcli.commands.local.cli_common.user_exceptions import InvalidLayerVersionArn, UnsupportedIntrinsic # Named Tuple to representing the properties of a Lambda Function @@ -54,7 +52,7 @@ def __init__(self, arn, codeuri): codeuri str CodeURI of the layer. This should contain the path to the layer code """ - if not isinstance(arn, six.string_types): + if not isinstance(arn, str): raise UnsupportedIntrinsic("{} is an Unsupported Intrinsic".format(arn)) self._arn = arn diff --git a/samcli/commands/local/lib/sam_function_provider.py b/samcli/commands/local/lib/sam_function_provider.py index 4a0ef70f77..1e8365b2fa 100644 --- a/samcli/commands/local/lib/sam_function_provider.py +++ b/samcli/commands/local/lib/sam_function_provider.py @@ -3,7 +3,6 @@ """ import logging -import six from samcli.commands.local.cli_common.user_exceptions import InvalidLayerVersionArn from .exceptions import InvalidLayerReference @@ -156,7 +155,7 @@ def _extract_sam_function_codeuri(name, resource_properties, code_property_key): """ codeuri = resource_properties.get(code_property_key, SamFunctionProvider._DEFAULT_CODEURI) # CodeUri can be a dictionary of S3 Bucket/Key or a S3 URI, neither of which are supported - if isinstance(codeuri, dict) or (isinstance(codeuri, six.string_types) and codeuri.startswith("s3://")): + if isinstance(codeuri, dict) or (isinstance(codeuri, str) and codeuri.startswith("s3://")): codeuri = SamFunctionProvider._DEFAULT_CODEURI LOG.warning( "Lambda function '%s' has specified S3 location for CodeUri which is unsupported. " @@ -253,7 +252,7 @@ def _parse_layer_info(list_of_layers, resources): ) # noqa: E501 # If the layer is a string, assume it is the arn - if isinstance(layer, six.string_types): + if isinstance(layer, str): layers.append(LayerVersion(layer, None)) continue diff --git a/samcli/commands/validate/lib/sam_template_validator.py b/samcli/commands/validate/lib/sam_template_validator.py index 46cbae6cd7..c869b53bf5 100644 --- a/samcli/commands/validate/lib/sam_template_validator.py +++ b/samcli/commands/validate/lib/sam_template_validator.py @@ -4,7 +4,6 @@ import logging import functools -import six from samtranslator.public.exceptions import InvalidDocumentException from samtranslator.parser import parser from samtranslator.translator.translator import Translator @@ -114,7 +113,7 @@ def is_s3_uri(uri): Returns True if the uri given is an S3 uri, otherwise False """ - return isinstance(uri, six.string_types) and uri.startswith("s3://") + return isinstance(uri, str) and uri.startswith("s3://") @staticmethod def _update_to_s3_uri(property_key, resource_property_dict, s3_uri_value="s3://bucket/value"): diff --git a/samcli/yamlhelper.py b/samcli/yamlhelper.py index 658bb8183c..690e5a55b5 100644 --- a/samcli/yamlhelper.py +++ b/samcli/yamlhelper.py @@ -23,8 +23,6 @@ import yaml from yaml.resolver import ScalarNode, SequenceNode -import six - def intrinsics_multi_constructor(loader, tag_prefix, node): """ @@ -42,7 +40,7 @@ def intrinsics_multi_constructor(loader, tag_prefix, node): cfntag = prefix + tag - if tag == "GetAtt" and isinstance(node.value, six.string_types): + if tag == "GetAtt" and isinstance(node.value, str): # ShortHand notation for !GetAtt accepts Resource.Attribute format # while the standard notation is to use an array # [Resource, Attribute]. Convert shorthand to standard format From 38fcfd84a84a8659ba0b559d98afccd19ec5e91d Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 19:59:41 -0700 Subject: [PATCH 16/42] remove backport import statement for std library tempfile --- tests/integration/init/test_init_command.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/integration/init/test_init_command.py b/tests/integration/init/test_init_command.py index 79acb2527c..138c22e862 100644 --- a/tests/integration/init/test_init_command.py +++ b/tests/integration/init/test_init_command.py @@ -1,8 +1,7 @@ from unittest import TestCase from subprocess import Popen import os - -from backports import tempfile +import tempfile class TestBasicInitCommand(TestCase): From 7cce9a9ca18fa60264cc75fb8c529e740f091ef1 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 20:06:59 -0700 Subject: [PATCH 17/42] Remove pylint overriding due to Py2 to Py3 differences --- .../local/cli_common/invoke_context.py | 3 +-- samcli/lib/utils/osutils.py | 22 ++----------------- samcli/local/layers/layer_downloader.py | 3 +-- 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/samcli/commands/local/cli_common/invoke_context.py b/samcli/commands/local/cli_common/invoke_context.py index b9f41465cf..6fdbb0584e 100644 --- a/samcli/commands/local/cli_common/invoke_context.py +++ b/samcli/commands/local/cli_common/invoke_context.py @@ -346,8 +346,7 @@ def _get_debug_context(debug_port, debug_args, debugger_path): raise error - # We turn off pylint here due to https://github.com/PyCQA/pylint/issues/1660 - if not debugger.is_dir(): # pylint: disable=no-member + if not debugger.is_dir(): raise DebugContextException("'{}' should be a directory with the debugger in it.".format(debugger_path)) debugger_path = str(debugger) diff --git a/samcli/lib/utils/osutils.py b/samcli/lib/utils/osutils.py index d59e7ae43e..e22f3edbbb 100644 --- a/samcli/lib/utils/osutils.py +++ b/samcli/lib/utils/osutils.py @@ -49,16 +49,7 @@ def stdout(): io.BytesIO Byte stream of Stdout """ - - # We write all of the data to stdout with bytes, typically io.BytesIO. stdout in Python2 - # accepts bytes but Python3 does not. This is due to a type change on the attribute. To keep - # this consistent, we leave Python2 the same and get the .buffer attribute on stdout in Python3 - byte_stdout = sys.stdout - - if sys.version_info.major > 2: - byte_stdout = sys.stdout.buffer # pylint: disable=no-member - - return byte_stdout + return sys.stdout.buffer def stderr(): @@ -70,13 +61,4 @@ def stderr(): io.BytesIO Byte stream of stderr """ - - # We write all of the data to stderr with bytes, typically io.BytesIO. stderr in Python2 - # accepts bytes but Python3 does not. This is due to a type change on the attribute. To keep - # this consistent, we leave Python2 the same and get the .buffer attribute on stderr in Python3 - byte_stderr = sys.stderr - - if sys.version_info.major > 2: - byte_stderr = sys.stderr.buffer # pylint: disable=no-member - - return byte_stderr + return sys.stderr.buffer diff --git a/samcli/local/layers/layer_downloader.py b/samcli/local/layers/layer_downloader.py index 83b22d3505..6e6703e8e1 100644 --- a/samcli/local/layers/layer_downloader.py +++ b/samcli/local/layers/layer_downloader.py @@ -94,8 +94,7 @@ def download(self, layer, force=False): layer.codeuri = resolve_code_path(self.cwd, layer.codeuri) return layer - # disabling no-member due to https://github.com/PyCQA/pylint/issues/1660 - layer_path = Path(self.layer_cache).resolve().joinpath(layer.name) # pylint: disable=no-member + layer_path = Path(self.layer_cache).resolve().joinpath(layer.name) is_layer_downloaded = self._is_layer_cached(layer_path) layer.codeuri = str(layer_path) From 7a75e8410379d56cd479c01c02a95010c6a44f1a Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 20:25:23 -0700 Subject: [PATCH 18/42] Force python3 on windows in appveyor --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 29b928b054..68c02643f0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,7 +30,7 @@ for: - "echo %PATH%" - "python --version" # Upgrade setuptools, wheel and virtualenv - - "python -m pip install --upgrade setuptools wheel virtualenv" + - "python3 -m pip install --upgrade setuptools wheel virtualenv" # Create new virtual environment and activate it - "rm -rf venv" From 73196f2aa5062457b4058850edbce926367fbc37 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 20:26:20 -0700 Subject: [PATCH 19/42] format using black --- samcli/commands/local/cli_common/user_exceptions.py | 1 - samcli/local/common/runtime_template.py | 8 ++++---- tests/unit/cli/test_main.py | 8 ++------ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/samcli/commands/local/cli_common/user_exceptions.py b/samcli/commands/local/cli_common/user_exceptions.py index 0db8d94823..78d06fee00 100644 --- a/samcli/commands/local/cli_common/user_exceptions.py +++ b/samcli/commands/local/cli_common/user_exceptions.py @@ -23,7 +23,6 @@ class SamTemplateNotFoundException(UserException): """ - class DebugContextException(UserException): """ Something went wrong when creating the DebugContext diff --git a/samcli/local/common/runtime_template.py b/samcli/local/common/runtime_template.py index a9e28025f2..3893b665e5 100644 --- a/samcli/local/common/runtime_template.py +++ b/samcli/local/common/runtime_template.py @@ -75,10 +75,10 @@ } SUPPORTED_DEP_MANAGERS = { - c["dependency_manager"] - for c in list(itertools.chain(*(RUNTIME_DEP_TEMPLATE_MAPPING.values()))) - if c["dependency_manager"] - } + c["dependency_manager"] + for c in list(itertools.chain(*(RUNTIME_DEP_TEMPLATE_MAPPING.values()))) + if c["dependency_manager"] +} RUNTIMES = set( itertools.chain(*[c["runtimes"] for c in list(itertools.chain(*(RUNTIME_DEP_TEMPLATE_MAPPING.values())))]) diff --git a/tests/unit/cli/test_main.py b/tests/unit/cli/test_main.py index 3a94bc000e..e24cc900ea 100644 --- a/tests/unit/cli/test_main.py +++ b/tests/unit/cli/test_main.py @@ -37,9 +37,7 @@ def test_cli_with_debug(self): @patch("samcli.cli.main.send_installed_metric") def test_cli_enable_telemetry_with_prompt(self, send_installed_metric_mock): - with patch( - "samcli.cli.global_config.GlobalConfig.telemetry_enabled", new_callable=PropertyMock - ) as mock_flag: + with patch("samcli.cli.global_config.GlobalConfig.telemetry_enabled", new_callable=PropertyMock) as mock_flag: mock_flag.return_value = None runner = CliRunner() runner.invoke(cli, ["local", "generate-event", "s3"]) @@ -50,9 +48,7 @@ def test_cli_enable_telemetry_with_prompt(self, send_installed_metric_mock): @patch("samcli.cli.main.send_installed_metric") def test_prompt_skipped_when_value_set(self, send_installed_metric_mock): - with patch( - "samcli.cli.global_config.GlobalConfig.telemetry_enabled", new_callable=PropertyMock - ) as mock_flag: + with patch("samcli.cli.global_config.GlobalConfig.telemetry_enabled", new_callable=PropertyMock) as mock_flag: mock_flag.return_value = True runner = CliRunner() runner.invoke(cli, ["local", "generate-event", "s3"]) From 6464407371ee8725dcfb1fcf5f553680a371afb3 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 20:52:49 -0700 Subject: [PATCH 20/42] attempt to to make windows appveyor use py3 instead of py2 --- appveyor.yml | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 68c02643f0..ed00a306ba 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,6 +18,8 @@ environment: PYTHON_ARCH: '64' RUN_SMOKE: 1 +stack: python %PYTHON% + for: - matrix: @@ -30,12 +32,17 @@ for: - "echo %PATH%" - "python --version" # Upgrade setuptools, wheel and virtualenv - - "python3 -m pip install --upgrade setuptools wheel virtualenv" + - "python -m pip install --upgrade setuptools wheel virtualenv" # Create new virtual environment and activate it - "rm -rf venv" - "python -m virtualenv venv" +<<<<<<< HEAD - "venv\\Scripts\\activate" +======= + - "venv/Scripts/activate" + - "python --version" +>>>>>>> attempt to to make windows appveyor use py3 instead of py2 build_script: # Activate virtualenv again on windows @@ -105,5 +112,28 @@ for: test_script: # Smoke tests run in parallel +<<<<<<< HEAD - sh: "venv/Scripts/activate" - sh: "pytest -n 4 -vv tests/smoke" +======= + - "pytest -n 4 -vv tests/smoke" + +build_script: + - "python -c \"import sys; print(sys.executable)\"" + + # Actually install SAM CLI's dependencies + - "pip install -e \".[dev]\"" + +test_script: + - "pytest --cov samcli --cov-report term-missing --cov-fail-under 95 tests/unit" + - "pylint --rcfile .pylintrc samcli" + + # Runs only in Linux + - sh: "pytest -vv tests/integration" + - sh: "/tmp/black --check setup.py tests samcli scripts" + - sh: "python scripts/check-isolated-needs-update.py" + + # Smoke tests run in parallel - it runs on both Linux & Windows + # Presence of the RUN_SMOKE envvar will run the smoke tests + - ps: "If ($env:RUN_SMOKE) {pytest -n 4 -vv tests/smoke}" +>>>>>>> attempt to to make windows appveyor use py3 instead of py2 From a7a9142a25b47ef1c7c40e1cbf82c2720909664b Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 20:56:45 -0700 Subject: [PATCH 21/42] try PYTHON_VERSION instead of PYTHON --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index ed00a306ba..35cfc30755 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,7 +18,7 @@ environment: PYTHON_ARCH: '64' RUN_SMOKE: 1 -stack: python %PYTHON% +stack: python %PYTHON_VERSION% for: - From 5f56464113e9fd1b08a34ac6906d4aea2ded5be5 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 17 Sep 2019 21:03:32 -0700 Subject: [PATCH 22/42] Add python from matrix to path on windows --- appveyor.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 35cfc30755..5edf0cbebe 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -18,8 +18,6 @@ environment: PYTHON_ARCH: '64' RUN_SMOKE: 1 -stack: python %PYTHON_VERSION% - for: - matrix: @@ -32,6 +30,7 @@ for: - "echo %PATH%" - "python --version" # Upgrade setuptools, wheel and virtualenv + - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" - "python -m pip install --upgrade setuptools wheel virtualenv" # Create new virtual environment and activate it From af1bdff8553070927e81d9523bdc57a7bbc08f21 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Wed, 18 Sep 2019 15:27:56 -0700 Subject: [PATCH 23/42] try non-quoted version --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 5edf0cbebe..ad1a78f51c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,7 +30,7 @@ for: - "echo %PATH%" - "python --version" # Upgrade setuptools, wheel and virtualenv - - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" + - SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH% - "python -m pip install --upgrade setuptools wheel virtualenv" # Create new virtual environment and activate it From 64ba49100b4e02a0313e3661923c3412efb49f5f Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Thu, 19 Sep 2019 18:17:28 -0700 Subject: [PATCH 24/42] try refreshenv --- appveyor.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index ad1a78f51c..6ca634507c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,7 +30,9 @@ for: - "echo %PATH%" - "python --version" # Upgrade setuptools, wheel and virtualenv - - SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH% + - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" + - "refreshenv" + - "echo %PATH%" - "python -m pip install --upgrade setuptools wheel virtualenv" # Create new virtual environment and activate it From 2ef451c43e209670d029d8ff7b6316ce4f1ca9a8 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Thu, 19 Sep 2019 19:06:21 -0700 Subject: [PATCH 25/42] Use PYTHON_HOME instead of PYTHON env var --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 6ca634507c..6cfa6093e6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,7 +30,7 @@ for: - "echo %PATH%" - "python --version" # Upgrade setuptools, wheel and virtualenv - - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" + - "SET PATH=%PYTHON_HOME%;%PYTHON_HOME%\\Scripts;%PATH%" - "refreshenv" - "echo %PATH%" - "python -m pip install --upgrade setuptools wheel virtualenv" From 33998466cd9a66ea11ee7d352475f4d0376276ff Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Thu, 19 Sep 2019 20:08:11 -0700 Subject: [PATCH 26/42] try only PYTHON_HOME --- appveyor.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 6cfa6093e6..c47f0b34d0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -30,7 +30,9 @@ for: - "echo %PATH%" - "python --version" # Upgrade setuptools, wheel and virtualenv - - "SET PATH=%PYTHON_HOME%;%PYTHON_HOME%\\Scripts;%PATH%" + - "SET PATH=%PYTHON_HOME%;%PATH%" + - "echo %PYTHON_HOME%" + - "echo %PATH%" - "refreshenv" - "echo %PATH%" - "python -m pip install --upgrade setuptools wheel virtualenv" From 90e820c7d0fad380f75956ee69e9bc410a47b8d8 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Thu, 19 Sep 2019 20:58:03 -0700 Subject: [PATCH 27/42] remove refreshenv --- appveyor.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index c47f0b34d0..8706545888 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -33,8 +33,6 @@ for: - "SET PATH=%PYTHON_HOME%;%PATH%" - "echo %PYTHON_HOME%" - "echo %PATH%" - - "refreshenv" - - "echo %PATH%" - "python -m pip install --upgrade setuptools wheel virtualenv" # Create new virtual environment and activate it From 0fe6eb78a186df29de8d074ba5f124edb100a160 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Thu, 19 Sep 2019 21:53:28 -0700 Subject: [PATCH 28/42] try to fix unicode error in py37 on windows --- samcli/commands/_utils/template.py | 2 +- samcli/commands/validate/validate.py | 2 +- tests/unit/commands/_utils/test_template.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samcli/commands/_utils/template.py b/samcli/commands/_utils/template.py index 370fac617d..47051886d5 100644 --- a/samcli/commands/_utils/template.py +++ b/samcli/commands/_utils/template.py @@ -44,7 +44,7 @@ def get_template_data(template_file): if not pathlib.Path(template_file).exists(): raise ValueError("Template file not found at {}".format(template_file)) - with open(template_file, "r") as fp: + with open(template_file, "rb") as fp: try: return yaml_parse(fp.read()) except (ValueError, yaml.YAMLError) as ex: diff --git a/samcli/commands/validate/validate.py b/samcli/commands/validate/validate.py index cdc9d7db71..be22b9f403 100644 --- a/samcli/commands/validate/validate.py +++ b/samcli/commands/validate/validate.py @@ -68,7 +68,7 @@ def _read_sam_file(template): click.secho("SAM Template Not Found", bg="red") raise SamTemplateNotFoundException("Template at {} is not found".format(template)) - with click.open_file(template, "r") as sam_template: + with click.open_file(template, "rb") as sam_template: sam_template = yaml_parse(sam_template.read()) return sam_template diff --git a/tests/unit/commands/_utils/test_template.py b/tests/unit/commands/_utils/test_template.py index 04cd9b0b5c..c5d048f7af 100644 --- a/tests/unit/commands/_utils/test_template.py +++ b/tests/unit/commands/_utils/test_template.py @@ -42,7 +42,7 @@ def test_must_read_file_and_parse(self, pathlib_mock, yaml_parse_mock): self.assertEqual(result, parse_result) - m.assert_called_with(filename, "r") + m.assert_called_with(filename, "rb") yaml_parse_mock.assert_called_with(file_data) @parameterized.expand([param(ValueError()), param(yaml.YAMLError())]) From 20047f747aaf3b6b5b86df0fd1200bd27282d9b9 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Mon, 23 Sep 2019 09:43:44 -0700 Subject: [PATCH 29/42] Revert "try to fix unicode error in py37 on windows" This reverts commit 6e40c34af8e814d260eb3747ab11fecddad31032. --- samcli/commands/_utils/template.py | 2 +- samcli/commands/validate/validate.py | 2 +- tests/unit/commands/_utils/test_template.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samcli/commands/_utils/template.py b/samcli/commands/_utils/template.py index 47051886d5..370fac617d 100644 --- a/samcli/commands/_utils/template.py +++ b/samcli/commands/_utils/template.py @@ -44,7 +44,7 @@ def get_template_data(template_file): if not pathlib.Path(template_file).exists(): raise ValueError("Template file not found at {}".format(template_file)) - with open(template_file, "rb") as fp: + with open(template_file, "r") as fp: try: return yaml_parse(fp.read()) except (ValueError, yaml.YAMLError) as ex: diff --git a/samcli/commands/validate/validate.py b/samcli/commands/validate/validate.py index be22b9f403..cdc9d7db71 100644 --- a/samcli/commands/validate/validate.py +++ b/samcli/commands/validate/validate.py @@ -68,7 +68,7 @@ def _read_sam_file(template): click.secho("SAM Template Not Found", bg="red") raise SamTemplateNotFoundException("Template at {} is not found".format(template)) - with click.open_file(template, "rb") as sam_template: + with click.open_file(template, "r") as sam_template: sam_template = yaml_parse(sam_template.read()) return sam_template diff --git a/tests/unit/commands/_utils/test_template.py b/tests/unit/commands/_utils/test_template.py index c5d048f7af..04cd9b0b5c 100644 --- a/tests/unit/commands/_utils/test_template.py +++ b/tests/unit/commands/_utils/test_template.py @@ -42,7 +42,7 @@ def test_must_read_file_and_parse(self, pathlib_mock, yaml_parse_mock): self.assertEqual(result, parse_result) - m.assert_called_with(filename, "rb") + m.assert_called_with(filename, "r") yaml_parse_mock.assert_called_with(file_data) @parameterized.expand([param(ValueError()), param(yaml.YAMLError())]) From 8d8765c01a0ee967c124670388b4201033ba7df5 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Mon, 23 Sep 2019 09:46:21 -0700 Subject: [PATCH 30/42] Try forcing encoding --- .../templates/sar/AmazonConnectSalesforceLambda-template.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/smoke/templates/sar/AmazonConnectSalesforceLambda-template.yaml b/tests/smoke/templates/sar/AmazonConnectSalesforceLambda-template.yaml index 2225caa54d..0ccb2b6140 100644 --- a/tests/smoke/templates/sar/AmazonConnectSalesforceLambda-template.yaml +++ b/tests/smoke/templates/sar/AmazonConnectSalesforceLambda-template.yaml @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: Amazon Connect SalesForce Lambda integration From bfcbd5d9ae2e37b2ac2bec3b437a0e7e816613ce Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Mon, 23 Sep 2019 11:17:38 -0700 Subject: [PATCH 31/42] force encoding on file open --- samcli/commands/validate/validate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samcli/commands/validate/validate.py b/samcli/commands/validate/validate.py index cdc9d7db71..4b554b0686 100644 --- a/samcli/commands/validate/validate.py +++ b/samcli/commands/validate/validate.py @@ -68,7 +68,7 @@ def _read_sam_file(template): click.secho("SAM Template Not Found", bg="red") raise SamTemplateNotFoundException("Template at {} is not found".format(template)) - with click.open_file(template, "r") as sam_template: + with click.open_file(template, "r", encoding="utf-8") as sam_template: sam_template = yaml_parse(sam_template.read()) return sam_template From 3500e81632fea5ebdf3f481ff4d9a82aa054d73e Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Mon, 23 Sep 2019 12:47:04 -0700 Subject: [PATCH 32/42] Remove forced encoding on a template file --- .../templates/sar/AmazonConnectSalesforceLambda-template.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/smoke/templates/sar/AmazonConnectSalesforceLambda-template.yaml b/tests/smoke/templates/sar/AmazonConnectSalesforceLambda-template.yaml index 0ccb2b6140..2225caa54d 100644 --- a/tests/smoke/templates/sar/AmazonConnectSalesforceLambda-template.yaml +++ b/tests/smoke/templates/sar/AmazonConnectSalesforceLambda-template.yaml @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: Amazon Connect SalesForce Lambda integration From 2f7152913f85a0cafd2592f4de2d7f1e683b884d Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Mon, 23 Sep 2019 12:48:37 -0700 Subject: [PATCH 33/42] remove un-needed dev requirements --- requirements/dev.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index c9c01dd471..c0209ea593 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -4,6 +4,5 @@ pylint==2.3.1 # Test requirements pytest==5.1.2 -#mock==2.0.0 # mock is now part of the Python standard library, available as unittest.mock in Python 3.3 onwards. parameterized==0.7.0 -pytest-xdist==1.29.0 +pytest-xdist==1.29.0 \ No newline at end of file From 1d0eb1a5cf13836efe14873ae333606563adb205 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Mon, 23 Sep 2019 12:50:16 -0700 Subject: [PATCH 34/42] Removed depreciation warning --- samcli/cli/command.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/samcli/cli/command.py b/samcli/cli/command.py index ca1fdee333..2a5527ed48 100644 --- a/samcli/cli/command.py +++ b/samcli/cli/command.py @@ -24,14 +24,6 @@ "samcli.commands.publish", ] -DEPRECATION_NOTICE = ( - "Deprecated : AWS SAM CLI no longer supports " - "installations on Python 2.7. " - "Install AWS SAM CLI via https://docs.aws.amazon.com/serverless-application-model/" - "latest/developerguide/serverless-sam-cli-install.html for continued support with new versions. \n" -) - - class BaseCommand(click.MultiCommand): """ Dynamically loads commands. It takes a list of names of Python packages representing the commands, loads @@ -69,9 +61,6 @@ def __init__(self, *args, cmd_packages=None, **kwargs): self._commands = {} self._commands = BaseCommand._set_commands(cmd_packages) - if sys.version_info.major == 2: - click.secho(DEPRECATION_NOTICE, fg="red", err=True) - @staticmethod def _set_commands(package_names): """ From 19c81c7f31873d8d2429c1c6a60826cbeb50d175 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Mon, 23 Sep 2019 13:01:53 -0700 Subject: [PATCH 35/42] Remove deprecation warning integ tests --- tests/integration/deprecation/__init__.py | 0 .../deprecation/test_deprecation_warning.py | 32 ------------------- 2 files changed, 32 deletions(-) delete mode 100644 tests/integration/deprecation/__init__.py delete mode 100644 tests/integration/deprecation/test_deprecation_warning.py diff --git a/tests/integration/deprecation/__init__.py b/tests/integration/deprecation/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/integration/deprecation/test_deprecation_warning.py b/tests/integration/deprecation/test_deprecation_warning.py deleted file mode 100644 index d4ea9e8c56..0000000000 --- a/tests/integration/deprecation/test_deprecation_warning.py +++ /dev/null @@ -1,32 +0,0 @@ -import os -import re -import subprocess -import sys - -from unittest import TestCase - -from samcli.cli.command import DEPRECATION_NOTICE - - -class TestPy2DeprecationWarning(TestCase): - def base_command(self): - command = "sam" - if os.getenv("SAM_CLI_DEV"): - command = "samdev" - - return command - - def run_cmd(self): - # Checking with base command to see if warning is present if running in python2 - cmd_list = [self.base_command()] - process = subprocess.Popen(cmd_list, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - return process - - def test_print_deprecation_warning_if_py2(self): - process = self.run_cmd() - (stdoutdata, stderrdata) = process.communicate() - - expected_notice = re.sub(r"\n", os.linesep, DEPRECATION_NOTICE) - # Deprecation notice should be part of the command output if running in python 2 - if sys.version_info.major == 2: - self.assertIn(expected_notice, stderrdata.decode()) From c6fb7f9d3b25c2f688e8d892056aecc8d35de45f Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 24 Sep 2019 08:19:28 -0700 Subject: [PATCH 36/42] Remove py27 formatting from black --- pyproject.toml | 3 ++- samcli/commands/init/__init__.py | 2 +- samcli/local/docker/manager.py | 6 +++--- scripts/check-isolated-needs-update.py | 2 +- scripts/check-requirements.py | 12 ++++++------ tests/functional/local/lambdafn/test_runtime.py | 12 ++++++------ .../local/invoke/runtimes/test_with_runtime_zips.py | 2 +- tests/integration/telemetry/integ_base.py | 2 +- tests/unit/local/lambdafn/test_env_vars.py | 2 +- 9 files changed, 22 insertions(+), 21 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 40711e3163..a1b0857777 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = ["setuptools", "wheel"] # PEP 508 specifications. [tool.black] line-length = 120 -target_version = ['py37', 'py27', 'py36'] +target_version = ['py37', 'py36'] exclude = ''' ( @@ -17,6 +17,7 @@ exclude = ''' | dist | pip-wheel-metadata | samcli/local/init/templates + | tests/integration/testdata )/ ) ''' diff --git a/samcli/commands/init/__init__.py b/samcli/commands/init/__init__.py index 613b624ee1..d6f0d29595 100644 --- a/samcli/commands/init/__init__.py +++ b/samcli/commands/init/__init__.py @@ -14,7 +14,7 @@ @click.command( - "init", short_help="Init an AWS SAM application.", context_settings=dict(help_option_names=[u"-h", u"--help"]) + "init", short_help="Init an AWS SAM application.", context_settings=dict(help_option_names=["-h", "--help"]) ) @click.option("-l", "--location", help="Template location (git, mercurial, http(s), zip, path)") @click.option( diff --git a/samcli/local/docker/manager.py b/samcli/local/docker/manager.py index ac99de4544..39faf9296e 100644 --- a/samcli/local/docker/manager.py +++ b/samcli/local/docker/manager.py @@ -127,16 +127,16 @@ def pull_image(self, image_name, stream=None): raise DockerImagePullFailedException(str(ex)) # io streams, especially StringIO, work only with unicode strings - stream_writer.write(u"\nFetching {} Docker container image...".format(image_name)) + stream_writer.write("\nFetching {} Docker container image...".format(image_name)) # Each line contains information on progress of the pull. Each line is a JSON string for _ in result_itr: # For every line, print a dot to show progress - stream_writer.write(u".") + stream_writer.write(".") stream_writer.flush() # We are done. Go to the next line - stream_writer.write(u"\n") + stream_writer.write("\n") def has_image(self, image_name): """ diff --git a/scripts/check-isolated-needs-update.py b/scripts/check-isolated-needs-update.py index c4325f2e59..d4ad92ad2d 100644 --- a/scripts/check-isolated-needs-update.py +++ b/scripts/check-isolated-needs-update.py @@ -54,5 +54,5 @@ def get_requirements_list(content): assert installed_pkg_version in isolated_req_list, "{} is in base.txt but not in isolated.txt".format( installed_pkg_version ) - print ("{} is in the isolated.txt file".format(installed_pkg_version)) + print("{} is in the isolated.txt file".format(installed_pkg_version)) break diff --git a/scripts/check-requirements.py b/scripts/check-requirements.py index 07dd425e4d..4d4b522db7 100755 --- a/scripts/check-requirements.py +++ b/scripts/check-requirements.py @@ -23,9 +23,9 @@ def read(*filenames, **kwargs): if package.split("==")[0] not in exclude_packages: all_pkgs_list.append(package) all_pkgs_list = sorted(all_pkgs_list) -print ("installed package/versions" + os.linesep) -print (",".join(all_pkgs_list)) -print (os.linesep) +print("installed package/versions" + os.linesep) +print(",".join(all_pkgs_list)) +print(os.linesep) content = read(os.path.join("requirements", "isolated.txt")) @@ -35,9 +35,9 @@ def read(*filenames, **kwargs): locked_pkgs.append(line) locked_pkgs = sorted(locked_pkgs) -print ("locked package/versions" + os.linesep) -print (",".join(locked_pkgs)) -print (os.linesep) +print("locked package/versions" + os.linesep) +print(",".join(locked_pkgs)) +print(os.linesep) assert len(locked_pkgs) == len(all_pkgs_list), "Number of expected dependencies do not match the number installed" assert locked_pkgs == all_pkgs_list, "The list of expected dependencies do not match what is installed" diff --git a/tests/functional/local/lambdafn/test_runtime.py b/tests/functional/local/lambdafn/test_runtime.py index 57f4dd4a4f..4f0ce0152d 100644 --- a/tests/functional/local/lambdafn/test_runtime.py +++ b/tests/functional/local/lambdafn/test_runtime.py @@ -95,7 +95,7 @@ def test_function_timeout(self): # Make sure that the wall clock duration is around the ballpark of timeout value wall_clock_func_duration = end - start - print ("Function completed in {} seconds".format(wall_clock_func_duration)) + print("Function completed in {} seconds".format(wall_clock_func_duration)) # The function should *not* preemptively stop self.assertGreater(wall_clock_func_duration, timeout - 1) # The function should not run for much longer than timeout. @@ -214,7 +214,7 @@ def tearDown(self): def _invoke_sleep(self, timeout, sleep_duration, check_stdout, exceptions=None): name = "sleepfunction_timeout_{}_sleep_{}".format(timeout, sleep_duration) - print ("Invoking function " + name) + print("Invoking function " + name) try: stdout_stream = io.BytesIO() stdout_stream_writer = StreamWriter(stdout_stream) @@ -276,10 +276,10 @@ def test_parallel(self): t.join() for e in exceptions: - print ("-------------") - print ("ERROR in function " + e["name"]) - print (e["error"]) - print ("-------------") + print("-------------") + print("ERROR in function " + e["name"]) + print(e["error"]) + print("-------------") if len(exceptions) > 0: raise AssertionError("Test failed. See print outputs above for details on the thread that failed") diff --git a/tests/integration/local/invoke/runtimes/test_with_runtime_zips.py b/tests/integration/local/invoke/runtimes/test_with_runtime_zips.py index 97227c05a8..3b6177e1ad 100644 --- a/tests/integration/local/invoke/runtimes/test_with_runtime_zips.py +++ b/tests/integration/local/invoke/runtimes/test_with_runtime_zips.py @@ -54,4 +54,4 @@ def test_custom_provided_runtime(self): self.assertEqual(return_code, 0) process_stdout = b"".join(process.stdout.readlines()).strip() - self.assertEqual(process_stdout.decode("utf-8"), u'{"body":"hello 曰有冥 world 🐿","statusCode":200,"headers":{}}') + self.assertEqual(process_stdout.decode("utf-8"), '{"body":"hello 曰有冥 world 🐿","statusCode":200,"headers":{}}') diff --git a/tests/integration/telemetry/integ_base.py b/tests/integration/telemetry/integ_base.py index f991afa3b0..6637e7bca6 100644 --- a/tests/integration/telemetry/integ_base.py +++ b/tests/integration/telemetry/integ_base.py @@ -192,5 +192,5 @@ def _request_handler(self, **kwargs): def _shutdown_flask(self): # Based on http://flask.pocoo.org/snippets/67/ request.environ.get("werkzeug.server.shutdown")() - print ("Server shutting down...") + print("Server shutting down...") return "" diff --git a/tests/unit/local/lambdafn/test_env_vars.py b/tests/unit/local/lambdafn/test_env_vars.py index 3e319fc682..5491df9b87 100644 --- a/tests/unit/local/lambdafn/test_env_vars.py +++ b/tests/unit/local/lambdafn/test_env_vars.py @@ -305,7 +305,7 @@ def test_must_replace_non_scalar_with_blank_values(self, input): (False, "false"), (1234, "1234"), (3.14, "3.14"), - (u"mystring\xe0", u"mystring\xe0"), + ("mystring\xe0", "mystring\xe0"), ("mystring", "mystring"), ] ) From e7861deedadb284414048fb410fbcba5cf8c2dcc Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Tue, 24 Sep 2019 12:06:38 -0700 Subject: [PATCH 37/42] Ingore nose-parameterize warnings --- appveyor-windows.yml | 1 + appveyor.yml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/appveyor-windows.yml b/appveyor-windows.yml index 3243f006a6..0bddf396cf 100644 --- a/appveyor-windows.yml +++ b/appveyor-windows.yml @@ -25,6 +25,7 @@ environment: HOME: 'C:\Users\appveyor' HOMEDRIVE: 'C:' HOMEPATH: 'C:\Users\appveyor' + NOSE_PARAMETERIZED_NO_WARN: 1 init: # Uncomment this for RDP diff --git a/appveyor.yml b/appveyor.yml index 8706545888..45c4262dd8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -12,11 +12,13 @@ environment: - PYTHON_HOME: "C:\\Python36-x64" PYTHON_VERSION: '3.6.8' PYTHON_ARCH: '64' + NOSE_PARAMETERIZED_NO_WARN: 1 - PYTHON_HOME: "C:\\Python37-x64" PYTHON_VERSION: '3.7.4' PYTHON_ARCH: '64' RUN_SMOKE: 1 + NOSE_PARAMETERIZED_NO_WARN: 1 for: - From ef1ae1e253bfd590fa8f1d1020d6b8711eff0378 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Mon, 21 Oct 2019 07:19:28 -0700 Subject: [PATCH 38/42] Fix rebase conflicts --- appveyor.yml | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 45c4262dd8..c7bf8d775c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -40,12 +40,8 @@ for: # Create new virtual environment and activate it - "rm -rf venv" - "python -m virtualenv venv" -<<<<<<< HEAD - "venv\\Scripts\\activate" -======= - - "venv/Scripts/activate" - "python --version" ->>>>>>> attempt to to make windows appveyor use py3 instead of py2 build_script: # Activate virtualenv again on windows @@ -115,28 +111,5 @@ for: test_script: # Smoke tests run in parallel -<<<<<<< HEAD - sh: "venv/Scripts/activate" - sh: "pytest -n 4 -vv tests/smoke" -======= - - "pytest -n 4 -vv tests/smoke" - -build_script: - - "python -c \"import sys; print(sys.executable)\"" - - # Actually install SAM CLI's dependencies - - "pip install -e \".[dev]\"" - -test_script: - - "pytest --cov samcli --cov-report term-missing --cov-fail-under 95 tests/unit" - - "pylint --rcfile .pylintrc samcli" - - # Runs only in Linux - - sh: "pytest -vv tests/integration" - - sh: "/tmp/black --check setup.py tests samcli scripts" - - sh: "python scripts/check-isolated-needs-update.py" - - # Smoke tests run in parallel - it runs on both Linux & Windows - # Presence of the RUN_SMOKE envvar will run the smoke tests - - ps: "If ($env:RUN_SMOKE) {pytest -n 4 -vv tests/smoke}" ->>>>>>> attempt to to make windows appveyor use py3 instead of py2 From 02a9ec13e30acef6447256745fe86f2cfaa64f4f Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Mon, 21 Oct 2019 07:25:41 -0700 Subject: [PATCH 39/42] format with black --- samcli/cli/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samcli/cli/command.py b/samcli/cli/command.py index 2a5527ed48..f56e93fb80 100644 --- a/samcli/cli/command.py +++ b/samcli/cli/command.py @@ -4,7 +4,6 @@ import logging import importlib -import sys from collections import OrderedDict import click @@ -24,6 +23,7 @@ "samcli.commands.publish", ] + class BaseCommand(click.MultiCommand): """ Dynamically loads commands. It takes a list of names of Python packages representing the commands, loads From 6348db8f28e2e0a533678a228c9c80f5e6170e8d Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Mon, 21 Oct 2019 07:25:52 -0700 Subject: [PATCH 40/42] fix import order --- samcli/commands/publish/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samcli/commands/publish/command.py b/samcli/commands/publish/command.py index d2817a2277..643895327e 100644 --- a/samcli/commands/publish/command.py +++ b/samcli/commands/publish/command.py @@ -5,12 +5,12 @@ import click import boto3 +from serverlessrepo.publish import CREATE_APPLICATION from samcli.cli.main import pass_context, common_options as cli_framework_options, aws_creds_options from samcli.commands._utils.options import template_common_option from samcli.commands._utils.template import get_template_data from samcli.lib.telemetry.metrics import track_command -from serverlessrepo.publish import CREATE_APPLICATION LOG = logging.getLogger(__name__) From 2e61897f2840883ee414b799923ce5716953e7d0 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Mon, 21 Oct 2019 11:13:02 -0500 Subject: [PATCH 41/42] Add pytest-forked and timeout back to dev.txt --- requirements/dev.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index c0209ea593..fc8282f6da 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -5,4 +5,6 @@ pylint==2.3.1 # Test requirements pytest==5.1.2 parameterized==0.7.0 -pytest-xdist==1.29.0 \ No newline at end of file +pytest-xdist==1.29.0 +pytest-forked==1.0.2 +pytest-timeout==1.3.3 \ No newline at end of file From d0a18962877c4014c342d0bd4fa07956e56edae0 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Wed, 23 Oct 2019 15:12:27 -0500 Subject: [PATCH 42/42] Handle further updates after rebasing with HEAD of develop --- requirements/dev.txt | 9 +++++---- .../lib/intrinsic_resolver/test_intrinsic_resolver.py | 3 +-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index fc8282f6da..af29d59fa2 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -3,8 +3,9 @@ pytest-cov==2.7.1 pylint==2.3.1 # Test requirements -pytest==5.1.2 +pytest==5.2.1 parameterized==0.7.0 -pytest-xdist==1.29.0 -pytest-forked==1.0.2 -pytest-timeout==1.3.3 \ No newline at end of file +pytest-xdist==1.30.0 +pytest-forked==1.1.3 +pytest-timeout==1.3.3 +pytest-rerunfailures==7.0 \ No newline at end of file diff --git a/tests/unit/lib/intrinsic_resolver/test_intrinsic_resolver.py b/tests/unit/lib/intrinsic_resolver/test_intrinsic_resolver.py index c262838608..047a292a63 100644 --- a/tests/unit/lib/intrinsic_resolver/test_intrinsic_resolver.py +++ b/tests/unit/lib/intrinsic_resolver/test_intrinsic_resolver.py @@ -3,8 +3,7 @@ from copy import deepcopy from pathlib import Path from unittest import TestCase - -from mock import patch +from unittest.mock import patch from parameterized import parameterized