test_read_data_set.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import os
  2. import subprocess
  3. from pathlib import Path
  4. def test_read_data_set(tmp_path):
  5. # we need to download first for the CI tests
  6. script_path = (
  7. Path(__file__).parent.parent.parent / "scripts" / "download_all_domains.py"
  8. )
  9. command = [
  10. "poetry",
  11. "run",
  12. "python3",
  13. str(script_path),
  14. ]
  15. result_download = subprocess.run(
  16. command, # noqa: S603
  17. capture_output=True,
  18. text=True,
  19. check=False,
  20. )
  21. assert result_download.returncode == 0, f"Script failed: {result_download.stderr}"
  22. # then read data
  23. script_path = Path(__file__).parent.parent.parent / "scripts" / "read_data_set.py"
  24. command = [
  25. "poetry",
  26. "run",
  27. "python3",
  28. str(script_path),
  29. "--save_path",
  30. str(tmp_path),
  31. "--run_id",
  32. "2024",
  33. ]
  34. result_read = subprocess.run(command, capture_output=True, text=True, check=False) # noqa: S603
  35. assert result_read.returncode == 0, f"Script failed: {result_read.stderr}"
  36. # check output files
  37. release_folder = os.listdir(tmp_path)
  38. # there should be one directory created
  39. assert len(release_folder) == 1
  40. # and it starts with "v" (the date changes with each release)
  41. assert release_folder[0].startswith("v")
  42. output_files = os.listdir(tmp_path / release_folder[0])
  43. # in the folder there should be three files
  44. assert len(output_files) == 3
  45. # a .yaml, .csv, and .nc file
  46. required_extensions = {"nc", "csv", "yaml"}
  47. file_extensions = {file.split(".")[-1] for file in output_files}
  48. assert required_extensions == file_extensions