From 64ea3bd660e67318eea2762e4723d3f2d952cc0d Mon Sep 17 00:00:00 2001 From: Satoru SATOH Date: Fri, 13 Mar 2015 15:47:33 +0900 Subject: [PATCH] add test cases of template support of cli frontend --- anyconfig/tests/cli.py | 56 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/anyconfig/tests/cli.py b/anyconfig/tests/cli.py index 4dabc883..39472fd5 100644 --- a/anyconfig/tests/cli.py +++ b/anyconfig/tests/cli.py @@ -2,8 +2,9 @@ # Copyright (C) 2013 Satoru SATOH # License: MIT # -import anyconfig.cli as T +import anyconfig.cli as TT import anyconfig.api as A +import anyconfig.template as AT import anyconfig.tests.common as C import os @@ -33,7 +34,7 @@ def tearDown(self): def run_and_check_exit_code(self, args=[], code=0, _not=False): try: - T.main(["dummy"] + args) + TT.main(["dummy"] + args) except SystemExit as e: if _not: self.assertNotEquals(e.code, code) @@ -61,7 +62,7 @@ def test_30_single_input(self): A.dump(a, input) self.assertTrue(os.path.exists(input)) - T.main(["dummy", "-o", output, input]) + TT.main(["dummy", "-o", output, input]) self.assertTrue(os.path.exists(output)) def test_32_single_input_w_get_option(self): @@ -73,7 +74,7 @@ def test_32_single_input_w_get_option(self): A.dump(d, input) self.assertTrue(os.path.exists(input)) - T.main(["dummy", "-o", output, "--get", "a.b", input]) + TT.main(["dummy", "-o", output, "--get", "a.b", input]) self.assertTrue(os.path.exists(output)) x = A.load(output) @@ -88,7 +89,7 @@ def test_34_single_input_w_set_option(self): A.dump(d, input) self.assertTrue(os.path.exists(input)) - T.main(["dummy", "-o", output, "--set", "a.b.d=E", input]) + TT.main(["dummy", "-o", output, "--set", "a.b.d=E", input]) self.assertTrue(os.path.exists(output)) ref = d.copy() @@ -102,7 +103,7 @@ def test_36_single_input__ignore_missing(self): 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", + TT.main(["dummy", "-O", "json", "--ignore-missing", input]) def test_40_multiple_inputs(self): @@ -122,7 +123,7 @@ def test_40_multiple_inputs(self): A.dump(xs[i], input) self.assertTrue(os.path.exists(input)) - T.main(["dummy", "-o", output] + inputs) + TT.main(["dummy", "-o", output] + inputs) self.assertTrue(os.path.exists(output)) def test_50_single_input__w_arg_option(self): @@ -134,7 +135,7 @@ def test_50_single_input__w_arg_option(self): A.dump(a, input) self.assertTrue(os.path.exists(input)) - T.main(["dummy", "-o", output, "-A", "a:10;name:x;d:3,4", input]) + TT.main(["dummy", "-o", output, "-A", "a:10;name:x;d:3,4", input]) self.assertTrue(os.path.exists(output)) x = A.load(output) @@ -161,4 +162,43 @@ def test_62_output_wo_output_option_and_otype_w_itype(self): self.run_and_check_exit_code(["--itype", "json", input], 0) + def test_70_multi_inputs__w_template(self): + if not AT.TEMPLATE_SUPPORT: + 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", "-o", output, + os.path.join(inputsdir, "*.yml")]) + self.assertTrue(os.path.exists(output)) + + def test_72_single_input__no_template(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)) + + TT.main(["dummy", "--no-template", "-o", output, input]) + self.assertTrue(os.path.exists(output)) + # vim:sw=4:ts=4:et: