Bläddra i källkod

[DATALAD] Recorded changes

Daniel Busch 4 månader sedan
förälder
incheckning
48456318d3
2 ändrade filer med 53 tillägg och 9 borttagningar
  1. 31 0
      scripts/read_data_set.py
  2. 22 9
      tests/integration/test_read_data_set.py

+ 31 - 0
scripts/read_data_set.py

@@ -0,0 +1,31 @@
+"""Read selected domains and versions."""
+from pathlib import Path
+
+import click
+
+from faostat_data_primap.helper.definitions import domains_and_releases_to_read
+from faostat_data_primap.helper.paths import (
+    extracted_data_path,
+)
+from faostat_data_primap.read import (
+    read_data,
+)
+
+
+@click.command()
+@click.option("--run_id", default="2024", help="Configuration to run")
+@click.option("--save_path", default=None, help="Where to save data in root directory.")
+def run(run_id, save_path):
+    """Prepare and run read data function"""
+    if not save_path:
+        save_path = extracted_data_path
+    else:
+        save_path = Path(save_path)
+    read_data(
+        domains_and_releases_to_read=domains_and_releases_to_read[run_id],
+        save_path=save_path,
+    )
+
+
+if __name__ == "__main__":
+    run()

+ 22 - 9
tests/integration/test_read_data_set.py

@@ -4,9 +4,26 @@ from pathlib import Path
 
 
 def test_read_data_set(tmp_path):
+    # we need to download first for the CI tests
+    script_path = (
+        Path(__file__).parent.parent.parent / "scripts" / "download_all_domains.py"
+    )
+    command = [
+        "poetry",
+        "run",
+        "python3",
+        str(script_path),
+    ]
+    result_download = subprocess.run(
+        command,  # noqa: S603
+        capture_output=True,
+        text=True,
+        check=False,
+    )
+    assert result_download.returncode == 0, f"Script failed: {result_download.stderr}"
+
+    # then read data
     script_path = Path(__file__).parent.parent.parent / "scripts" / "read_data_set.py"
-
-    # Build the command
     command = [
         "poetry",
         "run",
@@ -17,15 +34,11 @@ def test_read_data_set(tmp_path):
         "--run_id",
         "2024",
     ]
+    result_read = subprocess.run(command, capture_output=True, text=True, check=False)  # noqa: S603
+    assert result_read.returncode == 0, f"Script failed: {result_read.stderr}"
 
-    # Run the command
-    result = subprocess.run(command, capture_output=True, text=True, check=False)  # noqa: S603
-
-    # Check the result
-    assert result.returncode == 0, f"Script failed: {result.stderr}"
-
+    # check output files
     release_folder = os.listdir(tmp_path)
-
     # there should be one directory created
     assert len(release_folder) == 1
     # and it starts with "v" (the date changes with each release)