Ejemplo n.º 1
0
    def test_36_single_input__ignore_missing(self):
        # null_cntnr = A.container()
        input = os.path.join(os.curdir, "conf_file_should_not_exist.json")
        assert not os.path.exists(input)

        T.main(["dummy", "-O", "json", "--ignore-missing",
                input])
Ejemplo n.º 2
0
 def run_and_check_exit_code(self, args=None, code=0, _not=False,
                             exc_cls=SystemExit):
     try:
         TT.main(["dummy", "--silent"] + ([] if args is None else args))
     except exc_cls as exc:
         ecode = getattr(exc, "code", 1)
         (self.assertNotEqual if _not else self.assertEqual)(ecode, code)
Ejemplo n.º 3
0
 def run_and_check_exit_code(self, args=None, code=0, _not=False,
                             exc_cls=SystemExit):
     try:
         TT.main(["dummy"] + ([] if args is None else args))
     except exc_cls as exc:
         ecode = getattr(exc, "code", 1)
         (self.assertNotEqual if _not else self.assertEqual)(ecode, code)
Ejemplo n.º 4
0
    def test_70_multi_inputs__w_template(self):
        if not anyconfig.template.SUPPORTED:
            return

        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"))

        inputsdir = os.path.join(self.workdir, "in")
        os.makedirs(inputsdir)

        A.dump(a, os.path.join(inputsdir, "a0.yml"))
        open(os.path.join(inputsdir, "a1.yml"), "w").write(
            """\
name: {{ name }}
a: {{ a }}
b:
    b:
        {% for x in b.b -%}
        - {{ x }}
        {% endfor %}
    c: {{ b.c }}
"""
        )

        output = os.path.join(self.workdir, "b.json")

        TT.main(["dummy", "--template", "-o", output, os.path.join(inputsdir, "*.yml")])
        self.assertTrue(os.path.exists(output))
Ejemplo n.º 5
0
 def run_and_check_exit_code(self, args=[], code=0, _not=False):
     try:
         T.main(["dummy"] + args)
     except SystemExit as e:
         if _not:
             self.assertNotEquals(e.code, code)
         else:
             self.assertEquals(e.code, code)
Ejemplo n.º 6
0
 def run_and_check_exit_code(self, args=[], code=0, _not=False):
     try:
         T.main(["dummy"] + args)
     except SystemExit as e:
         if _not:
             self.assertNotEquals(e.code, code)
         else:
             self.assertEquals(e.code, code)
Ejemplo n.º 7
0
    def test_82_no_itype_and_otype(self):
        raised = False
        try:
            TT.main(["dummy", "-o", "out.txt", "in.txt"])
            sys.exit(-1)
        except RuntimeError:
            raised = True

        self.assertTrue(raised)
Ejemplo n.º 8
0
    def test_80_w_extra_opts(self):
        infile = os.path.join(tests.common.resdir(), "00-00-cnf.json")
        output = os.path.join(self.workdir, "out.json")
        ref = os.path.join(tests.common.resdir(), "00-00-cnf_indented.json")

        TT.main(["dummy", "-o", output, "--extra-opts", "indent:2", infile])
        self.assertTrue(os.path.exists(output))
        self.assertEqual(open(output).read().strip().rstrip(),
                         open(ref).read().strip().rstrip())
Ejemplo n.º 9
0
    def test_30_w_template(self):
        if not anyconfig.template.SUPPORTED:
            return

        infile = os.path.join(tests.common.resdir(), "30-*-template-cnf.json")
        output = os.path.join(self.workdir, "output.json")

        TT.main(["dummy", "--template", "-o", output, infile])
        self.assertTrue(os.path.exists(output))
Ejemplo n.º 10
0
    def test_30_w_template(self):
        if not anyconfig.template.SUPPORTED:
            return

        infile = os.path.join(tests.common.resdir(), "30-*-template-cnf.json")
        output = os.path.join(self.workdir, "output.json")

        TT.main(["dummy", "--template", "-o", output, infile])
        self.assertTrue(os.path.exists(output))
