kernel-luso-comfort commited on
Commit
29c9bfa
1 Parent(s): b304f79

Add testing support and new utility function for target distribution

Browse files

- Introduce a new function `modality_targets_from_target_dist` in `target_dist.py` to extract modality targets from a target distribution dictionary.
- Create a new test file `test_target_dist.py` with unit tests for the new function.
- Update `Makefile` to include a test command for running pytest.
- Modify `pyproject.toml` to configure pytest options.

Makefile CHANGED
@@ -1,2 +1,5 @@
1
  run:
2
  DEV_MODE=1 uv run gradio main.py
 
 
 
 
1
  run:
2
  DEV_MODE=1 uv run gradio main.py
3
+
4
+ test:
5
+ uv run pytest
inference_utils/target_dist.py CHANGED
@@ -0,0 +1,2 @@
 
 
 
1
+ def modality_targets_from_target_dist(target_dist: dict) -> dict:
2
+ return {modality: list(targets.keys()) for modality, targets in target_dist.items()}
pyproject.toml CHANGED
@@ -8,3 +8,6 @@ dependencies = [
8
  "gradio==4.44.1",
9
  "pytest>=8.3.4",
10
  ]
 
 
 
 
8
  "gradio==4.44.1",
9
  "pytest>=8.3.4",
10
  ]
11
+
12
+ [tool.pytest.ini_options]
13
+ pythonpath = ["."]
test_inference_utils/test_target_dist.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from inference_utils.target_dist import modality_targets_from_target_dist
2
+
3
+
4
+ def test_target_dist_dict_to_modality_targets():
5
+ target_dist_dict = {
6
+ "CT-Abdomen": {"postcava": [[1, 2], [3, 4]], "aorta": [[5, 6], [7, 8]]},
7
+ "CT-Chest": {"nodule": [[9, 10], [11, 12]], "tumor": [[13, 14], [15, 16]]},
8
+ }
9
+
10
+ expected = {
11
+ "CT-Abdomen": ["postcava", "aorta"],
12
+ "CT-Chest": ["nodule", "tumor"],
13
+ }
14
+
15
+ actual = modality_targets_from_target_dist(target_dist_dict)
16
+
17
+ assert actual == expected