示例#1
0
    def test_40_multi_load__templates(self):
        if not anyconfig.template.SUPPORTED:
            return

        a = dict(a=1, b=dict(b=[0, 1], c="C"), name="a")
        b = dict(a=2, b=dict(b=[1, 2, 3, 4, 5], d="D"))

        ma = TT.to_container(a, ac_merge=TT.MS_DICTS)
        ma.update(b)

        a_path = os.path.join(self.workdir, "a.yml")
        b_path = os.path.join(self.workdir, "b.yml")
        g_path = os.path.join(self.workdir, "*.yml")

        open(a_path, 'w').write(CNF_TMPL_1)
        open(b_path, 'w').write(CNF_TMPL_2)

        a0 = TT.multi_load(g_path, ac_merge=TT.MS_DICTS, ac_template=True,
                           ac_context=ma)
        a02 = TT.multi_load([g_path, b_path], ac_merge=TT.MS_DICTS,
                            ac_template=True, ac_context=ma)

        self.assertEqual(a0["name"], a["name"])
        self.assertEqual(a0["a"], b["a"])
        self.assertEqual(a0["b"]["b"], b["b"]["b"])
        self.assertEqual(a0["b"]["c"], a["b"]["c"])
        self.assertEqual(a0["b"]["d"], b["b"]["d"])

        self.assertEqual(a02["name"], a["name"])
        self.assertEqual(a02["a"], b["a"])
        self.assertEqual(a02["b"]["b"], b["b"]["b"])
        self.assertEqual(a02["b"]["c"], a["b"]["c"])
        self.assertEqual(a02["b"]["d"], b["b"]["d"])
示例#2
0
def main(argv=None):
    """
    :param argv: Argument list to parse or None (sys.argv will be set).
    """
    (parser, options, args) = parse_args(argv=argv)
    API.LOGGER.setLevel(to_log_level(options.loglevel))

    _check_options_and_args(parser, options, args)

    cnf = API.to_container(os.environ.copy() if options.env else {})
    diff = API.load(args, options.itype,
                    ignore_missing=options.ignore_missing,
                    ac_merge=options.merge, ac_template=options.template,
                    ac_schema=options.schema)

    _exit_if_load_failure(diff, "Failed to load: args=%s" % ", ".join(args))
    cnf.update(diff)

    if options.args:
        diff = anyconfig.parser.parse(options.args)
        cnf.update(diff)

    _exit_if_only_to_validate(options.validate)

    if options.gen_schema:
        cnf = API.gen_schema(cnf)

    if options.get:
        cnf = _do_get(cnf, options.get)

    if options.set:
        (key, val) = options.set.split('=')
        API.set_(cnf, key, anyconfig.parser.parse(val))

    _output_result(cnf, options.output, options.otype, args[0], options.itype)
示例#3
0
    def test_34_load__ignore_missing(self):
        null_cntnr = TT.to_container()
        cpath = os.path.join(os.curdir, "conf_file_should_not_exist")
        assert not os.path.exists(cpath)

        self.assertEqual(
            TT.load([cpath], ac_parser="ini", ignore_missing=True), null_cntnr)
示例#4
0
    def test_14_single_load__ignore_missing(self):
        null_cntnr = TT.to_container()
        cpath = os.path.join(os.curdir, "conf_file_should_not_exist")
        assert not os.path.exists(cpath)

        self.assertEqual(TT.single_load(cpath, "ini", ignore_missing=True),
                         null_cntnr)
示例#5
0
    def test_30_multi_load__ignore_missing(self):
        null_cntnr = TT.to_container()
        cpath = os.path.join(os.curdir, "conf_file_should_not_exist")
        assert not os.path.exists(cpath)

        self.assertEqual(TT.multi_load([cpath], ac_parser="ini",
                                       ignore_missing=True),
                         null_cntnr)
示例#6
0
def main(argv=None):
    """
    :param argv: Argument list to parse or None (sys.argv will be set).
    """
    (parser, options, args) = parse_args(argv=argv)
    API.LOGGER.setLevel(to_log_level(options.loglevel))

    _check_options_and_args(parser, options, args)

    cnf = API.to_container(os.environ.copy() if options.env else {})
    diff = API.load(args,
                    options.itype,
                    ignore_missing=options.ignore_missing,
                    ac_merge=options.merge,
                    ac_template=options.template,
                    ac_schema=options.schema)

    _exit_if_load_failure(diff, "Failed to load: args=%s" % ", ".join(args))
    cnf.update(diff)

    if options.args:
        diff = anyconfig.parser.parse(options.args)
        cnf.update(diff)

    _exit_if_only_to_validate(options.validate)

    if options.gen_schema:
        cnf = API.gen_schema(cnf)

    if options.get:
        cnf = _do_get(cnf, options.get)

    if options.set:
        (key, val) = options.set.split('=')
        API.set_(cnf, key, anyconfig.parser.parse(val))

    _output_result(cnf, options.output, options.otype, args[0], options.itype)
示例#7
0
    def test_40_multi_load__templates(self):
        if not anyconfig.template.SUPPORTED:
            return

        a = dict(a=1, b=dict(b=[0, 1], c="C"), name="a")
        b = dict(a=2, b=dict(b=[1, 2, 3, 4, 5], d="D"))

        ma = TT.to_container(a, ac_merge=TT.MS_DICTS)
        ma.update(b)

        a_path = os.path.join(self.workdir, "a.yml")
        b_path = os.path.join(self.workdir, "b.yml")
        g_path = os.path.join(self.workdir, "*.yml")

        open(a_path, 'w').write(CNF_TMPL_1)
        open(b_path, 'w').write(CNF_TMPL_2)

        a0 = TT.multi_load(g_path,
                           ac_merge=TT.MS_DICTS,
                           ac_template=True,
                           ac_context=ma)
        a02 = TT.multi_load([g_path, b_path],
                            ac_merge=TT.MS_DICTS,
                            ac_template=True,
                            ac_context=ma)

        self.assertEqual(a0["name"], a["name"])
        self.assertEqual(a0["a"], b["a"])
        self.assertEqual(a0["b"]["b"], b["b"]["b"])
        self.assertEqual(a0["b"]["c"], a["b"]["c"])
        self.assertEqual(a0["b"]["d"], b["b"]["d"])

        self.assertEqual(a02["name"], a["name"])
        self.assertEqual(a02["a"], b["a"])
        self.assertEqual(a02["b"]["b"], b["b"]["b"])
        self.assertEqual(a02["b"]["c"], a["b"]["c"])
        self.assertEqual(a02["b"]["d"], b["b"]["d"])
示例#8
0
 def test_15_multi_load__empty_path_list(self):
     self.assertEqual(TT.multi_load([]), TT.to_container())
示例#9
0
 def test_15_multi_load__empty_path_list(self):
     self.assertEqual(TT.multi_load([]), TT.to_container())