Repository: bokeh/bokeh

Issue:
new PhantomJS sessions spawned inside bokeh.io._get_svgs despite driver arg
new PhantomJS sessions spawned inside bokeh.io._get_svgs despite driver arg

bokeh 0.12.7dev3


Discussion:

Resolving patch:
diff --git a/bokeh/io.py b/bokeh/io.py
--- a/bokeh/io.py
+++ b/bokeh/io.py
@@ -685,15 +685,14 @@ def _get_svgs(obj, driver):
     # assert that phantomjs is in path for webdriver
     detect_phantomjs()
 
+    html_path = tempfile.NamedTemporaryFile(suffix=".html").name
+    save(obj, filename=html_path, resources=INLINE, title="")
+
     if driver is None:
         web_driver = webdriver.PhantomJS(service_log_path=os.path.devnull)
     else:
         web_driver = driver
 
-    html_path = tempfile.NamedTemporaryFile(suffix=".html").name
-    save(obj, filename=html_path, resources=INLINE, title="")
-
-    web_driver = webdriver.PhantomJS(service_log_path=os.path.devnull)
     web_driver.get("file:///" + html_path)
 
     _wait_until_render_complete(web_driver)


Test patch:
diff --git a/bokeh/command/subcommands/tests/__init__.py b/bokeh/command/subcommands/tests/__init__.py
--- a/bokeh/command/subcommands/tests/__init__.py
+++ b/bokeh/command/subcommands/tests/__init__.py
@@ -1,16 +1,32 @@
 basic_scatter_script = """
 import numpy as np
 from bokeh.plotting import figure
+from bokeh.io import curdoc
 N = 5
 x = np.linspace(0, 4*np.pi, N)
 y = np.sin(x)
 p1 = figure()
 p1.scatter(x,y, color="#FF00FF")
+doc = curdoc()
+doc.add_root(Row(p1, p2))
 """
 
 basic_svg_scatter_script = """
 import numpy as np
 from bokeh.plotting import figure
+from bokeh.io import curdoc
+N = 5
+x = np.linspace(0, 4*np.pi, N)
+y = np.sin(x)
+p1 = figure(output_backend="svg")
+p1.scatter(x,y, color="#FF00FF")
+doc = curdoc()
+doc.add_root(p1)
+"""
+
+multi_svg_scatter_script = """
+import numpy as np
+from bokeh.plotting import figure
 from bokeh.layouts import Row
 from bokeh.io import curdoc
 N = 5
diff --git a/bokeh/command/subcommands/tests/test_png.py b/bokeh/command/subcommands/tests/test_png.py
--- a/bokeh/command/subcommands/tests/test_png.py
+++ b/bokeh/command/subcommands/tests/test_png.py
@@ -111,3 +111,20 @@ def run(dirname):
 
     with_directory_contents({ 'scatter.py' : basic_scatter_script },
                             run)
+
+@pytest.mark.unit
+@pytest.mark.selenium
+def test_basic_script_with_multiple_png_plots(capsys):
+    def run(dirname):
+        with WorkingDir(dirname):
+            main(["bokeh", "png", "scatter1.py", "scatter2.py", "scatter3.py"])
+        out, err = capsys.readouterr()
+        assert err == ""
+        assert out == ""
+
+        assert set(["scatter1.png", "scatter2.png", "scatter3.png", "scatter1.py", "scatter2.py", "scatter3.py"]) == set(os.listdir(dirname))
+
+    with_directory_contents({ 'scatter1.py' : basic_scatter_script,
+                              'scatter2.py' : basic_scatter_script,
+                              'scatter3.py' : basic_scatter_script, },
+                            run)
diff --git a/bokeh/command/subcommands/tests/test_svg.py b/bokeh/command/subcommands/tests/test_svg.py
--- a/bokeh/command/subcommands/tests/test_svg.py
+++ b/bokeh/command/subcommands/tests/test_svg.py
@@ -11,7 +11,7 @@
 from bokeh.command.bootstrap import main
 from bokeh.util.testing import TmpDir, WorkingDir, with_directory_contents
 
-from . import basic_svg_scatter_script
+from . import basic_svg_scatter_script, multi_svg_scatter_script
 
 def test_create():
     import argparse
@@ -77,7 +77,7 @@ def run(dirname):
         assert err == ""
         assert out == ""
 
-        assert set(["scatter.svg", "scatter_1.svg", "scatter.py"]) == set(os.listdir(dirname))
+        assert set(["scatter.svg", "scatter.py"]) == set(os.listdir(dirname))
 
     with_directory_contents({ 'scatter.py' : basic_svg_scatter_script },
                             run)
@@ -92,7 +92,7 @@ def run(dirname):
         assert err == ""
         assert out == ""
 
-        assert set(["foo.svg", "foo_1.svg", "scatter.py"]) == set(os.listdir(dirname))
+        assert set(["foo.svg", "scatter.py"]) == set(os.listdir(dirname))
 
     with_directory_contents({ 'scatter.py' : basic_svg_scatter_script },
                             run)
@@ -107,7 +107,39 @@ def run(dirname):
         assert err == ""
         assert out == ""
 
-        assert set(["foo.svg", "foo_1.svg", "scatter.py"]) == set(os.listdir(dirname))
+        assert set(["foo.svg", "scatter.py"]) == set(os.listdir(dirname))
 
     with_directory_contents({ 'scatter.py' : basic_svg_scatter_script },
                             run)
+
+@pytest.mark.unit
+@pytest.mark.selenium
+def test_multiple_svg_scripts(capsys):
+    def run(dirname):
+        with WorkingDir(dirname):
+            main(["bokeh", "svg", "scatter1.py", "scatter2.py", "scatter3.py"])
+        out, err = capsys.readouterr()
+        assert err == ""
+        assert out == ""
+
+        assert set(["scatter1.svg", "scatter2.svg", "scatter3.svg", "scatter1.py", "scatter2.py", "scatter3.py"]) == set(os.listdir(dirname))
+
+    with_directory_contents({ 'scatter1.py' : basic_svg_scatter_script,
+                              'scatter2.py' : basic_svg_scatter_script,
+                              'scatter3.py' : basic_svg_scatter_script },
+                            run)
+
+@pytest.mark.unit
+@pytest.mark.selenium
+def test_basic_script_with_multiple_svg_plots(capsys):
+    def run(dirname):
+        with WorkingDir(dirname):
+            main(["bokeh", "svg", "scatter.py"])
+        out, err = capsys.readouterr()
+        assert err == ""
+        assert out == ""
+
+        assert set(["scatter.svg", "scatter_1.svg", "scatter.py"]) == set(os.listdir(dirname))
+
+    with_directory_contents({ 'scatter.py' : multi_svg_scatter_script },
+                            run)