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
def test_curl(tempname): n = 3 curl(path=tempname, url=make_url(2012), max_chunk=n) assert Path(tempname).stat().st_size == n * 1024
def test_make_url_on_good_year(): assert make_url(2012)
def test_make_url_on_0(): assert make_url(0)
def test_make_url_on_bad_year(): with pytest.raises(ValueError): make_url(1990)
def file_length(year: int): return url_content_length(url=make_url(year))