Skip to content
Snippets Groups Projects
utils.py 839 B
Newer Older
"""Utilities for running tests."""

import urllib.request
David Hoese's avatar
David Hoese committed
from pathlib import Path
David Hoese's avatar
David Hoese committed
CACHE_DIR = Path(__file__).resolve().parent / "test_data"


def get_cached_level_00(num_files=2):
    """Get a couple real ASCII files to test against."""
    file_urls = (
        "https://metobs-test.ssec.wisc.edu/pub/cache/aoss/tower/level_00/version_00/2020/01/01/aoss_tower.2020-01-01.ascii",
        "https://metobs-test.ssec.wisc.edu/pub/cache/aoss/tower/level_00/version_00/2020/01/02/aoss_tower.2020-01-02.ascii",
    )
    if num_files > len(file_urls):
David Hoese's avatar
David Hoese committed
        msg = f"Maximum of {len(file_urls)} can be loaded."
        raise ValueError(msg)
    file_urls = file_urls[:num_files]

    for u in file_urls:
David Hoese's avatar
David Hoese committed
        fn = CACHE_DIR / u.rsplit("/", 1)[-1]
        if not fn.is_file():
            urllib.request.urlretrieve(u, fn)
        yield fn