python-benedict/tests/github/test_issue_0020.py

62 lines
1.7 KiB
Python
Raw Normal View History

import unittest
2020-08-12 10:42:16 +00:00
from benedict import benedict
from benedict.serializers.yaml import yaml
class GetAtt(yaml.YAMLObject):
yaml_loader = yaml.SafeLoader
2022-02-13 10:35:43 +00:00
yaml_tag = "!GetAtt"
2020-08-12 10:42:16 +00:00
def __init__(self, val):
self.val = val
@classmethod
def from_yaml(cls, loader, node):
return cls(node.value)
def __repr__(self):
return f"GetAtt({self.val})"
2020-08-12 10:42:16 +00:00
2022-02-13 10:35:43 +00:00
yaml.add_constructor("!GetAtt", GetAtt.from_yaml)
2020-08-12 10:42:16 +00:00
class github_issue_0020_test_case(unittest.TestCase):
2022-02-13 10:35:43 +00:00
"""
This class describes a github issue 0020 test case.
"""
2020-08-12 10:42:16 +00:00
def test_github_issue_0020(self):
"""
https://github.com/fabiocaccamo/python-benedict/issues/20
"""
2022-02-13 10:35:43 +00:00
yaml_str = """
2020-08-12 10:42:16 +00:00
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Outputs:
Description: "LoremIpsum Ex nisi incididunt occaecat dolor."
Value: !GetAtt LoremIpsum.Arn
"""
2023-02-09 18:19:02 +00:00
# r = {
# "AWSTemplateFormatVersion": "2010-09-09",
# "Transform": "AWS::Serverless-2016-10-31",
# "Outputs": {
# "Description": "LoremIpsum Ex nisi incididunt occaecat dolor.",
# "Value": GetAtt("LoremIpsum.Arn"),
# },
# }
2020-08-12 10:42:16 +00:00
2022-02-13 10:35:43 +00:00
b = benedict(yaml_str, format="yaml")
# print(b.dump())
2020-08-12 10:42:16 +00:00
2023-02-09 18:19:02 +00:00
self.assertEqual(b["AWSTemplateFormatVersion"], "2010-09-09")
self.assertEqual(b["Transform"], "AWS::Serverless-2016-10-31")
self.assertEqual(
b["Outputs.Description"], "LoremIpsum Ex nisi incididunt occaecat dolor."
2022-02-13 10:35:43 +00:00
)
self.assertTrue(isinstance(b["Outputs.Value"], GetAtt))
2023-02-09 18:19:02 +00:00
# self.assertEqual(b["Outputs.Value"], r["Outputs"]["Value"])
# self.assertEqual(b, r)