Esempio n. 1
0
File: main.py Progetto: ra2003/boo
def download(year: int, force=False, directory=None):
    """Download file from Rosstat web site."""
    raw_file = RawFile(year, directory)
    path = raw_file.path
    url = make_url(year)
    conditional_delete(path, force)
    if not path.exists():
        print(f"Downloading source file for {year} from", url)
        curl(path, url)
        print("Saved as", raw_file)
    else:
        print("Already downloaded:", raw_file)
        print(force_message(year, "download"))
    return path
Esempio n. 2
0
def test_curl(tempname):
    n = 3
    curl(path=tempname, url=make_url(2012), max_chunk=n)
    assert Path(tempname).stat().st_size == n * 1024
Esempio n. 3
0
def test_make_url_on_good_year():
    assert make_url(2012)
Esempio n. 4
0
def test_make_url_on_0():
    assert make_url(0)
Esempio n. 5
0
def test_make_url_on_bad_year():
    with pytest.raises(ValueError):
        make_url(1990)
Esempio n. 6
0
def file_length(year: int):
    return url_content_length(url=make_url(year))