test_read_script.py 987 B

123456789101112131415161718192021222324252627282930
  1. import os
  2. from src.faostat_data_primap.helper.paths import root_path
  3. from src.faostat_data_primap.read import read_latest_data
  4. example_csv_content = ()
  5. def test_read_latest_data(tmp_path):
  6. # get the downloaded data from here
  7. downloaded_data_path = root_path / "downloaded_data"
  8. # read and save latest data
  9. read_latest_data(downloaded_data_path=downloaded_data_path, save_path=tmp_path)
  10. release_folder = os.listdir(tmp_path)
  11. # there should be one directory created
  12. assert len(release_folder) == 1
  13. # and it starts with "v" (the date changes with each release)
  14. assert release_folder[0].startswith("v")
  15. output_files = os.listdir(tmp_path / release_folder[0])
  16. # in the folder there should be three files
  17. assert len(output_files) == 3
  18. # a .yaml, .csv, and .nc file
  19. required_extensions = {"nc", "csv", "yaml"}
  20. file_extensions = {file.split(".")[-1] for file in output_files}
  21. assert required_extensions == file_extensions