test_download_script.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import os
  2. from src.faostat_data_primap.download import download_all_domains
  3. # test the whole download script run
  4. def test_download_all_domains(tmp_path):
  5. downloaded_data_path = tmp_path / "downloaded_data"
  6. download_all_domains(downloaded_data_path=downloaded_data_path)
  7. expected_downloaded_domains = [
  8. "farm_gate_emissions_crops",
  9. "farm_gate_livestock",
  10. "farm_gate_agriculture_energy",
  11. "land_use_forests",
  12. "land_use_fires",
  13. "land_use_drained_organic_soils",
  14. "pre_post_agricultural_production",
  15. ]
  16. domains = []
  17. for domain in downloaded_data_path.iterdir():
  18. if domain.is_dir():
  19. domains.append(domain.name)
  20. for release in domain.iterdir():
  21. downloaded_data = os.listdir(release)
  22. # make sure we have at least one .csv, one .pdf and one .zip file
  23. assert [f for f in downloaded_data if f.endswith(".csv")]
  24. assert [f for f in downloaded_data if f.endswith(".pdf")]
  25. assert [f for f in downloaded_data if f.endswith(".zip")]
  26. assert sorted(expected_downloaded_domains) == sorted(domains)