# Path: tripleo_heat_templates/environment_generator.py
# _PARAM_FORMAT = u"""%(indent_space)s  # %(description)s
#   %(mandatory)s%(indent_space)s# Type: %(type)s
#   %(indent_space)s%(name)s:%(default)s
# """
# _STATIC_MESSAGE_START = (
#     '%(indent_space)s  # ******************************************************\n'
#     '%(indent_space)s  # Static parameters - these are values that must be\n'
#     '%(indent_space)s  # included in the environment but should not be changed.\n'
#     '%(indent_space)s  # ******************************************************\n'
#     )
# _STATIC_MESSAGE_END = ('%(indent_space)s  # *********************\n'
#                        '%(indent_space)s  # End static parameters\n'
#                        '%(indent_space)s  # *********************\n'
#                        )
# _FILE_HEADER = (
#     '# *******************************************************************\n'
#     '# This file was created automatically by the sample environment\n'
#     '# generator. Developers should use `tox -e genconfig` to update it.\n'
#     '# Users are recommended to make changes to a copy of the file instead\n'
#     '# of the original, if any customizations are needed.\n'
#     '# *******************************************************************\n'
#     )
# _PARAMETERS = "parameters"
# _PRIVATE_OVERRIDES = ['server', 'servers', 'NodeIndex']
# _HIDDEN_PARAMS = ['EndpointMap', 'RoleName', 'RoleParameters',
#                   'ServiceNetMap', 'ServiceData',
#                   ]
# def _initialize_params_dict(params_dict, k, v):
# def _create_output_dir(target_file):
# def _generate_environment(input_env, output_path, parent_env=None):
#     def write_sample_entry(f, name, value, indent_space_count=0):
#     def write_params_entry(f, parameter_defaults_tuple, static_defaults_tuple, indent_space_count):
# def generate_environments(config_path, output_path):
# def usage(exit_code=1):
# def main():


import io
import tempfile
import testscenarios
from unittest import mock
from oslotest import base
from tripleo_heat_templates import environment_generator
        cls.scenarios = testscenarios.multiply_scenarios(
            cls.content_scenarios)

    def test_generator(self):
        fake_input = io.StringIO(str(self.input_file))
        fake_template = io.StringIO(str(self.template))
        _, fake_output_path = tempfile.mkstemp()
        fake_output = open(fake_output_path, 'w')
        with mock.patch('tripleo_heat_templates.environment_generator.open',
                        create=True) as mock_open:
            mock_se = [fake_input, fake_template, fake_output]
            if 'files:' not in self.input_file:
                # No files were specified so that open call won't happen
                mock_se.remove(fake_template)
            if self.nested_output:
                _, fake_nested_output_path = tempfile.mkstemp()
                fake_nested_output = open(fake_nested_output_path, 'w')
                fake_template2 = io.StringIO(str(self.template))
                mock_se = [fake_input, fake_template, fake_output,
                           fake_template2, fake_nested_output]
            mock_open.side_effect = mock_se
            if not self.exception:
                environment_generator.generate_environments('ignored.yaml',
                                                            'environments')
            else:
                self.assertRaises(self.exception,
                                  environment_generator.generate_environments,
                                  'ignored.yaml',
                                  'environments')
                return

# Path: tripleo_heat_templates/environment_generator.py
# _PARAM_FORMAT = u"""%(indent_space)s  # %(description)s
#   %(mandatory)s%(indent_space)s# Type: %(type)s
#   %(indent_space)s%(name)s:%(default)s
# """
# _STATIC_MESSAGE_START = (
#     '%(indent_space)s  # ******************************************************\n'
#     '%(indent_space)s  # Static parameters - these are values that must be\n'
#     '%(indent_space)s  # included in the environment but should not be changed.\n'
#     '%(indent_space)s  # ******************************************************\n'
#     )
# _STATIC_MESSAGE_END = ('%(indent_space)s  # *********************\n'
#                        '%(indent_space)s  # End static parameters\n'
#                        '%(indent_space)s  # *********************\n'
#                        )
# _FILE_HEADER = (
#     '# *******************************************************************\n'
#     '# This file was created automatically by the sample environment\n'
#     '# generator. Developers should use `tox -e genconfig` to update it.\n'
#     '# Users are recommended to make changes to a copy of the file instead\n'
#     '# of the original, if any customizations are needed.\n'
#     '# *******************************************************************\n'
#     )
# _PARAMETERS = "parameters"
# _PRIVATE_OVERRIDES = ['server', 'servers', 'NodeIndex']
# _HIDDEN_PARAMS = ['EndpointMap', 'RoleName', 'RoleParameters',
#                   'ServiceNetMap', 'ServiceData',
#                   ]
# def _initialize_params_dict(params_dict, k, v):
# def _create_output_dir(target_file):
# def _generate_environment(input_env, output_path, parent_env=None):
#     def write_sample_entry(f, name, value, indent_space_count=0):
#     def write_params_entry(f, parameter_defaults_tuple, static_defaults_tuple, indent_space_count):
# def generate_environments(config_path, output_path):
# def usage(exit_code=1):
# def main():


# Path: tripleo_heat_templates/tests/test_environment_generator.py
import io
import tempfile
import testscenarios
from unittest import mock
from oslotest import base
from tripleo_heat_templates import environment_generator

        cls.scenarios = testscenarios.multiply_scenarios(
            cls.content_scenarios)

    def test_generator(self):
        fake_input = io.StringIO(str(self.input_file))
        fake_template = io.StringIO(str(self.template))
        _, fake_output_path = tempfile.mkstemp()
        fake_output = open(fake_output_path, 'w')
        with mock.patch('tripleo_heat_templates.environment_generator.open',
                        create=True) as mock_open:
            mock_se = [fake_input, fake_template, fake_output]
            if 'files:' not in self.input_file:
                # No files were specified so that open call won't happen
                mock_se.remove(fake_template)
            if self.nested_output:
                _, fake_nested_output_path = tempfile.mkstemp()
                fake_nested_output = open(fake_nested_output_path, 'w')
                fake_template2 = io.StringIO(str(self.template))
                mock_se = [fake_input, fake_template, fake_output,
                           fake_template2, fake_nested_output]
            mock_open.side_effect = mock_se
            if not self.exception:
                environment_generator.generate_environments('ignored.yaml',
                                                            'environments')
            else:
                self.assertRaises(self.exception,
                                  environment_generator.generate_environments,
                                  'ignored.yaml',
                                  'environments')
                return

        expected = environment_generator._FILE_HEADER + self.expected_output