Skip to content

Commit

Permalink
add test cases of template support of cli frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
ssato committed Mar 13, 2015
1 parent d8bb088 commit 64ea3bd
Showing 1 changed file with 48 additions and 8 deletions.
56 changes: 48 additions & 8 deletions anyconfig/tests/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# Copyright (C) 2013 Satoru SATOH <ssato @ redhat.com>
# 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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -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:

0 comments on commit 64ea3bd

Please sign in to comment.