Пример #1
0
 def test_add_argument(self, m_parser):
     """add_argument() wraps argparse.ArgumentParser.add_argument()
     """
     cli = CommandLineInterface("test")
     cli.parser = m_parser
     cli.add_argument(
         "--yesterday",
         action="store_true",
         help="Download forecast files for previous day's date.",
     )
     m_parser.add_argument.assert_called_once_with(
         "--yesterday",
         action="store_true",
         help="Download forecast files for previous day's date.",
     )
Пример #2
0
 def test_config_file_arg(self):
     cli = CommandLineInterface("test")
     cli.build_parser()
     assert cli.parser._positionals._actions[1].dest == "config_file"
Пример #3
0
 def test_usage(self):
     cli = CommandLineInterface("test")
     cli.build_parser()
     assert cli.parser.prog == "python -m nowcast.test"
Пример #4
0
 def test_no_help(self):
     cli = CommandLineInterface("test")
     cli.build_parser(add_help=False)
     assert not isinstance(cli.parser._optionals._actions[0], argparse._HelpAction)
Пример #5
0
 def test_description(self):
     cli = CommandLineInterface("test", description="foo bar baz")
     assert cli.description == "foo bar baz"
Пример #6
0
 def test_parser(self):
     cli = CommandLineInterface("test")
     assert cli.parser is None
Пример #7
0
 def test_package(self):
     cli = CommandLineInterface("test", package="foo")
     assert cli.package == "foo"
Пример #8
0
 def test_default_no_description(self):
     cli = CommandLineInterface("test")
     assert cli.description is None
Пример #9
0
 def test_module_name(self):
     cli = CommandLineInterface("test")
     assert cli.module_name == "test"
Пример #10
0
 def test_default_package(self):
     cli = CommandLineInterface("test")
     assert cli.package == "nowcast"
Пример #11
0
 def test_arrow_date_parse_erroe(self):
     cli = CommandLineInterface("test")
     with pytest.raises(argparse.ArgumentTypeError):
         cli.arrow_date("205-7-261")
Пример #12
0
 def test_arrow_date(self):
     cli = CommandLineInterface("test")
     arw = cli.arrow_date("2016-09-22")
     expected = arrow.get(datetime(2016, 9, 22, 0, 0, 0), "utc")
     assert arw == expected
Пример #13
0
 def test_help(self):
     cli = CommandLineInterface("test")
     cli.build_parser()
     cli.add_date_option("--test-date", arrow.get("2016-09-22"), "Help message.")
     expected = "Help message. Use YYYY-MM-DD format. Defaults to 2016-09-22."
     assert cli.parser._actions[2].help == expected
Пример #14
0
 def test_default(self):
     cli = CommandLineInterface("test")
     cli.build_parser()
     cli.add_date_option("--test-date", arrow.get("2016-09-22"), "help")
     assert cli.parser._actions[2].default == arrow.get("2016-09-22")
Пример #15
0
 def test_option_name(self):
     cli = CommandLineInterface("test")
     cli.build_parser()
     cli.add_date_option("--test-date", arrow.get("2016-09-22"), "help")
     assert cli.parser._actions[2].option_strings == ["--test-date"]