Ejemplo n.º 11
0
    def test_80_w_extra_opts(self):
        infile = os.path.join(tests.common.resdir(), "00-00-cnf.json")
        output = os.path.join(self.workdir, "out.json")
        ref = os.path.join(tests.common.resdir(), "00-00-cnf_indented.json")

        TT.main(["dummy", "-o", output, "--extra-opts", "indent:2", infile])
        self.assertTrue(os.path.exists(output))
        self.assertEqual(open(output).read().strip().rstrip(),
                         open(ref).read().strip().rstrip())
Ejemplo n.º 12
0
    def test_30_w_template(self):
        if not anyconfig.template.SUPPORTED:
            return

        curdir = anyconfig.tests.common.selfdir()

        infile = os.path.join(curdir, "*template-c*.yml")
        output = os.path.join(self.workdir, "output.yml")

        TT.main(["dummy", "--silent", "--template", "-o", output, infile])
Ejemplo n.º 13
0
    def test_30_w_template(self):
        if not anyconfig.template.SUPPORTED:
            return

        curdir = tests.common.selfdir()

        infile = os.path.join(curdir, "*template-c*.yml")
        output = os.path.join(self.workdir, "output.yml")

        TT.main(["dummy", "--silent", "--template", "-o", output, infile])
Ejemplo n.º 14
0
    def test_80_no_out_dumper(self):
        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"), d=[1, 2])
        input = os.path.join(self.workdir, "a.json")
        A.dump(a, input)

        try:
            TT.main(["dummy", "-o", "out.txt", input])
            sys.exit(-1)
        except RuntimeError:
            pass
Ejemplo n.º 15
0
    def test_74_multi_inputs__w_template(self):
        if not anyconfig.template.SUPPORTED:
            return

        curdir = C.selfdir()

        infile = os.path.join(curdir, "*template-c*.yml")
        output = os.path.join(self.workdir, "output.yml")

        TT.main(["dummy", "--template", "-o", output, infile])
Ejemplo n.º 16
0
    def test_10(self):
        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"))

        infile = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        anyconfig.api.dump(a, infile)
        self.assertTrue(os.path.exists(infile))

        TT.main(["dummy", "--silent", "-o", output, infile])
        self.assertTrue(os.path.exists(output))
Ejemplo n.º 17
0
    def test_30_single_input(self):
        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"))

        input = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        A.dump(a, input)
        self.assertTrue(os.path.exists(input))

        T.main(["dummy", "-o", output, input])
        self.assertTrue(os.path.exists(output))
Ejemplo n.º 18
0
    def test_72_single_input__no_template(self):
        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"))

        infile = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        A.dump(a, infile)
        self.assertTrue(os.path.exists(infile))

        TT.main(["dummy", "-o", output, infile])
        self.assertTrue(os.path.exists(output))
Ejemplo n.º 19
0
    def test_30_single_input(self):
        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"))

        input = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        A.dump(a, input)
        self.assertTrue(os.path.exists(input))

        T.main(["dummy", "-o", output, input])
        self.assertTrue(os.path.exists(output))
Ejemplo n.º 20
0
    def test_10(self):
        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"))

        infile = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        anyconfig.api.dump(a, infile)
        self.assertTrue(os.path.exists(infile))

        TT.main(["dummy", "--silent", "-o", output, infile])
        self.assertTrue(os.path.exists(output))
Ejemplo n.º 21
0
    def test_40_no_inputs__w_env_option(self):
        infile = "/dev/null"
        output = os.path.join(self.workdir, "out.yml")

        if anyconfig.api.find_loader(infile, "yaml") is None:
            return

        TT.main(["dummy", "--silent", "--env", "-o", output, infile])
        data = anyconfig.api.load(output)

        for env_var, env_val in os.environ.items():
            self.assertTrue(env_var in data)
            self.assertEqual(env_val, os.environ[env_var])
