コード例 #1
0
ファイル: test_gen_utils.py プロジェクト: sparkpoints/evalml
def test_save_matplotlib_default_format(file_name, format, interactive,
                                        fitted_tree_estimators, tmpdir):
    plt = pytest.importorskip("matplotlib.pyplot")

    def setup_plt():
        fig_ = plt.figure(figsize=(4.5, 4.5))
        plt.plot(range(5))
        return fig_

    fig = setup_plt()
    filepath = os.path.join(str(tmpdir), f'{file_name}')
    no_output_ = save_plot(fig=fig,
                           filepath=filepath,
                           format=format,
                           interactive=interactive,
                           return_filepath=False)
    output_ = save_plot(fig=fig,
                        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_) == 'test_plot.png'
コード例 #2
0
ファイル: test_gen_utils.py プロジェクト: sparkpoints/evalml
def test_save_seaborn_default_format(file_name, format, interactive,
                                     fitted_tree_estimators, tmpdir,
                                     has_minimal_dependencies):
    sns = pytest.importorskip("seaborn")

    def setup_plt():
        data_ = [0, 1, 2, 3, 4]
        fig = sns.scatterplot(data=data_)
        return fig

    fig = setup_plt()
    filepath = os.path.join(str(tmpdir), f'{file_name}')
    no_output_ = save_plot(fig=fig,
                           filepath=filepath,
                           format=format,
                           interactive=interactive,
                           return_filepath=False)
    output_ = save_plot(fig=fig,
                        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_) == 'test_plot.png'
コード例 #3
0
ファイル: test_gen_utils.py プロジェクト: sparkpoints/evalml
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'
コード例 #4
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)
コード例 #5
0
def test_save_plotly_interactive(file_name, format, interactive, decision_tree_classification_pipeline_class, tmpdir, has_minimal_dependencies):
    if not has_minimal_dependencies:
        pipeline = decision_tree_classification_pipeline_class
        feat_fig_ = pipeline.graph_feature_importance()

        filepath = os.path.join(str(tmpdir), f'{file_name}') if file_name else None
        no_output_ = save_plot(fig=feat_fig_, filepath=filepath, format=format, interactive=interactive, return_filepath=False)
        output_ = save_plot(fig=feat_fig_, 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_) == 'test_plot.html'