示例#1
0
    def test_summarized_option_order_single_ns(self):

        config = [('namespace1', [('alpha', self.opts)])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter,
                                   'alpha',
                                   groups.pop('alpha'),
                                   summarize=True)
        expected = '''[alpha]

#
# From namespace1
#

# This is the summary line for a config option. For more information,
# refer to the documentation. (string value)
#foo = fred

# This is a less carefully formatted configuration
# option, where the author has not broken their description into a
# brief
# summary line and larger description. Watch this person's commit
# messages! (string value)
#bar = <None>
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
    def test_required_option_order_single_ns(self):

        config = [("namespace1", [
                   ("alpha", self.opts)])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter, 'alpha',
                                   groups.pop('alpha'), True)
        expected = '''[alpha]

#
# From namespace1
#

# bar option (string value)
bar = <None>

# bars foo (string value)
bars = <None>
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
示例#3
0
    def test_summarized_option_order_single_ns(self):

        config = [('namespace1', [('alpha', self.opts)])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter,
                                   'alpha',
                                   groups.pop('alpha'),
                                   summarize=True)
        expected = '''[alpha]

#
# From namespace1
#

# This is the summary line for a config option. For more information,
# refer to the documentation. (string value)
#foo = fred

# This is a less carefully formatted configuration
# option, where the author has not broken their description into a
# brief
# summary line and larger description. Watch this person's commit
# messages! (string value)
#bar = <None>
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
示例#4
0
    def test_required_option_order_single_ns(self):

        config = [("namespace1", [("alpha", self.opts)])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter,
                                   'alpha',
                                   groups.pop('alpha'),
                                   minimal=True)
        expected = '''[alpha]

#
# From namespace1
#

# bar option (string value)
bar = <None>

# bars foo (string value)
bars = <None>
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
示例#5
0
 def test_do_not_include_message(self):
     out = moves.StringIO()
     opt = cfg.StrOpt('foo', help='foo option', mutable=False)
     gen = generator._OptFormatter(output_file=out)
     gen.format(opt, 'group1')
     result = out.getvalue()
     self.assertNotIn(
         'This option can be changed without restarting.',
         result,
     )
示例#6
0
 def test_do_not_include_message(self):
     out = moves.StringIO()
     opt = cfg.StrOpt('foo', help='foo option', mutable=False)
     gen = generator._OptFormatter(output_file=out)
     gen.format(opt, 'group1')
     result = out.getvalue()
     self.assertNotIn(
         'This option can be changed without restarting.',
         result,
     )
示例#7
0
文件: base.py 项目: fabrickit/fabkit
def genconfig(conf_file='fabfile.ini.sample'):
    conf_file_path = os.path.join(CONF._repo_dir, conf_file)
    output_file = open(conf_file_path, 'w')
    formatter = generator._OptFormatter(output_file=output_file, wrap_width=wrap_width)

    formatter.write("#\n# fabfile.ini\n#\n")
    for section, opts in list_opts:
        formatter.write("\n\n")
        formatter.write("[{0}]\n".format(section))
        for opt in opts:
            formatter.write("\n")
            formatter.format(opt)
示例#8
0
def genconfig(conf_file='fabfile.ini.sample'):
    conf_file_path = os.path.join(CONF._repo_dir, conf_file)
    output_file = open(conf_file_path, 'w')
    formatter = generator._OptFormatter(output_file=output_file,
                                        wrap_width=wrap_width)

    formatter.write("#\n# fabfile.ini\n#\n")
    for section, opts in list_opts:
        formatter.write("\n\n")
        formatter.write("[{0}]\n".format(section))
        for opt in opts:
            formatter.write("\n")
            formatter.format(opt)
示例#9
0
def save_config(config, snapshot_name, env_name=None):
    if env_name is None:
        env_name = 'config'
    test_config_path = os.path.join(
        settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name))

    with open(test_config_path, 'w') as output_file:
        formatter = generator._OptFormatter(output_file=output_file)
        for group, opts in list_current_opts(config):
            formatter.format_group(group)
            for opt in opts:
                formatter.format(opt, group, minimal=True)
                formatter.write('\n')
            formatter.write('\n')
