def test_10_multi_load_w_validation_for_partial_single_config_files(self): cpaths = [os.path.join(resdir(), "00-00-cnf.json"), os.path.join(resdir(), "00-01-cnf.json"), os.path.join(resdir(), "00-02-cnf.json")] spath = os.path.join(resdir(), "00-scm.json") cnf = TT.multi_load(cpaths, ac_schema=spath) ref = TT.multi_load(cpaths) self.assert_dicts_equal(cnf, ref, ordered=False)
def test_18_single_load__templates(self): if not anyconfig.template.SUPPORTED: return a_path = os.path.join(resdir(), "30-00-cnf.json") a2_path = os.path.join(resdir(), "00-00-cnf.json") # Not a template cnf1 = TT.single_load(a_path, ac_template=True, ac_context=self.cnf) self.assertTrue(dicts_equal(self.cnf, cnf1), str(cnf1)) cnf2 = TT.single_load(a2_path, ac_template=True) self.assertEqual(cnf2["a"], 1)
def test_16_single_load__template(self): if not anyconfig.template.SUPPORTED: return cpath = os.path.join(resdir(), "30-00-template-cnf.json") cnf = TT.single_load(cpath, ac_template=True, ac_context=self.cnf) self.assert_dicts_equal(cnf, self.cnf) spath = os.path.join(resdir(), "30-00-template-cnf-ng-scm.json") # Validation should fail. cnf2 = TT.single_load(cpath, ac_template=True, ac_context=self.cnf, ac_schema=spath) self.assertTrue(cnf2 is None)
class Test_22_single_load(TestBase): a_path = os.path.join(resdir(), "00-cnf.json") cnf = CNF_1 pathlib = anyconfig.compat.pathlib def test_10__single_load(self): res = TT.single_load(self.a_path) self.assert_dicts_equal(res, self.cnf) def test_12__single_load__ac_parser(self): res = TT.single_load(self.a_path, ac_parser="json") self.assert_dicts_equal(res, self.cnf) def test_14__single_load__ac_parser_by_id(self): cid = anyconfig.backend.json.Parser.cid() res = TT.single_load(self.a_path, ac_parser=cid) self.assert_dicts_equal(res, self.cnf) def test_20__single_load__stream(self): res = TT.single_load(open(self.a_path), ac_parser="json") self.assert_dicts_equal(res, self.cnf) def test_30__single_load__pathlib(self): if self.pathlib: pobj = self.pathlib.Path(self.a_path) res = TT.single_load(pobj) self.assert_dicts_equal(res, self.cnf)
def test_50_multi_load__templates(self): if not anyconfig.template.SUPPORTED: return ctx = self.dic.copy() TT.merge(ctx, self.upd, ac_merge=TT.MS_DICTS) # a_path = os.path.join(resdir(), "30-00-template-cnf.json") b_path = os.path.join(resdir(), "30-10-template-cnf.json") g_path = os.path.join(resdir(), "30-*-template-cnf.json") opts = dict(ac_merge=TT.MS_DICTS, ac_template=True, ac_context=ctx) try: res0 = TT.multi_load(g_path, **opts) res1 = TT.multi_load([g_path, b_path], **opts) except (TT.UnknownProcessorTypeError, TT.UnknownFileTypeError): return self.assert_dicts_equal(res0, self.exp) self.assert_dicts_equal(res1, self.exp)
# License: MIT # # pylint: disable=missing-docstring, invalid-name from __future__ import absolute_import import os.path import unittest import anyconfig.backend.json import anyconfig.backends as TT import anyconfig.ioinfo import tests.common as TC from anyconfig.compat import pathlib from anyconfig.globals import (UnknownProcessorTypeError, UnknownFileTypeError) CNF_PATH = os.path.join(TC.resdir(), "00-cnf.json") class Test(unittest.TestCase): def setUp(self): self.psrs = TT.Parsers() def test_10_list_types(self): types = self.psrs.list_types() self.assertTrue(isinstance(types, list)) self.assertTrue(bool(list)) # check it's not empty. def test_20_find_by_type_or_id__ng_cases(self): self.assertRaises(ValueError, self.psrs.find_by_type_or_id, None) self.assertRaises(UnknownProcessorTypeError,
import os.path import unittest import anyconfig.compat import anyconfig.ioinfo as TT import anyconfig.utils from anyconfig.globals import ( IOI_PATH_STR, IOI_PATH_OBJ, IOI_STREAM, ) import tests.common as TC IPATH_0 = os.path.join(TC.resdir(), "00-cnf.json") IPATH_0_FULL = anyconfig.utils.normpath(IPATH_0) IPATH_0_EXT = anyconfig.utils.get_file_extension(IPATH_0) class Test_10_inspect_io_obj(unittest.TestCase): def test_10_path_str(self): self.assertEqual(TT.inspect_io_obj(IPATH_0), (IOI_PATH_STR, IPATH_0_FULL, open, IPATH_0_EXT)) def test_20_stream(self): self.assertEqual( TT.inspect_io_obj(open(IPATH_0)), (IOI_STREAM, IPATH_0_FULL, anyconfig.utils.noop, IPATH_0_EXT)) def test_30_path_obj(self):
import os.path import os import unittest import anyconfig.compat import anyconfig.ioinfo as TT import anyconfig.utils from anyconfig.globals import ( IOI_PATH_STR, IOI_PATH_OBJ, IOI_STREAM, ) import tests.common as TC IPATH_0 = os.path.join(TC.resdir(), "00-cnf.json") IPATH_0_FULL = anyconfig.utils.normpath(IPATH_0) IPATH_0_EXT = anyconfig.utils.get_file_extension(IPATH_0) class Test_10_inspect_io_obj(unittest.TestCase): def test_10_path_str(self): self.assertEqual(TT.inspect_io_obj(IPATH_0), (IOI_PATH_STR, IPATH_0_FULL, open, IPATH_0_EXT)) def test_20_stream(self): self.assertEqual(TT.inspect_io_obj(open(IPATH_0)), (IOI_STREAM, IPATH_0_FULL, anyconfig.utils.noop, IPATH_0_EXT))
try: import anyconfig.backend.yaml.pyyaml as PYYAML except ImportError: PYYAML = None import anyconfig.backends as TT import anyconfig.ioinfo import tests.common as TC from anyconfig.compat import pathlib from anyconfig.globals import ( UnknownProcessorTypeError, UnknownFileTypeError ) CNF_PATH = os.path.join(TC.resdir(), "00-cnf.json") class Test(unittest.TestCase): def setUp(self): self.psrs = TT.Parsers() def test_10_json_parsers(self): jpsrs = self.psrs.findall(None, forced_type="json") self.assertTrue(isinstance(jpsrs[0], JSON.Parser)) def test_12_yaml_parsers(self): if PYYAML: ypsrs = self.psrs.findall(None, forced_type="yaml") self.assertTrue(isinstance(ypsrs[0], PYYAML.Parser))