Esempio n. 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)
Esempio n. 2
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'), 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)
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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)
    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)
Esempio n. 7
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)
    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)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
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)
Esempio n. 15
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)
Esempio n. 16
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)