Ejemplo n.º 22
0
    def test_90_no_inputs__w_env_option(self):
        infile = "/dev/null"
        output = os.path.join(self.workdir, "out.yml")

        if A.find_loader(infile, "yaml") is None:
            return

        TT.main(["dummy", "--env", "-o", output, infile])
        data = A.load(output)

        for env_var, env_val in os.environ.items():
            self.assertTrue(env_var in data)
            self.assertEquals(env_val, os.environ[env_var])
Ejemplo n.º 23
0
    def test_30_w_get_option(self):
        d = dict(name="a", a=dict(b=dict(c=[1, 2], d="C")))

        infile = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        anyconfig.api.dump(d, infile)
        self.assertTrue(os.path.exists(infile))

        TT.main(["dummy", "--silent", "-o", output, "--get", "a.b", infile])
        self.assertTrue(os.path.exists(output))

        x = anyconfig.api.load(output)
        self.assertEqual(x, d['a']['b'])
Ejemplo n.º 24
0
    def test_32_single_input_w_get_option(self):
        d = dict(name="a", a=dict(b=dict(c=[1, 2], d="C")))

        input = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        A.dump(d, input)
        self.assertTrue(os.path.exists(input))

        T.main(["dummy", "-o", output, "--get", "a.b", input])
        self.assertTrue(os.path.exists(output))

        x = A.load(output)
        self.assertEquals(x, d['a']['b'])
Ejemplo n.º 25
0
    def test_32_single_input_w_get_option(self):
        d = dict(name="a", a=dict(b=dict(c=[1, 2], d="C")))

        input = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        A.dump(d, input)
        self.assertTrue(os.path.exists(input))

        T.main(["dummy", "-o", output, "--get", "a.b", input])
        self.assertTrue(os.path.exists(output))

        x = A.load(output)
        self.assertEquals(x, d['a']['b'])
Ejemplo n.º 26
0
    def test_30_w_get_option(self):
        d = dict(name="a", a=dict(b=dict(c=[1, 2], d="C")))

        infile = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        anyconfig.api.dump(d, infile)
        self.assertTrue(os.path.exists(infile))

        TT.main(["dummy", "--silent", "-o", output, "--get", "a.b", infile])
        self.assertTrue(os.path.exists(output))

        x = anyconfig.api.load(output)
        self.assertEqual(x, d['a']['b'])
Ejemplo n.º 27
0
    def test_20_w_template(self):
        if not anyconfig.template.SUPPORTED:
            return

        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"))

        inputsdir = os.path.join(self.workdir, "in")
        os.makedirs(inputsdir)

        anyconfig.api.dump(a, os.path.join(inputsdir, "a0.yml"))
        open(os.path.join(inputsdir, "a1.yml"), 'w').write(CNF_TMPL_0)
        output = os.path.join(self.workdir, "b.json")

        TT.main(["dummy", "--silent", "--template", "-o", output,
                 os.path.join(inputsdir, "*.yml")])
        self.assertTrue(os.path.exists(output))
Ejemplo n.º 28
0
    def test_32_w_set_option(self):
        d = dict(name="a", a=dict(b=dict(c=[1, 2], d="C")))

        infile = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        anyconfig.api.dump(d, infile)
        self.assertTrue(os.path.exists(infile))

        TT.main(["dummy", "-q", "-o", output, "--set", "a.b.d=E", infile])
        self.assertTrue(os.path.exists(output))

        ref = d.copy()
        ref['a']['b']['d'] = 'E'

        x = anyconfig.api.load(output)
        self.assertEqual(x, ref)
Ejemplo n.º 29
0
    def test_40_ignore_missing(self):
        infile = os.path.join(os.curdir, "conf_file_should_not_exist.json")
        assert not os.path.exists(infile)

        self.assertFalse(
            TT.main([
                "dummy", "--silent", "-O", "json", "--ignore-missing", infile
            ]))
