Skip to content

Commit

Permalink
add version to requirement and raise an error if not supported values…
Browse files Browse the repository at this point in the history
… are given
  • Loading branch information
eunwoosh committed Sep 13, 2023
1 parent 3a10d56 commit 22ad518
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ scipy>=1.8
bayesian-optimization>=1.2.0
tensorboard>=2.11.0
multiprocess
pynvml
pynvml>=11.0.0
2 changes: 1 addition & 1 deletion src/otx/cli/utils/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _check_resource(queue: mp.Queue, resource_types: Optional[List[str]] = None,
continue
trackers[resource_type] = GpuUsageRecorder(gpu_ids)
else:
logger.warning(
raise ValueError(
"Resource type {} isn't supported now. Current available types are cpu and gpu.".format(resource_type)
)

Expand Down
25 changes: 7 additions & 18 deletions tests/unit/cli/utils/test_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,31 +139,20 @@ def test_check_resource(mocker, resource_types, tmp_path):
assert Path(output_file).exists() # check a file is saved well


@pytest.mark.parametrize("resource_types", (["wrong"], None))
@e2e_pytest_unit
def test_check_resource_wrong_resource_type(mocker, resource_types, tmp_path):
def test_check_resource_wrong_resource_type(mocker, tmp_path):
# prepare
resource_types = ["wrong"]
output_file = f"{tmp_path}/fake.yaml"
mock_queue = MockQueue(output_file)

mock_cpu_recorder = mocker.MagicMock()
mock_cpu_recorder_cls = mocker.patch.object(target_file, "CpuUsageRecorder", return_value=mock_cpu_recorder)
mock_gpu_recorder = mocker.MagicMock()
mock_gpu_recorder_cls = mocker.patch.object(target_file, "GpuUsageRecorder", return_value=mock_gpu_recorder)

mocker.patch.object(target_file, "CpuUsageRecorder")
mocker.patch.object(target_file, "GpuUsageRecorder")
mocker.patch.object(target_file, "yaml")
mocker.patch.object(target_file, "time")

# run
_check_resource(mock_queue, resource_types)

# check the recorders aren't called
mock_cpu_recorder.record.assert_not_called()
mock_cpu_recorder_cls.assert_not_called()
mock_gpu_recorder.record.assert_not_called()
mock_gpu_recorder_cls.assert_not_called()

assert not Path(output_file).exists() # check a file isn't saved
# check that ValueError is raised.
with pytest.raises(ValueError):
_check_resource(mock_queue, resource_types)


class TestCpuUsageRecorder:
Expand Down

0 comments on commit 22ad518

Please sign in to comment.