def test_update(self): from c2c.template import main sys.argv = [ '', '--vars', 'c2c/tests/update.yaml', '--get-config', 'config4.yaml', 'obj' ] main() with open('config4.yaml') as config: self.assertEquals( yaml.safe_load(config.read()), { 'vars': { 'obj': { 'v1': 1, 'v2': 5, 'v3': [1, 2, 3, 3, 4, 5] } }, 'environment': [], 'interpreted': {}, 'no_interpreted': [], 'postprocess': [], } )
def test_path(self): from c2c.template import main sys.argv = [ "", "--vars", "c2c/tests/path.yaml", "--get-config", "config3.yaml", "path" ] main() with open("config3.yaml") as config: self.assertEquals( yaml.safe_load(config.read()), { "vars": { "path": { "var_interpreted": 4, "facter_json": {"osfamily": "Debian"}, "facter_yaml": {"osfamily": "Debian"}, "pi": "3.14" } }, 'environment': [], 'interpreted': {}, 'no_interpreted': [], 'postprocess': [], } )
def test_gen_config_with_cache(self): from c2c.template import main sys.argv = [ '', '--vars', 'c2c/tests/vars.yaml', '--get-cache', 'cache.yaml', ] main() sys.argv = [ '', '--cache', 'cache.yaml', '--get-config', 'config1.yaml', 'var_interpreted', 'var1', 'obj' ] main() with open('config1.yaml') as config: self.assertEquals( yaml.safe_load(config.read()), { 'vars': { 'var_interpreted': 4, 'var1': 'first', 'obj': { 'v1': 1, 'v2': '2', 'v3': [1, 2, 3] } }, 'environment': [], 'interpreted': {}, 'no_interpreted': [], 'postprocess': [], } )
def test_get_config_wrong(self): from c2c.template import main sys.argv = [ '', '--vars', 'c2c/tests/vars.yaml', '--get-config', 'config2.yaml', 'wrong' ] with self.assertRaises(SystemExit): main()
def test_recursiveint(self): from c2c.template import main sys.argv = [ "", "--vars", "c2c/tests/recursive_int.yaml", "--get-config", "config.yaml", "3third" ] main() with open("config.yaml") as config: self.assertEquals(yaml.load(config.read()), {"3third": "123"})
def test_get_var(self): from c2c.template import main sys.argv = [ '', '--vars', 'c2c/tests/vars.yaml', '--get-var', 'var_interpreted', 'VAR_1=var1' ] sys.stdout = StringIO() main() self.assertEquals(sys.stdout.getvalue(), "VAR_INTERPRETED=4\n" "VAR_1='first'\n") sys.stdout = sys.__stdout__
def test_mako(self): from c2c.template import main sys.argv = [ '', '--engine', 'mako', '--vars', 'c2c/tests/vars.yaml', '--files', 'c2c/tests/mako.mako' ] main() self.assertEquals( open('c2c/tests/mako', 'r').read(), 'var1: first, var2: second\n' 'var3: first, second, third\n' 'var_interpreted: 4\n')
def test_builder(self): from c2c.template import main sys.argv = [ '', '--vars', 'c2c/tests/builder_vars.yaml', '--files-builder', 'c2c/tests/builder.jinja', '{name}.txt', 'iter' ] main() with open('aa.txt') as test: self.assertEquals(test.read(), "var1: first\nvar2: second") with open('bb.txt') as test: self.assertEquals(test.read(), "var1: first\nvar2: 2")
def test_get_var(self): from c2c.template import main sys.argv = [ '', '--vars', 'c2c/tests/vars.yaml', '--get-var', 'var_interpreted', 'VAR_1=var1' ] sys.stdout = StringIO() main() self.assertEquals( sys.stdout.getvalue(), "VAR_INTERPRETED=4\n" "VAR_1='first'\n" ) sys.stdout = sys.__stdout__
def test_template(self): from c2c.template import main sys.argv = [ '', '--engine', 'template', '--vars', 'c2c/tests/vars.yaml', '--files', 'c2c/tests/template.in' ] main() self.assertEquals( open('c2c/tests/template', 'r').read(), 'var1: first, var2: second\n' 'var3: first, second, third\n' 'var_interpreted: 4\n' )
def test_jinja(self): from c2c.template import main sys.argv = [ '', '--engine', 'jinja', '--vars', 'c2c/tests/vars.yaml', '--files', 'c2c/tests/jinja.jinja' ] main() self.assertEquals( open('c2c/tests/jinja', 'r').read(), 'var1: first, var2: second\n' 'var3: first, second, third\n' 'var_interpreted: 4\n' 'JSON kernel: Linux\n' 'YAML kernel: Linux\n' 'pi: 3.14\n')
def test_recursiveint(self): from c2c.template import main sys.argv = [ "", "--vars", "c2c/tests/recursive_int.yaml", "--get-config", "config.yaml", "3third" ] main() with open("config.yaml") as config: self.assertEquals( yaml.load(config.read()), { "3third": "123" } )
def test_update(self): from c2c.template import main sys.argv = [ '', '--vars', 'c2c/tests/update.yaml', '--get-config', 'config.yaml', 'obj' ] main() with open('config.yaml') as config: self.assertEquals( yaml.load(config.read()), {'obj': { 'v1': 1, 'v2': 5, 'v3': [1, 2, 3, 3, 4, 5] }})
def test_jinja(self): from c2c.template import main sys.argv = [ '', '--engine', 'jinja', '--vars', 'c2c/tests/vars.yaml', '--files', 'c2c/tests/jinja.jinja' ] main() self.assertEquals( open('c2c/tests/jinja', 'r').read(), 'var1: first, var2: second\n' 'var3: first, second, third\n' 'var_interpreted: 4\n' 'JSON kernel: Linux\n' 'YAML kernel: Linux\n' 'pi: 3.14\n' )
def test_update(self): from c2c.template import main sys.argv = [ '', '--vars', 'c2c/tests/update.yaml', '--get-config', 'config.yaml', 'obj' ] main() with open('config.yaml') as config: self.assertEquals( yaml.load(config.read()), { 'obj': { 'v1': 1, 'v2': 5, 'v3': [1, 2, 3, 3, 4, 5] } } )
def test_builder(self): from c2c.template import main sys.argv = [ '', '--vars', 'c2c/tests/builder_vars.yaml', '--files-builder', 'c2c/tests/builder.jinja', '{name}.txt', 'iter' ] main() with open('aa.txt') as test: self.assertEquals( test.read(), "var1: first\nvar2: second" ) with open('bb.txt') as test: self.assertEquals( test.read(), "var1: first\nvar2: 2" )
def test_get_config(self): from c2c.template import main sys.argv = [ '', '--vars', 'c2c/tests/vars.yaml', '--get-config', 'config.yaml', 'var_interpreted', 'var1', 'obj' ] main() with open('config.yaml') as config: self.assertEquals( yaml.load(config.read()), { 'var_interpreted': 4, 'var1': 'first', 'obj': { 'v1': 1, 'v2': '2', 'v3': [1, 2, 3] } })
def test_path(self): from c2c.template import main sys.argv = [ "", "--vars", "c2c/tests/path.yaml", "--get-config", "config.yaml", "path" ] main() with open("config.yaml") as config: self.assertEquals( yaml.load(config.read()), { "path": { "var_interpreted": 4, "facter_json": {"osfamily": "Debian"}, "facter_yaml": {"osfamily": "Debian"}, "pi": "3.14\n" } } )
def test_get_config(self): from c2c.template import main sys.argv = [ '', '--vars', 'c2c/tests/vars.yaml', '--get-config', 'config.yaml', 'var_interpreted', 'var1', 'obj' ] main() with open('config.yaml') as config: self.assertEquals( yaml.load(config.read()), { 'var_interpreted': 4, 'var1': 'first', 'obj': { 'v1': 1, 'v2': '2', 'v3': [1, 2, 3] } } )
def test_recursiveint(self): from c2c.template import main sys.argv = [ "", "--vars", "c2c/tests/recursive_int.yaml", "--get-config", "config6.yaml", "3third" ] main() with open("config6.yaml") as config: self.assertEquals( yaml.safe_load(config.read()), { 'vars': { "3third": "123" }, 'environment': [], 'interpreted': {}, 'no_interpreted': [], 'postprocess': [], } )
def test_path(self): from c2c.template import main sys.argv = [ "", "--vars", "c2c/tests/path.yaml", "--get-config", "config.yaml", "path" ] main() with open("config.yaml") as config: self.assertEquals( yaml.load(config.read()), { "path": { "var_interpreted": 4, "facter_json": { "osfamily": "Debian" }, "facter_yaml": { "osfamily": "Debian" }, "pi": "3.14\n" } })