def test_unknown_type() -> None: checkpoint_config = { "type": "unknown", "host_path": HOST_PATH, "container_path": CONTAINER_PATH, } with pytest.raises(TypeError, match="Unknown storage type: unknown"): tensorboard.build(test_util.get_dummy_env(), checkpoint_config)
def test_getting_manager_instance(tmp_path: pathlib.Path) -> None: checkpoint_config = { "type": "shared_fs", "host_path": HOST_PATH, "container_path": tmp_path } manager = tensorboard.build(test_util.get_dummy_env(), checkpoint_config) assert isinstance(manager, SharedFSTensorboardManager)
def test_setting_storage_path(tmp_path: pathlib.Path) -> None: checkpoint_config = { "type": "shared_fs", "host_path": str(HOST_PATH), "container_path": tmp_path, "storage_path": str(STORAGE_PATH), } manager = tensorboard.build(test_util.get_dummy_env(), checkpoint_config) assert isinstance(manager, SharedFSTensorboardManager) assert manager.container_path == tmp_path.joinpath("test_storage_path")
def test_setting_optional_variable(tmp_path: pathlib.Path) -> None: checkpoint_config = { "type": "shared_fs", "base_path": "test_value", "host_path": HOST_PATH, "container_path": tmp_path, } manager = tensorboard.build(test_util.get_dummy_env(), checkpoint_config) assert isinstance(manager, SharedFSTensorboardManager) assert manager.base_path == pathlib.Path("test_value/tensorboard")
def test_s3_lifecycle(monkeypatch: monkeypatch.MonkeyPatch) -> None: monkeypatch.setattr("boto3.client", s3.s3_client) manager = tensorboard.build(test_util.get_dummy_env(), default_conf) assert isinstance(manager, tensorboard.S3TensorboardManager) manager.sync() expected = ( "s3_bucket", "uuid-123/tensorboard/experiment/1/trial/1/events.out.tfevents.example", ) assert expected in manager.client.objects
def test_list_nonexistent_directory(tmp_path: pathlib.Path) -> None: base_path = "/non-existent-directory" checkpoint_config = { "type": "shared_fs", "base_path": base_path, "host_path": HOST_PATH, "container_path": tmp_path, } manager = tensorboard.build(test_util.get_dummy_env(), checkpoint_config) assert not pathlib.Path(base_path).exists() assert manager.list_tfevents() == []
def test_list_directory(tmp_path: pathlib.Path) -> None: checkpoint_config = { "type": "shared_fs", "base_path": BASE_PATH, "host_path": HOST_PATH, "container_path": tmp_path, } manager = tensorboard.build(test_util.get_dummy_env(), checkpoint_config) full_event_path = BASE_PATH.joinpath("tensorboard", "events.out.tfevents.example") assert set(manager.list_tfevents()) == {full_event_path}
def test_s3_faulty_lifecycle(monkeypatch: monkeypatch.MonkeyPatch) -> None: monkeypatch.setattr("boto3.client", s3.s3_faulty_client) manager = tensorboard.build(test_util.get_dummy_env(), default_conf) with pytest.raises(exceptions.S3UploadFailedError): manager.sync()
def test_s3_build_missing_param() -> None: conf = copy.deepcopy(default_conf) del conf["bucket"] with pytest.raises(KeyError): tensorboard.build(test_util.get_dummy_env(), conf)
def test_s3_build() -> None: manager = tensorboard.build(test_util.get_dummy_env(), default_conf) assert isinstance(manager, tensorboard.S3TensorboardManager)
def test_illegal_type() -> None: checkpoint_config = {"type": 4} with pytest.raises(TypeError, match="must be a string"): tensorboard.build(test_util.get_dummy_env(), checkpoint_config)
def test_missing_type() -> None: with pytest.raises(TypeError, match="Missing 'type' parameter"): tensorboard.build(test_util.get_dummy_env(), {})