Ejemplo n.º 30
0
    def test_34_single_input_w_set_option(self):
        d = dict(name="a", a=dict(b=dict(c=[1, 2], d="C")))

        input = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        A.dump(d, input)
        self.assertTrue(os.path.exists(input))

        T.main(["dummy", "-o", output, "--set", "a.b.d=E", input])
        self.assertTrue(os.path.exists(output))

        ref = d.copy()
        ref['a']['b']['d'] = 'E'

        x = A.load(output)
        self.assertEquals(x, ref)
Ejemplo n.º 31
0
    def test_32_w_set_option(self):
        d = dict(name="a", a=dict(b=dict(c=[1, 2], d="C")))

        infile = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        anyconfig.api.dump(d, infile)
        self.assertTrue(os.path.exists(infile))

        TT.main(["dummy", "-q", "-o", output, "--set", "a.b.d=E", infile])
        self.assertTrue(os.path.exists(output))

        ref = d.copy()
        ref['a']['b']['d'] = 'E'

        x = anyconfig.api.load(output)
        self.assertEqual(x, ref)
Ejemplo n.º 32
0
    def test_34_single_input_w_set_option(self):
        d = dict(name="a", a=dict(b=dict(c=[1, 2], d="C")))

        input = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        A.dump(d, input)
        self.assertTrue(os.path.exists(input))

        T.main(["dummy", "-o", output, "--set", "a.b.d=E", input])
        self.assertTrue(os.path.exists(output))

        ref = d.copy()
        ref['a']['b']['d'] = 'E'

        x = A.load(output)
        self.assertEquals(x, ref)
Ejemplo n.º 33
0
    def test_40_multiple_inputs(self):
        xs = [dict(a=1), dict(b=dict(b=[1, 2], c="C"))]

        a = xs[0].copy()
        a.update(xs[1])

        output = os.path.join(self.workdir, "b.json")

        inputs = []
        for i in [0, 1]:
            infile = os.path.join(self.workdir, "a%d.json" % i)
            inputs.append(infile)

            A.dump(xs[i], infile)
            self.assertTrue(os.path.exists(infile))

        TT.main(["dummy", "-o", output] + inputs)
        self.assertTrue(os.path.exists(output))
Ejemplo n.º 34
0
    def test_20_w_template(self):
        if not anyconfig.template.SUPPORTED:
            return

        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"))

        inputsdir = os.path.join(self.workdir, "in")
        os.makedirs(inputsdir)

        anyconfig.api.dump(a, os.path.join(inputsdir, "a0.yml"))
        open(os.path.join(inputsdir, "a1.yml"), 'w').write(CNF_TMPL_0)
        output = os.path.join(self.workdir, "b.json")

        TT.main([
            "dummy", "--silent", "--template", "-o", output,
            os.path.join(inputsdir, "*.yml")
        ])
        self.assertTrue(os.path.exists(output))
Ejemplo n.º 35
0
    def test_10(self):
        xs = [dict(a=1, ),
              dict(b=dict(b=[1, 2], c="C")), ]

        a = xs[0].copy()
        a.update(xs[1])

        output = os.path.join(self.workdir, "b.json")

        inputs = []
        for i in [0, 1]:
            infile = os.path.join(self.workdir, "a%d.json" % i)
            inputs.append(infile)

            anyconfig.api.dump(xs[i], infile)
            self.assertTrue(os.path.exists(infile))

        TT.main(["dummy", "-o", output] + inputs)
        self.assertTrue(os.path.exists(output))
Ejemplo n.º 36
0
    def test_50_single_input__w_arg_option(self):
        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"), d=[1, 2])

        input = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        A.dump(a, input)
        self.assertTrue(os.path.exists(input))

        T.main(["dummy", "-o", output, "-A", "a:10;name:x;d:3,4", input])
        self.assertTrue(os.path.exists(output))

        x = A.load(output)

        self.assertNotEquals(a["name"], x["name"])
        self.assertNotEquals(a["a"], x["a"])
        self.assertNotEquals(a["d"], x["d"])

        self.assertEquals(x["name"], 'x')
        self.assertEquals(x["a"], 10)
        self.assertEquals(x["d"], [3, 4])
