From 6c4ed246eb1d0d358ec55290f3298fe405208e92 Mon Sep 17 00:00:00 2001 From: Jacob Fuss Date: Wed, 4 Sep 2019 08:27:53 -0700 Subject: [PATCH] Rebase/blackify new commits into develop --- samcli/yamlhelper.py | 9 +---- tests/unit/test_yamlhelper.py | 74 +++++++++++++++++------------------ 2 files changed, 37 insertions(+), 46 deletions(-) diff --git a/samcli/yamlhelper.py b/samcli/yamlhelper.py index 6e21bba56c..658bb8183c 100644 --- a/samcli/yamlhelper.py +++ b/samcli/yamlhelper.py @@ -74,11 +74,7 @@ def yaml_dump(dict_to_dump): :return: """ FlattenAliasDumper.add_representer(OrderedDict, _dict_representer) - return yaml.dump( - dict_to_dump, - default_flow_style=False, - Dumper=FlattenAliasDumper, - ) + return yaml.dump(dict_to_dump, default_flow_style=False, Dumper=FlattenAliasDumper) def _dict_constructor(loader, node): @@ -96,8 +92,7 @@ def yaml_parse(yamlstr): return json.loads(yamlstr, object_pairs_hook=OrderedDict) except ValueError: yaml.SafeLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, _dict_constructor) - yaml.SafeLoader.add_multi_constructor( - "!", intrinsics_multi_constructor) + yaml.SafeLoader.add_multi_constructor("!", intrinsics_multi_constructor) return yaml.safe_load(yamlstr) diff --git a/tests/unit/test_yamlhelper.py b/tests/unit/test_yamlhelper.py index 04079c009f..c8f0aa46d5 100644 --- a/tests/unit/test_yamlhelper.py +++ b/tests/unit/test_yamlhelper.py @@ -65,7 +65,7 @@ def test_yaml_getatt(self): def test_parse_json_with_tabs(self): template = '{\n\t"foo": "bar"\n}' output = yaml_parse(template) - self.assertEqual(output, {'foo': 'bar'}) + self.assertEqual(output, {"foo": "bar"}) def test_parse_json_preserve_elements_order(self): input_template = """ @@ -88,31 +88,35 @@ def test_parse_json_preserve_elements_order(self): } } """ - expected_dict = OrderedDict([ - ('B_Resource', OrderedDict([('Key2', {'Name': 'name2'}), ('Key1', {'Name': 'name1'})])), - ('A_Resource', OrderedDict([('Key2', {'Name': 'name2'}), ('Key1', {'Name': 'name1'})])) - ]) + expected_dict = OrderedDict( + [ + ("B_Resource", OrderedDict([("Key2", {"Name": "name2"}), ("Key1", {"Name": "name1"})])), + ("A_Resource", OrderedDict([("Key2", {"Name": "name2"}), ("Key1", {"Name": "name1"})])), + ] + ) output_dict = yaml_parse(input_template) self.assertEqual(expected_dict, output_dict) def test_parse_yaml_preserve_elements_order(self): input_template = ( - 'B_Resource:\n' - ' Key2:\n' - ' Name: name2\n' - ' Key1:\n' - ' Name: name1\n' - 'A_Resource:\n' - ' Key2:\n' - ' Name: name2\n' - ' Key1:\n' - ' Name: name1\n' + "B_Resource:\n" + " Key2:\n" + " Name: name2\n" + " Key1:\n" + " Name: name1\n" + "A_Resource:\n" + " Key2:\n" + " Name: name2\n" + " Key1:\n" + " Name: name1\n" ) output_dict = yaml_parse(input_template) - expected_dict = OrderedDict([ - ('B_Resource', OrderedDict([('Key2', {'Name': 'name2'}), ('Key1', {'Name': 'name1'})])), - ('A_Resource', OrderedDict([('Key2', {'Name': 'name2'}), ('Key1', {'Name': 'name1'})])) - ]) + expected_dict = OrderedDict( + [ + ("B_Resource", OrderedDict([("Key2", {"Name": "name2"}), ("Key1", {"Name": "name1"})])), + ("A_Resource", OrderedDict([("Key2", {"Name": "name2"}), ("Key1", {"Name": "name1"})])), + ] + ) self.assertEqual(expected_dict, output_dict) output_template = yaml_dump(output_dict) @@ -127,30 +131,22 @@ def test_yaml_merge_tag(self): """ output = yaml_parse(test_yaml) self.assertTrue(isinstance(output, OrderedDict)) - self.assertEqual(output.get('test').get('property'), 'value') + self.assertEqual(output.get("test").get("property"), "value") def test_unroll_yaml_anchors(self): - properties = { - "Foo": "bar", - "Spam": "eggs", - } - template = { - "Resources": { - "Resource1": {"Properties": properties}, - "Resource2": {"Properties": properties} - } - } + properties = {"Foo": "bar", "Spam": "eggs"} + template = {"Resources": {"Resource1": {"Properties": properties}, "Resource2": {"Properties": properties}}} expected = ( - 'Resources:\n' - ' Resource1:\n' - ' Properties:\n' - ' Foo: bar\n' - ' Spam: eggs\n' - ' Resource2:\n' - ' Properties:\n' - ' Foo: bar\n' - ' Spam: eggs\n' + "Resources:\n" + " Resource1:\n" + " Properties:\n" + " Foo: bar\n" + " Spam: eggs\n" + " Resource2:\n" + " Properties:\n" + " Foo: bar\n" + " Spam: eggs\n" ) actual = yaml_dump(template) self.assertEqual(actual, expected)