test_download.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import pytest
  2. import requests
  3. from faostat_data_primap.download import (
  4. calculate_checksum,
  5. download_methodology,
  6. find_previous_release_path,
  7. )
  8. @pytest.fixture
  9. def temp_domain_directories(tmp_path):
  10. """
  11. Sets up a temporary directory structure for domains and releases for testing.
  12. Parameters
  13. ----------
  14. tmp_path : pathlib.Path
  15. A pytest-provided temporary directory path.
  16. Returns
  17. -------
  18. dict
  19. A dictionary containing the paths to the `downloaded_data` directory,
  20. the specific domain directory, and a list of sorted release paths.
  21. """
  22. downloaded_data = tmp_path / "downloaded_data"
  23. downloaded_data.mkdir()
  24. domains = (
  25. "farm_gate_emissions_crops",
  26. "farm_gate_livestock",
  27. "farm_gate_agriculture_energy",
  28. "land_use_forests",
  29. "land_use_fires",
  30. "land_use_drained_organic_soils",
  31. "pre_post_agricultural_production",
  32. )
  33. domain_paths = []
  34. for domain in domains:
  35. domain_path = downloaded_data / domain
  36. domain_path.mkdir()
  37. domain_paths.append(domain_path)
  38. return {
  39. "downloaded_data": downloaded_data,
  40. "domain_paths": domain_paths,
  41. }