def test_find_src_dir_errors_when_no_init_is_found(self, tmp_path: pathlib.Path): tmp_path.joinpath("setup.py").write_text("I exist") output_folder = tmp_path / "src" / "test" output_folder.mkdir(parents=True) with pytest.raises(MLToolingError, match="No modules found in"): _find_src_dir(output_folder)
def save(self, estimator: Estimator, filename: str, prod: bool = False) -> Path: """ Save a joblib pickled estimator. Parameters ---------- estimator: obj The estimator object filename: str filename of estimator pickle file prod: bool Whether or not to save in "production mode" - Production mode saves to /src/<projectname>/ regardless of what FileStorage was instantiated with Example ------- To save your trained estimator, use the FileStorage context manager. storage = FileStorage('/path/to/save/dir/') file_path = storage.save(estimator, 'filename') We now have saved an estimator to a pickle file. Returns ------- Path Path to the saved object """ if prod: file_path = _find_src_dir() / filename else: file_path = make_dir(self.dir_path) / filename joblib.dump(estimator, file_path) return file_path
def test_can_find_src_dir_from_inside_project( self, temp_project_structure: pathlib.Path): result = _find_src_dir(temp_project_structure / "notebooks") assert result == temp_project_structure / "src" / "my_test_project"
def test_find_src_dir_errors_when_no_src_is_found(self, tmp_path: pathlib.Path): tmp_path.joinpath("setup.py").write_text("I exist") with pytest.raises(MLToolingError, match="Project must have a src folder!"): _find_src_dir(tmp_path / "test" / "test")
def test_can_find_src_dir_from_root_folder_structure( self, temp_project_structure: pathlib.Path): result = _find_src_dir(temp_project_structure) assert result == temp_project_structure / "src" / "my_test_project"