File: test_castinterpolated.py

package info (click to toggle)
python-hiyapyco 0.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 436 kB
  • sloc: python: 2,012; makefile: 237
file content (69 lines) | stat: -rwxr-xr-x 1,739 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /usr/bin/env python

import sys
import os
import logging
import platform
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())
        )
    )

yamlfile = os.path.join(basepath, 'castinterpolated.yaml')

logger.info('test uncasted ...')
conf = hiyapyco.load(
        yamlfile,
        method=hiyapyco.METHOD_SIMPLE,
        failonmissingfiles=True,
        interpolate=True,
        )
v = conf['three']
logger.info('test uncasted: %s (type: %s) ... ' % (v, type(v),))
assert v == '3'
v = conf['c']
logger.info('test uncasted: %s (type: %s) ... ' % (v, type(v),))
assert v == '5.9'
v = conf['bool']
logger.info('test uncasted: %s (type: %s) ... ' % (v, type(v),))
assert v == 'True'

conf = hiyapyco.load(
        yamlfile,
        method=hiyapyco.METHOD_SIMPLE,
        failonmissingfiles=True,
        interpolate=True,
        castinterpolated=True,
        )
v = conf['three']
logger.info('test casted: %s (type: %s) ... ' % (v, type(v),))
assert v == 3
v = conf['c']
logger.info('test casted: %s (type: %s) ... ' % (v, type(v),))
assert v == 5.9
v = conf['bool']
logger.info('test casted: %s (type: %s) ... ' % (v, type(v),))
assert v == True

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 smartindent nu