From 991487590f35aae09a373b114e28435f3d534b1b Mon Sep 17 00:00:00 2001 From: Fabio Caccamo Date: Wed, 12 Aug 2020 12:42:16 +0200 Subject: [PATCH] Added issue #20 test case. --- tests/github/__init__.py | 0 tests/github/test_issue_0020.py | 55 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/github/__init__.py create mode 100644 tests/github/test_issue_0020.py diff --git a/tests/github/__init__.py b/tests/github/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/github/test_issue_0020.py b/tests/github/test_issue_0020.py new file mode 100644 index 0000000..5aa1f8f --- /dev/null +++ b/tests/github/test_issue_0020.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- + +from benedict import benedict +from benedict.serializers.yaml import yaml + +import unittest + + +class GetAtt(yaml.YAMLObject): + yaml_loader = yaml.SafeLoader + yaml_tag = '!GetAtt' + + def __init__(self, val): + self.val = val + + @classmethod + def from_yaml(cls, loader, node): + return cls(node.value) + + def __repr__(self): + return 'GetAtt({})'.format(self.val) + +yaml.add_constructor('!GetAtt', GetAtt.from_yaml) + + +class github_issue_0020_test_case(unittest.TestCase): + + def test_github_issue_0020(self): + """ + https://github.com/fabiocaccamo/python-benedict/issues/20 + """ + yaml_str =""" +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Outputs: + Description: "LoremIpsum Ex nisi incididunt occaecat dolor." + Value: !GetAtt LoremIpsum.Arn + """ + + r = { + 'AWSTemplateFormatVersion': '2010-09-09', + 'Transform': 'AWS::Serverless-2016-10-31', + 'Outputs': { + 'Description': 'LoremIpsum Ex nisi incididunt occaecat dolor.', + 'Value': GetAtt('LoremIpsum.Arn'), + }, + } + + b = benedict(yaml_str, format='yaml') + # print(b.dump()) + + self.assertTrue(b['AWSTemplateFormatVersion'] == '2010-09-09') + self.assertTrue(b['Transform'] == 'AWS::Serverless-2016-10-31') + self.assertTrue(b['Outputs.Description'] == 'LoremIpsum Ex nisi incididunt occaecat dolor.') + self.assertTrue(isinstance(b['Outputs.Value'], GetAtt))