test_read_data_set.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import os
  2. import subprocess
  3. from pathlib import Path
  4. def test_read_data_set(tmp_path):
  5. script_path = Path(__file__).parent.parent.parent / "scripts" / "read_data_set.py"
  6. # Build the command
  7. command = [
  8. "poetry",
  9. "run",
  10. "python3",
  11. str(script_path),
  12. "--save_path",
  13. str(tmp_path),
  14. "--run_id",
  15. "2024",
  16. ]
  17. # Run the command
  18. result = subprocess.run(command, capture_output=True, text=True, check=False) # noqa: S603
  19. # Check the result
  20. assert result.returncode == 0, f"Script failed: {result.stderr}"
  21. release_folder = os.listdir(tmp_path)
  22. # there should be one directory created
  23. assert len(release_folder) == 1
  24. # and it starts with "v" (the date changes with each release)
  25. assert release_folder[0].startswith("v")
  26. output_files = os.listdir(tmp_path / release_folder[0])
  27. # in the folder there should be three files
  28. assert len(output_files) == 3
  29. # a .yaml, .csv, and .nc file
  30. required_extensions = {"nc", "csv", "yaml"}
  31. file_extensions = {file.split(".")[-1] for file in output_files}
  32. assert required_extensions == file_extensions