def test_parse_str_to_date_incomplete():
    try:
        parse_str_to_date("2019-07")
        assert 1 == 0
    except Exception as e:
        assert isinstance(
            e, ValueError), "Should throw value error on short string."
def test_parse_str_to_date_short():
    try:
        parse_str_to_date("190706")
        assert 1 == 0
    except Exception as e:
        assert isinstance(
            e, ValueError), "Should throw value error on short string."
Esempio n. 3
0
def setup(date):
    # Check if date is passed as argument, set to default (today) otherwise
    if date is None:
        date = datetime.now()
    else:
        date = parse_str_to_date(date)
    print(date)
def update(date, auto):
    '''Get the newest NASA Picture of the Day and set it as background'''
    # Check if date is passed as argument, set to default (today) otherwise
    if date is None:
        date = datetime.now()
    else:
        date = parse_str_to_date(date)

    try:
        # Download and print information about
        meta_info = nasa_api.get_info(date)
        click.echo(f"Title: {meta_info['title']}\n")
        click.echo(meta_info['explanation'] + "\n")

        # Check if auto is selected, otherwise prompt user to set it as background
        if auto or click.confirm(
                "Do you wish to download this image and set it as background?"
        ):
            # Download and set the background
            file_path = nasa_api.download_image(date)
            background.change_background(file_path, auto)
    except KeyError:
        click.echo(f"Image not found for the selected date {date}. ")
    except Exception as e:
        click.echo("Fatal error encountered, exiting program.")
        click.echo(e)
def test_parse_str_to_date_extra():
    assert parse_str_to_date("2019-7-6-9-12-3-34-5-1") == datetime(2019, 7, 6)
def test_parse_str_to_date_minified():
    assert parse_str_to_date("2019-7-6") == datetime(2019, 7, 6)
def test_parse_str_to_date_full():
    assert parse_str_to_date("20190706") == datetime(2019, 7, 6)