Exemple #1
0
def test_save_graphviz_different_filename_output(file_name, format,
                                                 interactive,
                                                 fitted_tree_estimators,
                                                 tmpdir,
                                                 has_minimal_dependencies):
    if not has_minimal_dependencies:
        est_class, _ = fitted_tree_estimators
        src = visualize_decision_tree(estimator=est_class,
                                      filled=True,
                                      max_depth=3)

        filepath = os.path.join(str(tmpdir), f'{file_name}')
        no_output_ = save_plot(fig=src,
                               filepath=filepath,
                               format=format,
                               interactive=interactive,
                               return_filepath=False)
        output_ = save_plot(fig=src,
                            filepath=filepath,
                            format=format,
                            interactive=interactive,
                            return_filepath=True)

        assert not no_output_
        assert os.path.exists(output_)
        assert isinstance(output_, str)
        assert os.path.basename(output_) == 'example_plot.png'
Exemple #2
0
def test_save_graphviz_invalid_filepath(file_name, format, interactive, fitted_tree_estimators, tmpdir, has_minimal_dependencies):
    if not has_minimal_dependencies:
        est_class, _ = fitted_tree_estimators
        src = visualize_decision_tree(estimator=est_class, filled=True, max_depth=3)

        filepath = f'{file_name}.{format}'

        with pytest.raises(ValueError, match="Specified filepath is not writeable"):
            save_plot(fig=src, filepath=filepath, format=format, interactive=interactive, return_filepath=False)