Forráskód Böngészése

[DATALAD] Recorded changes

Daniel Busch 4 hónapja
szülő
commit
e33f4eebdc
2 módosított fájl, 45 hozzáadás és 3 törlés
  1. 19 3
      dodo.py
  2. 26 0
      tests/integration/test_doit_targets.py

+ 19 - 3
dodo.py

@@ -43,11 +43,16 @@ def task_read_data():
     read data set
     """
 
-    def read_dataset():
+    def read_dataset(save_path, run_id):
         output_folders = get_output_folders(domains_and_releases_to_read)
 
+        cmd = (
+            f"python3 scripts/read_data_set.py "
+            f"--save_path {save_path} --run_id {run_id}"
+        )
+
         datalad.api.run(
-            cmd="python3 scripts/read_data_set.py",
+            cmd=cmd,
             message="Read data set",
             outputs=output_folders,
         )
@@ -55,7 +60,18 @@ def task_read_data():
     return {
         "actions": [read_dataset],
         "params": [
-            {"name": "run_id", "long": "run_id", "type": str, "default": "2024"}
+            {
+                "name": "save_path",
+                "short": "s",
+                "default": "/extracted_data",
+                "help": "Path to save the data.",
+            },
+            {
+                "name": "run_id",
+                "short": "r",
+                "default": "2024",
+                "help": "Run identifier.",
+            },
         ],
         "verbosity": 2,
     }

+ 26 - 0
tests/integration/test_doit_targets.py

@@ -0,0 +1,26 @@
+import pytest
+from doit.doit_cmd import DoitMain
+
+from src.faostat_data_primap.helper.paths import root_path
+
+
+@pytest.fixture
+def change_to_project_root(monkeypatch):
+    monkeypatch.chdir(root_path)
+
+
+def test_doit_command(change_to_project_root, tmp_path):
+    """
+    Test a `doit` task programmatically.
+    """
+    save_path = tmp_path / "extracted_data"
+    save_path.mkdir()
+
+    # Command-line arguments for the doit task
+    cmd_args = ["run", "read_data", f"save_path={save_path!s}", "run_id=2024"]
+
+    # Run the doit command programmatically
+    result = DoitMain().run(cmd_args)
+
+    # Assert that the task ran successfully (return code 0)
+    assert result == 0, f"doit task failed with return code: {result}"