comparison tests/test.py @ 119:eefde3288fb8

FIX: YAML-file streams must be opened as UTF-8 text files; otherwise double encoding occurs for non-Unicode locales (e.g. Windows)
author Franz Glasner <f.glasner@feldmann-mg.com>
date Thu, 29 Mar 2018 12:37:20 +0200
parents c37fa787c022
children ba5970a2dcef
comparison
equal deleted inserted replaced
118:e37fc67ae7f3 119:eefde3288fb8
2 2
3 import sys 3 import sys
4 import os 4 import os
5 import unittest 5 import unittest
6 import platform 6 import platform
7 import io
7 8
8 sys.path.insert( 9 sys.path.insert(
9 0, 10 0,
10 os.path.abspath( 11 os.path.abspath(
11 os.path.normpath(os.path.join(os.path.dirname(__file__), "..")))) 12 os.path.normpath(os.path.join(os.path.dirname(__file__), ".."))))
57 def test02_py_types(self): 58 def test02_py_types(self):
58 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf1.py")) 59 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf1.py"))
59 self.__check_types(cfg) 60 self.__check_types(cfg)
60 61
61 def test03_yaml_types(self): 62 def test03_yaml_types(self):
62 with open(os.path.join(TESTDATADIR, "conf1.yml"), "rt") as f: 63 with io.open(os.path.join(TESTDATADIR, "conf1.yml"), "rt",
64 encoding="utf-8") as f:
63 cfg = configmix.yaml.safe_load(f) 65 cfg = configmix.yaml.safe_load(f)
64 self.__check_types(cfg) 66 self.__check_types(cfg)
65 67
66 def test04_py_export_all(self): 68 def test04_py_export_all(self):
67 # When __all__ is given only it's keys are exported 69 # When __all__ is given only it's keys are exported
84 def test07_py_tree(self): 86 def test07_py_tree(self):
85 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf10.py")) 87 cfg = configmix.py.load(os.path.join(TESTDATADIR, "conf10.py"))
86 self.__check_tree(cfg) 88 self.__check_tree(cfg)
87 89
88 def test08_yaml_tree(self): 90 def test08_yaml_tree(self):
89 with open(os.path.join(TESTDATADIR, "conf10.yml"), "rt") as f: 91 with io.open(os.path.join(TESTDATADIR, "conf10.yml"), "rt",
92 encoding="utf-8") as f:
90 cfg = configmix.yaml.safe_load(f) 93 cfg = configmix.yaml.safe_load(f)
91 self.__check_tree(cfg) 94 self.__check_tree(cfg)
92 95
93 96
94 class _T02MixinLoadAndMerge: 97 class _T02MixinLoadAndMerge: