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)
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)
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, )
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)
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')
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)
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)
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_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)
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)
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)
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)
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)
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)