Skip to content

Commit db386e0

Browse files
committed
style: apply black formatting to new tests
1 parent b07095f commit db386e0

2 files changed

Lines changed: 41 additions & 38 deletions

File tree

tests/unit/commands/package/test_package_context.py

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -977,25 +977,30 @@ def test_apply_artifact_mappings_to_template_integration(self):
977977

978978
def test_get_prop_value_flat_key(self):
979979
from samcli.lib.package.language_extensions_packaging import _get_prop_value
980+
980981
self.assertEqual(_get_prop_value({"CodeUri": "s3://b/k"}, "CodeUri"), "s3://b/k")
981982

982983
def test_get_prop_value_dotted_key(self):
983984
from samcli.lib.package.language_extensions_packaging import _get_prop_value
985+
984986
props = {"Command": {"ScriptLocation": "s3://b/k.py"}}
985987
self.assertEqual(_get_prop_value(props, "Command.ScriptLocation"), "s3://b/k.py")
986988

987989
def test_get_prop_value_missing_returns_none(self):
988990
from samcli.lib.package.language_extensions_packaging import _get_prop_value
991+
989992
self.assertIsNone(_get_prop_value({"CodeUri": "x"}, "Command.ScriptLocation"))
990993

991994
def test_set_prop_value_flat_key(self):
992995
from samcli.lib.package.language_extensions_packaging import _set_prop_value
996+
993997
props = {"CodeUri": "./src"}
994998
_set_prop_value(props, "CodeUri", "s3://b/k")
995999
self.assertEqual(props["CodeUri"], "s3://b/k")
9961000

9971001
def test_set_prop_value_dotted_key_creates_intermediate(self):
9981002
from samcli.lib.package.language_extensions_packaging import _set_prop_value
1003+
9991004
props = {"Command": {"Name": "glueetl"}}
10001005
_set_prop_value(props, "Command.ScriptLocation", "s3://b/k.py")
10011006
self.assertEqual(props["Command"]["ScriptLocation"], "s3://b/k.py")
@@ -1018,42 +1023,34 @@ def test_copy_artifact_uris_for_type_serverless_application(self):
10181023
"""Regression for #9005: Location URI must be copied for AWS::Serverless::Application."""
10191024
original_props = {"Location": "./PublisherApi/template.yaml"}
10201025
exported_props = {"Location": "https://s3.amazonaws.com/bucket/abc123.template"}
1021-
self.assertTrue(_copy_artifact_uris_for_type(
1022-
original_props, exported_props, "AWS::Serverless::Application"
1023-
))
1026+
self.assertTrue(_copy_artifact_uris_for_type(original_props, exported_props, "AWS::Serverless::Application"))
10241027
self.assertEqual(original_props["Location"], "https://s3.amazonaws.com/bucket/abc123.template")
10251028

10261029
def test_copy_artifact_uris_for_type_cloudformation_stack(self):
10271030
"""TemplateURL must be copied for AWS::CloudFormation::Stack."""
10281031
original_props = {"TemplateURL": "./child/template.yaml"}
10291032
exported_props = {"TemplateURL": "https://s3.amazonaws.com/bucket/xyz789.template"}
1030-
self.assertTrue(_copy_artifact_uris_for_type(
1031-
original_props, exported_props, "AWS::CloudFormation::Stack"
1032-
))
1033+
self.assertTrue(_copy_artifact_uris_for_type(original_props, exported_props, "AWS::CloudFormation::Stack"))
10331034
self.assertEqual(original_props["TemplateURL"], "https://s3.amazonaws.com/bucket/xyz789.template")
10341035

10351036
def test_copy_artifact_uris_for_type_cloudformation_stackset(self):
10361037
original_props = {"TemplateURL": "./child.yaml"}
10371038
exported_props = {"TemplateURL": "https://s3.amazonaws.com/b/k.template"}
1038-
self.assertTrue(_copy_artifact_uris_for_type(
1039-
original_props, exported_props, "AWS::CloudFormation::StackSet"
1040-
))
1039+
self.assertTrue(_copy_artifact_uris_for_type(original_props, exported_props, "AWS::CloudFormation::StackSet"))
10411040
self.assertEqual(original_props["TemplateURL"], "https://s3.amazonaws.com/b/k.template")
10421041

