Skip to content

Commit

Permalink
#57 - example on how to use ruamel with the new custom class loader
Browse files Browse the repository at this point in the history
  • Loading branch information
zerwes committed Oct 19, 2024
1 parent af03ece commit 610096d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/test_ruamel_yaml_loader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#! /usr/bin/env python

import sys
import os
import logging
import platform
from ruamel.yaml import YAML

basepath = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.dirname(basepath))

import hiyapyco


sys.path.insert(
0,
os.path.join(
os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0]))), "lib"
),
)
import testsetup

logger = testsetup.setup(sys.argv[1:])

basepath = os.path.dirname(os.path.realpath(__file__))

print(
"start test %s for hiyapyco %s using python %s (loglevel:%s)"
% (
__file__,
hiyapyco.__version__,
platform.python_version(),
logging.getLevelName(logger.getEffectiveLevel()),
)
)

logger.info("test ruamel yaml loader ...")


def ruamel_loader(stream):
yaml = YAML(typ='safe')
return yaml.load_all(stream)


conf = hiyapyco.load(os.path.join(basepath, "base.yaml"), loader_callback=ruamel_loader)

expected = {'singel': 'base', 'int': 1, 'array': ['base1', 'base2'], 'hash': {'k1': 'b1', 'k2': 'b2'}, 'deeplist': [{'d1': {'d1k1': 'v1', 'd1k2': 'v2'}}, {'d2': {'d2k1': 'x1', 'd2k2': 'x2'}}, {'d31': {'a': 'A', 'b': 'B', 'c': 'C'}, 'd32': {'a': 'A2', 'b': 'B2'}}], 'deepmap': {'l1k1': {'l2k1': 'xyz', 'l2k2': 'abc'}, 'l1k2': {'l2k1': 'bli', 'l2k2': 'bla', 'l2k3': 'blub'}}, 'missing_key': 'one', 'common_key': {'common_subkey_deep': 'one', 'missing_key_base': 'val2'}}

assert conf == expected

print("passed test %s" % __file__)

0 comments on commit 610096d

Please sign in to comment.