Commits

Tikitu de Jager  committed 4196a6e Draft

Added another test, and improved the current one.

  • Participants
  • Parent commits f9d1705

Comments (0)

Files changed (1)

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

         """
         [default]
         int_value: 3
-        flag:
+        flag
         """
         arg_parser = ArgumentParser()
         arg_parser.add_argument('--int-value', type=int)
         sub_parsers = arg_parser.add_subparsers()
         subcommand_parser = sub_parsers.add_parser('subcommand')
         subcommand_parser.add_argument('--tool', default='hammer')
+        subcommand_parser.add_argument('--object', default='nail')
 
         parsed_args = arg_parser.parse_args(['subcommand'])
         new_config_file = write_defaults(arg_parser, parsed_args)
 
         [subcommand]
         tool: hammer
+        object: nail
         """.lstrip('\n')))
 
         set_defaults(arg_parser, config_parser)
-        parsed_args = arg_parser.parse_args(['subcommand'])
+        parsed_args = arg_parser.parse_args(['subcommand', '--object', 'thumb'])
         new_config_file = write_defaults(arg_parser, parsed_args)
         self.assertEquals(new_config_file, textwrap.dedent("""
         [default]
 
         [subcommand]
         tool: hammer
+        object: thumb
         """.lstrip('\n')))
+
+    @with_config_file()
+    def test_everything(self, config_parser):
+        """
+        [default]
+        flag
+        """
+        def check_round_trip(arg_parser):
+            set_defaults(arg_parser, config_parser)
+            parsed_args = arg_parser.parse_args([])
+            new_config_file = write_defaults(arg_parser, parsed_args)
+            self.assertEquals(new_config_file, textwrap.dedent("""
+            [default]
+            flag
+            """.lstrip('\n')))
+
+        arg_parser = ArgumentParser()
+        arg_parser.add_argument('--flag', action='store_true')
+        check_round_trip(arg_parser)
+
+        arg_parser = ArgumentParser()
+        arg_parser.add_argument('--flag', action='store_false')
+        check_round_trip(arg_parser)
+
+