Added issue #20 test case.

This commit is contained in:
Fabio Caccamo 2020-08-12 12:42:16 +02:00
parent 9610ee35f0
commit 991487590f
2 changed files with 55 additions and 0 deletions

0
tests/github/__init__.py Normal file
View File

View File

@ -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))