From f906c332350ac9675a22299078e72dc92932e642 Mon Sep 17 00:00:00 2001 From: Ian Date: Fri, 10 Mar 2023 11:11:57 -0500 Subject: [PATCH] fix close(::Figure) and add test --- .gitignore | 2 ++ src/PythonPlot.jl | 2 +- test/runtests.jl | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0e8c587 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Manifest.toml +.CondaPkg diff --git a/src/PythonPlot.jl b/src/PythonPlot.jl index 9c21423..2e42ff0 100755 --- a/src/PythonPlot.jl +++ b/src/PythonPlot.jl @@ -190,7 +190,7 @@ Base.close(f::Figure) = plotclose(f) # rename to avoid type piracy: @doc LazyHelp(pyplot,"close") plotclose() = pyplot.close() -plotclose(f::Figure) = pyconvert(Int, plotclose(pyconvert(Int, f.number))) +plotclose(f::Figure) = pyconvert(Union{Nothing,Int}, plotclose(pyconvert(Int, f.number))) function plotclose(f::Integer) pop!(withfig_fignums, f, f) pyplot.close(f) diff --git a/test/runtests.jl b/test/runtests.jl index f3d7eb4..18a01df 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -37,4 +37,9 @@ rgba = PyArray(pycall(PythonPlot.ScalarMappable; cmap=c, norm=PythonPlot.Normali 0.8991926182237601 0.5144175317185697 0.4079200307574009 1.0 0.9657054978854287 0.9672433679354094 0.9680891964628989 1.0 0.4085351787773935 0.6687427912341408 0.8145328719723184 1.0 - 0.0196078431372549 0.18823529411764706 0.3803921568627451 1.0 ] \ No newline at end of file + 0.0196078431372549 0.18823529411764706 0.3803921568627451 1.0 ] + +@testset "close figure: issue 22" begin + f = figure() + @test close(f) === nothing +end