Skip to content

Commit

Permalink
Show the right style options with the help function (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximlt authored May 8, 2022
1 parent b2e0a2a commit 04f6dae
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache

# Translations
*.mo
Expand Down
2 changes: 1 addition & 1 deletion hvplot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _get_doc_and_signature(
formatter += "{options}"

# Bokeh is the default backend
backend = hvplot_extension.compatibility or 'bokeh'
backend = hvplot_extension.compatibility or Store.current_backend
if eltype in Store.registry[backend]:
valid_opts = Store.registry[backend][eltype].style_opts
if style:
Expand Down
66 changes: 66 additions & 0 deletions hvplot/tests/testhelp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import hvplot.pandas
import pytest

from holoviews.core import Store
from holoviews.element import Curve


@pytest.fixture
def reset_default_backend():
yield
hvplot.extension('bokeh')
hvplot.extension.compatibility = None


def test_help_style_extension_output(reset_default_backend):
# default, after e.g. import hvplot.pandas
docstring, signature = hvplot._get_doc_and_signature(
cls=hvplot.hvPlot,
kind='line',
completions=False,
docstring=False,
generic=False,
style=True,
signature=None,
)
assert docstring == '\nStyle options\n-------------\n\n' + '\n'.join(sorted(Store.registry['bokeh'][Curve].style_opts))

# The current backend becomes matplotlib
hvplot.extension('matplotlib', 'plotly')
docstring, signature = hvplot._get_doc_and_signature(
cls=hvplot.hvPlot,
kind='line',
completions=False,
docstring=False,
generic=False,
style=True,
signature=None,
)
assert docstring == '\nStyle options\n-------------\n\n' + '\n'.join(sorted(Store.registry['matplotlib'][Curve].style_opts))

# The current backend becomes plotly
hvplot.output(backend='plotly')
docstring, signature = hvplot._get_doc_and_signature(
cls=hvplot.hvPlot,
kind='line',
completions=False,
docstring=False,
generic=False,
style=True,
signature=None,
)
assert docstring == '\nStyle options\n-------------\n\n' + '\n'.join(sorted(Store.registry['plotly'][Curve].style_opts))

def test_help_style_compatibility(reset_default_backend):
# The current backend is plotly but the style options are those of matplotlib
hvplot.extension('plotly', 'matplotlib', compatibility='matplotlib')
docstring, signature = hvplot._get_doc_and_signature(
cls=hvplot.hvPlot,
kind='line',
completions=False,
docstring=False,
generic=False,
style=True,
signature=None,
)
assert docstring == '\nStyle options\n-------------\n\n' + '\n'.join(sorted(Store.registry['matplotlib'][Curve].style_opts))

0 comments on commit 04f6dae

Please sign in to comment.