Commits

Tikitu de Jager  committed 38e7e2c Draft

Added failing test for producing a config file.

  • Participants
  • Parent commits a51a9c0

Comments (0)

Files changed (2)

File argparse_config.src/argparse_config/__init__.py

             value=e.value
         ))
 
+def write_defaults(arg_parser):
+    pass
+
 class DefaultError(Exception):
     def __init__(self, section_name, option_string, value, type_transformer):
         self.section_name = section_name

File argparse_config.src/argparse_config/tests/__init__.py

 import tempfile
 import textwrap
 from unittest import TestCase
-from .. import set_defaults, read_config
+from .. import set_defaults, read_config, write_defaults
 
 __author__ = 'tikitu'
 
             read_config(arg_parser, temp_file.name)
         parsed_args = arg_parser.parse_args([])
         self.assertTrue(parsed_args.verbose)
+
+class DefaultsOutputTest(TestCase):
+
+    @with_config_file()
+    def test_everything(self, config_parser):
+        """
+        [default]
+        int_value: 3
+        flag:
+        """
+        arg_parser = ArgumentParser()
+        arg_parser.add_argument('--int-value', type=int)
+        arg_parser.add_argument('--flag', action='store_true')
+
+        sub_parsers = arg_parser.add_subparsers()
+        subcommand_parser = sub_parsers.add_parser('subcommand')
+        subcommand_parser.add_argument('--tool', default='hammer')
+
+        parsed_args = arg_parser.parse_args([])
+        new_config_file = write_defaults(arg_parser)
+        self.assertEquals(new_config_file, textwrap.dedent("""
+        [default]
+
+        [subcommand]
+        tool: hammer
+        """.lstrip('\n')))
+
+        set_defaults(arg_parser, config_parser)
+        parsed_args = arg_parser.parse_args([])
+        new_config_file = write_defaults(arg_parser)
+        self.assertEquals(new_config_file, textwrap.dedent("""
+        [default]
+        int_value: 3
+        flag:
+
+        [subcommand]
+        tool: hammer
+        """.lstrip('\n')))