Ejemplo n.º 37
0
    def test_60_w_arg_option(self):
        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"), d=[1, 2])

        infile = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        anyconfig.api.dump(a, infile)
        self.assertTrue(os.path.exists(infile))

        TT.main(["dummy", "-o", output, "-A", "a:10;name:x;d:3,4", infile])
        self.assertTrue(os.path.exists(output))

        x = anyconfig.api.load(output)

        self.assertNotEqual(a["name"], x["name"])
        self.assertNotEqual(a["a"], x["a"])
        self.assertNotEqual(a["d"], x["d"])

        self.assertEqual(x["name"], 'x')
        self.assertEqual(x["a"], 10)
        self.assertEqual(x["d"], [3, 4])
Ejemplo n.º 38
0
    def test_50_single_input__w_arg_option(self):
        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"), d=[1, 2])

        input = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        A.dump(a, input)
        self.assertTrue(os.path.exists(input))

        T.main(["dummy", "-o", output, "-A", "a:10;name:x;d:3,4", input])
        self.assertTrue(os.path.exists(output))

        x = A.load(output)

        self.assertNotEquals(a["name"], x["name"])
        self.assertNotEquals(a["a"], x["a"])
        self.assertNotEquals(a["d"], x["d"])

        self.assertEquals(x["name"], 'x')
        self.assertEquals(x["a"], 10)
        self.assertEquals(x["d"], [3, 4])
Ejemplo n.º 39
0
    def test_60_w_arg_option(self):
        a = dict(name="a", a=1, b=dict(b=[1, 2], c="C"), d=[1, 2])

        infile = os.path.join(self.workdir, "a.json")
        output = os.path.join(self.workdir, "b.json")

        anyconfig.api.dump(a, infile)
        self.assertTrue(os.path.exists(infile))

        TT.main(["dummy", "--silent", "-o", output, "-A",
                 "a:10;name:x;d:3,4", infile])
        self.assertTrue(os.path.exists(output))

        x = anyconfig.api.load(output)

        self.assertNotEqual(a["name"], x["name"])
        self.assertNotEqual(a["a"], x["a"])
        self.assertNotEqual(a["d"], x["d"])

        self.assertEqual(x["name"], 'x')
        self.assertEqual(x["a"], 10)
        self.assertEqual(x["d"], [3, 4])
Ejemplo n.º 40
0
def _run(*args):
    return TT.main(["dummy"] + [str(a) for a in args])
Ejemplo n.º 41
0
 def test_82_no_itype_and_otype(self):
     try:
         TT.main(["dummy", "-o", "out.txt", "in.txt"])
         sys.exit(-1)
     except RuntimeError:
         pass
Ejemplo n.º 42
0
def _run(*args):
    TT.main(["dummy", "--silent"] + list(args))
Ejemplo n.º 43
0
def _run(*args):
    TT.main(["dummy", "--silent"] + list(args))
Ejemplo n.º 44
0
    def test_36_single_input__ignore_missing(self):
        infile = os.path.join(os.curdir, "conf_file_should_not_exist.json")
        assert not os.path.exists(infile)

        self.assertFalse(TT.main(["dummy", "-O", "json", "--ignore-missing", infile]))
Ejemplo n.º 45
0
def _run(*args):
    TT.main(["dummy"] + list(args))
Ejemplo n.º 46
0
    def test_36_single_input__ignore_missing(self):
        # null_cntnr = A.container()
        input = os.path.join(os.curdir, "conf_file_should_not_exist.json")
        assert not os.path.exists(input)

        T.main(["dummy", "-O", "json", "--ignore-missing", input])
Ejemplo n.º 47
0
def _run(*args):
    TT.main(["dummy"] + list(args))