Skip to content

Commit

Permalink
argparse tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ainur Karimov committed Dec 20, 2024
1 parent a4bce08 commit 8295047
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion innofw/utils/data_utils/rtk/lungs_description_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def main():
"""Main module function"""
parser = ArgumentParser(
prog="innofw",
description="A tool to determine lung decision from a description",
description="Tool to calc lung decision metrcis",
formatter_class=ArgumentDefaultsHelpFormatter,
)
setup_parser(parser)
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/datamodules/lightning_datamodules/test_rtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
)
from innofw.core.datasets.coco_rtk import DicomCocoDatasetRTK
from innofw.utils.data_utils.preprocessing.CT_hemorrhage_contrast_rtk import (
hemorrhage_contrast, transform as resize_transform
hemorrhage_contrast,
transform as resize_transform,
)
from innofw.utils.data_utils.preprocessing.CT_hemorrhage_contrast_metrics import (
hemorrhage_contrast_metrics,
)
from innofw.utils.data_utils.rtk.CT_hemorrhage_metrics import process_metrics
from innofw.utils.data_utils.preprocessing.CT_hemorrhage_contrast_metrics import hemorrhage_contrast_metrics

rtk_complex = "https://api.blackhole.ai.innopolis.university/public-datasets/rtk/complex_infer.zip"
rtk_segm = "https://api.blackhole.ai.innopolis.university/public-datasets/rtk/infer.zip"
Expand Down Expand Up @@ -133,7 +136,7 @@ def test_segm_detection_pipeline_metrics(mock_show, tmp_path_factory, task):

out_dir = tmp_path_factory.mktemp("out")
for i in range(samples_number):
random_numpy = np.random.randint(0, 1, [256,256,1])
random_numpy = np.random.randint(0, 1, [256, 256, 1])
np.save(os.path.join(out_dir, f"{i}.npy"), random_numpy)

process_metrics(input_path=target_dir, output_folder=out_dir)
Expand Down
34 changes: 34 additions & 0 deletions tests/unit/rtk/test_hemorrhage_contrast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from unittest.mock import patch
import argparse

from innofw.utils.data_utils.preprocessing.CT_hemorrhage_contrast_rtk import (
callback,
default_output_path,
setup_parser,
)


def test_setup_parser():
parser = argparse.ArgumentParser()
setup_parser(parser)
args = parser.parse_args(["-i", "input.txt"])
assert args.input == "input.txt"
assert args.output is None

args = parser.parse_args(["-i", "input.txt", "-o", "output.txt"])
assert args.input == "input.txt"
assert args.output == "output.txt"


def test_default_output_path():
# Mock get_log_dir to return a predictable value
with patch("innofw.utils.getters.get_log_dir", return_value="mock_log_dir"):
output_path = default_output_path()
assert output_path == "mock_log_dir"


@patch("innofw.utils.data_utils.preprocessing.CT_hemorrhage_contrast_rtk.hemorrhage_contrast")
def test_callback_success(mock_contrast):
arguments = argparse.Namespace(input="input.txt", output="output.txt")
callback(arguments)
mock_contrast.assert_called_once_with("input.txt", "output.txt")
22 changes: 22 additions & 0 deletions tests/unit/rtk/test_lung_description_rtk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import argparse
from unittest.mock import patch

from innofw.utils.data_utils.rtk.lungs_description_metrics import (
callback,
setup_parser,
)


def test_setup_parser():
parser = argparse.ArgumentParser()
setup_parser(parser)
args = parser.parse_args(["-i", "input.txt", "-o", "output.txt"])
assert args.input == "input.txt"
assert args.output == "output.txt"


@patch("innofw.utils.data_utils.rtk.lungs_description_metrics.calculate_lungs_metrics")
def test_callback_success(mock_calc):
arguments = argparse.Namespace(input="input.txt", output="output.txt")
callback(arguments)
mock_calc.assert_called_once_with("input.txt", "output.txt")
File renamed without changes.

0 comments on commit 8295047

Please sign in to comment.