10431042
def test_copy_artifact_uris_for_type_eb_application_version(self):
10441043
original_props = {"SourceBundle": "./bundle.zip"}
10451044
exported_props = {"SourceBundle": {"S3Bucket": "b", "S3Key": "k"}}
1046-
self.assertTrue(_copy_artifact_uris_for_type(
1047-
original_props, exported_props, "AWS::ElasticBeanstalk::ApplicationVersion"
1048-
))
1045+
self.assertTrue(
1046+
_copy_artifact_uris_for_type(original_props, exported_props, "AWS::ElasticBeanstalk::ApplicationVersion")
1047+
)
10491048
self.assertEqual(original_props["SourceBundle"], {"S3Bucket": "b", "S3Key": "k"})
10501049

10511050
def test_copy_artifact_uris_for_type_appsync_graphql_schema(self):
10521051
original_props = {"DefinitionS3Location": "./schema.graphql"}
10531052
exported_props = {"DefinitionS3Location": "s3://b/schema.graphql"}
1054-
self.assertTrue(_copy_artifact_uris_for_type(
1055-
original_props, exported_props, "AWS::AppSync::GraphQLSchema"
1056-
))
1053+
self.assertTrue(_copy_artifact_uris_for_type(original_props, exported_props, "AWS::AppSync::GraphQLSchema"))
10571054
self.assertEqual(original_props["DefinitionS3Location"], "s3://b/schema.graphql")
10581055

10591056
def test_copy_artifact_uris_for_type_appsync_resolver_all_three(self):
@@ -1067,46 +1064,41 @@ def test_copy_artifact_uris_for_type_appsync_resolver_all_three(self):
10671064
"ResponseMappingTemplateS3Location": "s3://b/res.vtl",
10681065
"CodeS3Location": "s3://b/code.js",
10691066
}
1070-
self.assertTrue(_copy_artifact_uris_for_type(
1071-
original_props, exported_props, "AWS::AppSync::Resolver"
1072-
))
1067+
self.assertTrue(_copy_artifact_uris_for_type(original_props, exported_props, "AWS::AppSync::Resolver"))
10731068
self.assertEqual(original_props["RequestMappingTemplateS3Location"], "s3://b/req.vtl")
10741069
self.assertEqual(original_props["ResponseMappingTemplateS3Location"], "s3://b/res.vtl")
10751070
self.assertEqual(original_props["CodeS3Location"], "s3://b/code.js")
10761071

10771072
def test_copy_artifact_uris_for_type_appsync_function_configuration(self):
10781073
original_props = {"CodeS3Location": "./code.js"}
10791074
exported_props = {"CodeS3Location": "s3://b/code.js"}
1080-
self.assertTrue(_copy_artifact_uris_for_type(
1081-
original_props, exported_props, "AWS::AppSync::FunctionConfiguration"
1082-
))
1075+
self.assertTrue(
1076+
_copy_artifact_uris_for_type(original_props, exported_props, "AWS::AppSync::FunctionConfiguration")
1077+
)
10831078
self.assertEqual(original_props["CodeS3Location"], "s3://b/code.js")
10841079

10851080
def test_copy_artifact_uris_for_type_cloudformation_module_version(self):
10861081
original_props = {"ModulePackage": "./module.zip"}
10871082
exported_props = {"ModulePackage": "s3://b/module.zip"}
1088-
self.assertTrue(_copy_artifact_uris_for_type(
1089-
original_props, exported_props, "AWS::CloudFormation::ModuleVersion"
1090-
))
1083+
self.assertTrue(
1084+
_copy_artifact_uris_for_type(original_props, exported_props, "AWS::CloudFormation::ModuleVersion")
1085+
)
10911086
self.assertEqual(original_props["ModulePackage"], "s3://b/module.zip")
10921087

10931088
def test_copy_artifact_uris_for_type_cloudformation_resource_version(self):
10941089
original_props = {"SchemaHandlerPackage": "./pkg.zip"}
10951090
exported_props = {"SchemaHandlerPackage": "s3://b/pkg.zip"}
1096-
self.assertTrue(_copy_artifact_uris_for_type(
1097-
original_props, exported_props, "AWS::CloudFormation::ResourceVersion"
1098-
))
1091+
self.assertTrue(
1092+
_copy_artifact_uris_for_type(original_props, exported_props, "AWS::CloudFormation::ResourceVersion")
1093+
)
10991094
self.assertEqual(original_props["SchemaHandlerPackage"], "s3://b/pkg.zip")
11001095