示例#10
0
    def test_output_opts_empty_default(self):

        config = [("namespace1", [("alpha", [])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        f = open(tmp_file, 'w+')
        formatter = generator._OptFormatter(output_file=f)
        expected = '''[DEFAULT]
'''
        generator._output_opts(formatter, 'DEFAULT', groups.pop('DEFAULT'))
        f.close()
        content = open(tmp_file).read()
        self.assertEqual(expected, content)
示例#11
0
    def test_output_opts_empty_default(self):

        config = [("namespace1", [("alpha", [])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter, 'DEFAULT', groups.pop('DEFAULT'))
        expected = '''[DEFAULT]
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
示例#12
0
def save_config(config, snapshot_name, env_name=None):
    if env_name is None:
        env_name = 'config'
    test_config_path = os.path.join(
        settings.LOGS_DIR, '{0}_{1}.ini'.format(env_name, snapshot_name))

    with open(test_config_path, 'w') as output_file:
        formatter = generator._OptFormatter(output_file=output_file)
        for group, opts in list_current_opts(config):
            formatter.format_group(group)
            for opt in opts:
                formatter.format(opt, group, minimal=True)
                formatter.write('\n')
            formatter.write('\n')
示例#13
0
    def test_output_opts_empty_default(self):

        config = [("namespace1", [
                   ("alpha", [])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        f = open(tmp_file, 'w+')
        formatter = generator._OptFormatter(output_file=f)
        expected = '''[DEFAULT]
'''
        generator._output_opts(formatter, 'DEFAULT', groups.pop('DEFAULT'))
        f.close()
        content = open(tmp_file).read()
        self.assertEqual(expected, content)
示例#14
0
    def test_output_opts_empty_default(self):

        config = [("namespace1", [
                   ("alpha", [])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter, 'DEFAULT', groups.pop('DEFAULT'))
        expected = '''[DEFAULT]
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
示例#15
0
    def test_output_opts_group(self):

        config = [("namespace1", [("alpha", [self.opts[0]])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        expected = '''[alpha]

#
# From namespace1
#

# foo option (string value)
#foo = fred
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
示例#16
0
    def test_output_opts_group(self):

        config = [("namespace1", [("alpha", [self.opts[0]])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        f = open(tmp_file, 'w+')
        formatter = generator._OptFormatter(output_file=f)
        expected = '''[alpha]

#
# From namespace1
#

# foo option (string value)
#foo = fred
'''
        generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        f.close()
        content = open(tmp_file).read()
        self.assertEqual(expected, content)
示例#17
0
    def _test_output_default_list_opt_with_string_value(self, default):
        opt = cfg.ListOpt('list_opt', help='a list', default=default)
        config = [("namespace1", [
                   ("alpha", [opt])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        f = open(tmp_file, 'w+')
        formatter = generator._OptFormatter(output_file=f)
        expected = '''[alpha]

#
# From namespace1
#

# a list (list value)
#list_opt = %(default)s
''' % {'default': default}
        generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        f.close()
        content = open(tmp_file).read()
        self.assertEqual(expected, content)
示例#18
0
    def test_output_opts_group(self):

        config = [("namespace1", [
                   ("alpha", [self.opts[0]])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        f = open(tmp_file, 'w+')
        formatter = generator._OptFormatter(output_file=f)
        expected = '''[alpha]

#
# From namespace1
#

# foo option (string value)
#foo = fred
'''
        generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        f.close()
        content = open(tmp_file).read()
        self.assertEqual(expected, content)
示例#19
0
    def test_output_opts_group(self):

        config = [("namespace1", [
                   ("alpha", [self.opts[0]])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        expected = '''[alpha]

#
# From namespace1
#

# foo option (string value)
#foo = fred
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
示例#20
0
    def _test_output_default_list_opt_with_string_value(self, default):
        opt = cfg.ListOpt('list_opt', help='a list', default=default)
        config = [("namespace1", [
                   ("alpha", [opt])])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        f = open(tmp_file, 'w+')
        formatter = generator._OptFormatter(output_file=f)
        expected = '''[alpha]

#
# From namespace1
#

# a list (list value)
#list_opt = %(default)s
''' % {'default': default}
        generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        f.close()
        content = open(tmp_file).read()
        self.assertEqual(expected, content)
示例#21
0
    def test_advanced_option_order_single_ns(self):

        config = [("namespace1", [
                   ("alpha", self.opts)])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        expected = '''[alpha]

#
# From namespace1
#

# foo option (string value)
#foo = fred

# foobar (string value)
#foo_bar = <None>

# bar option (string value)
# Advanced Option: intended for advanced users and not used
# by the majority of users, and might have a significant
# effect on stability and/or performance.
#bar = <None>

# bars foo (boolean value)
# Advanced Option: intended for advanced users and not used
# by the majority of users, and might have a significant
# effect on stability and/or performance.
#bars = true
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)
示例#22
0
    def test_advanced_option_order_single_ns(self):

        config = [("namespace1", [
                   ("alpha", self.opts)])]
        groups = generator._get_groups(config)

        fd, tmp_file = tempfile.mkstemp()
        with open(tmp_file, 'w+') as f:
            formatter = generator._OptFormatter(output_file=f)
            generator._output_opts(formatter, 'alpha', groups.pop('alpha'))
        expected = '''[alpha]

#
# From namespace1
#

# foo option (string value)
#foo = fred

# foobar (string value)
#foo_bar = <None>

# bar option (string value)
# Advanced Option: intended for advanced users and not used
# by the majority of users, and might have a significant
# effect on stability and/or performance.
#bar = <None>

# bars foo (boolean value)
# Advanced Option: intended for advanced users and not used
# by the majority of users, and might have a significant
# effect on stability and/or performance.
#bars = true
'''
        with open(tmp_file, 'r') as f:
            actual = f.read()
        self.assertEqual(expected, actual)