Exemplo n.º 1
0
    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': [],
                }
            )
Exemplo n.º 2
0
    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': [],
                }
            )
Exemplo n.º 3
0
    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': [],
                }
            )
Exemplo n.º 4
0
 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()
Exemplo n.º 5
0
    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"})
Exemplo n.º 6
0
 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__
Exemplo n.º 7
0
    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')
Exemplo n.º 8
0
    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")
Exemplo n.º 9
0
 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__
Exemplo n.º 10
0
    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'
        )
Exemplo n.º 11
0
    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')
Exemplo n.º 12
0
    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"
                }
            )
Exemplo n.º 13
0
    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]
                }})
Exemplo n.º 14
0
    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'
        )
Exemplo n.º 15
0
    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]
                    }
                }
            )
Exemplo n.º 16
0
    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"
            )
Exemplo n.º 17
0
    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]
                    }
                })
Exemplo n.º 18
0
    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"
                    }
                }
            )
Exemplo n.º 19
0
    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]
                    }
                }
            )
Exemplo n.º 20
0
    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': [],
                }
            )
Exemplo n.º 21
0
    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"
                    }
                })