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.", )
def test_config_file_arg(self): cli = CommandLineInterface("test") cli.build_parser() assert cli.parser._positionals._actions[1].dest == "config_file"
def test_usage(self): cli = CommandLineInterface("test") cli.build_parser() assert cli.parser.prog == "python -m nowcast.test"
def test_no_help(self): cli = CommandLineInterface("test") cli.build_parser(add_help=False) assert not isinstance(cli.parser._optionals._actions[0], argparse._HelpAction)
def test_description(self): cli = CommandLineInterface("test", description="foo bar baz") assert cli.description == "foo bar baz"
def test_parser(self): cli = CommandLineInterface("test") assert cli.parser is None
def test_package(self): cli = CommandLineInterface("test", package="foo") assert cli.package == "foo"
def test_default_no_description(self): cli = CommandLineInterface("test") assert cli.description is None
def test_module_name(self): cli = CommandLineInterface("test") assert cli.module_name == "test"
def test_default_package(self): cli = CommandLineInterface("test") assert cli.package == "nowcast"
def test_arrow_date_parse_erroe(self): cli = CommandLineInterface("test") with pytest.raises(argparse.ArgumentTypeError): cli.arrow_date("205-7-261")
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
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
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")
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"]