11011096
def test_copy_artifact_uris_for_type_lambda_function_image_dotted(self):
11021097
# AWS::Lambda::Function has both Code and Code.ImageUri (dotted path)
11031098
original_props = {"Code": {"ImageUri": "local-tag:latest"}}
11041099
exported_props = {"Code": {"ImageUri": "111.dkr.ecr.us-east-1.amazonaws.com/r:tag"}}
1105-
self.assertTrue(_copy_artifact_uris_for_type(
1106-
original_props, exported_props, "AWS::Lambda::Function"
1107-
))
1108-
self.assertEqual(original_props["Code"]["ImageUri"],
1109-
"111.dkr.ecr.us-east-1.amazonaws.com/r:tag")
1100+
self.assertTrue(_copy_artifact_uris_for_type(original_props, exported_props, "AWS::Lambda::Function"))
1101+
self.assertEqual(original_props["Code"]["ImageUri"], "111.dkr.ecr.us-east-1.amazonaws.com/r:tag")
11101102

11111103

11121104
class TestPackageContextMappingsIntegration(TestCase):

tests/unit/lib/cfn_language_extensions/test_models.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,69 +290,80 @@ class TestPackageableResourceArtifactProperties:
290290

291291
def test_includes_existing_serverless_function(self):
292292
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
293+
293294
assert "CodeUri" in PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::Serverless::Function"]
294295
assert "ImageUri" in PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::Serverless::Function"]
295296

296297
def test_includes_existing_lambda_function_dotted_image(self):
297298
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
299+
298300
props = PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::Lambda::Function"]
299301
assert "Code" in props
300302
assert "Code.ImageUri" in props
301303

302304
def test_includes_serverless_application(self):
303305
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
306+
304307
assert PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::Serverless::Application"] == ["Location"]
305308

306309
def test_includes_cloudformation_stackset(self):
307310
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
311+
308312
assert PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::CloudFormation::StackSet"] == ["TemplateURL"]
309313

310314
def test_includes_elasticbeanstalk_application_version(self):
311315
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
312-
assert PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::ElasticBeanstalk::ApplicationVersion"] == [
313-
"SourceBundle"
314-
]
316+
317+
assert PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::ElasticBeanstalk::ApplicationVersion"] == ["SourceBundle"]
315318

316319
def test_includes_appsync_graphql_schema(self):
317320
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
321+
318322
assert PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::AppSync::GraphQLSchema"] == ["DefinitionS3Location"]
319323

320324
def test_includes_appsync_resolver_three_props(self):
321325
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
326+
322327
props = PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::AppSync::Resolver"]
323328
assert sorted(props) == sorted(
324329
["RequestMappingTemplateS3Location", "ResponseMappingTemplateS3Location", "CodeS3Location"]
325330
)
326331

327332
def test_includes_appsync_function_configuration_three_props(self):
328333
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
334+
329335
props = PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::AppSync::FunctionConfiguration"]
330336
assert sorted(props) == sorted(
331337
["RequestMappingTemplateS3Location", "ResponseMappingTemplateS3Location", "CodeS3Location"]
332338
)
333339

334340
def test_includes_glue_job_dotted_path(self):
335341
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
342+
336343
assert PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::Glue::Job"] == ["Command.ScriptLocation"]
337344

338345
def test_includes_cloudformation_module_version(self):
339346
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
347+
340348
assert PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::CloudFormation::ModuleVersion"] == ["ModulePackage"]
341349

342350
def test_includes_cloudformation_resource_version(self):
343351
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
352+
344353
assert PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES["AWS::CloudFormation::ResourceVersion"] == [
345354
"SchemaHandlerPackage"
346355
]
347356

348357
def test_excludes_ecr_repository_repositoryname(self):
349358
"""RepositoryName is a name, not a packaged-artifact URI. Excluded by design."""
350359
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
360+
351361
assert "AWS::ECR::Repository" not in PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
352362

353363
def test_excludes_serverlessrepo_application_metadata(self):
354364
"""ServerlessRepo::Application uses METADATA_WITH_LOCAL_PATHS, not resource props."""
355365
from samcli.lib.cfn_language_extensions.models import PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
366+
356367
assert "AWS::ServerlessRepo::Application" not in PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
357368

358369
def test_dict_is_in_sync_with_canonical_lists(self):
@@ -361,8 +372,8 @@ def test_dict_is_in_sync_with_canonical_lists(self):
361372
from samcli.lib.utils.resources import RESOURCES_WITH_LOCAL_PATHS
362373

363374
for resource_type, props in RESOURCES_WITH_LOCAL_PATHS.items():
364-
assert resource_type in PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES, (
365-
f"{resource_type} from RESOURCES_WITH_LOCAL_PATHS must be in derived dict"
366-
)
375+
assert (
376+
resource_type in PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES
377+
), f"{resource_type} from RESOURCES_WITH_LOCAL_PATHS must be in derived dict"
367378
for prop in props:
368379
assert prop in PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES[resource_type]

0 commit comments

Comments
 (0)