def create_showcase_nb(cls, force=False): """ Creates a new notebook to showcase a plot class from the showcase template. Parameters ----------- cls: str the name of the class that you want to """ if cls not in [c.__name__ for c in get_plot_classes()]: message = f"We didn't find a plot class with the name '{cls}'" if force: print(message) else: raise ValueError(message) with open(Path(__file__).parent / "Showcase template.ipynb", "r") as f: lines = f.read() with open(Path(__file__).parent.parent / f"{cls}.ipynb", "w") as f: f.write(lines.replace("<$plotclass$>", cls))
from sisl.viz.plotly.tests.test_plot import BasePlotTester from sisl.viz.plotly.plots import * from sisl.viz.plotly.plotutils import get_plot_classes pytestmark = [pytest.mark.viz, pytest.mark.plotly] # Test all plot subclasses with the subclass tester # The following function basically tells pytest to run TestPlotSubClass # once for each plot class. It takes care of setting the PlotClass attribute # to the corresponding plot class. @pytest.fixture(autouse=True, scope="class", params=get_plot_classes()) def plot_class(request): request.cls.PlotClass = request.param class TestPlotSubClass(BasePlotTester): def test_compulsory_methods(self): assert hasattr(self.PlotClass, "_set_data") assert callable(self.PlotClass._set_data) assert hasattr(self.PlotClass, "_plot_type") assert isinstance(self.PlotClass._plot_type, str) def test_param_groups(self):
""" Fills the documentation for a class that inherits from Configurable You just need to use the placeholder %%configurable_settings%% or %%ClassName_configurable_settings%% for more specificity, where ClassName is the name of the class that you want to document. Then, this function replaces that placeholder with the documentation for all the settings. Parameters ----------- cls: the class you want to document. """ filename = inspect.getfile(cls) parameters_docs = "\n ".join( get_parameters_docstrings(cls) .split("\n") ) with open(filename, 'r') as fi: lines = fi.read() new_lines = lines.replace("%%configurable_settings%%", parameters_docs) new_lines = new_lines.replace(f"%%{cls.__name__}_configurable_settings%%", parameters_docs) open(filename, 'w').write(new_lines) if __name__ == "__main__": for cls in [*get_plot_classes(), Plot, MultiplePlot, Animation, SubPlots, Session, *get_session_classes().values()]: fill_class_docs(cls)
You just need to use the placeholder %%configurable_settings%% or %%ClassName_configurable_settings%% for more specificity, where ClassName is the name of the class that you want to document. Then, this function replaces that placeholder with the documentation for all the settings. Parameters ----------- cls: the class you want to document. """ filename = inspect.getfile(cls) parameters_docs = "\n ".join(get_parameters_docstrings(cls).split("\n")) with open(filename, 'r') as fi: lines = fi.read() new_lines = lines.replace("%%configurable_settings%%", parameters_docs) new_lines = new_lines.replace( f"%%{cls.__name__}_configurable_settings%%", parameters_docs) open(filename, 'w').write(new_lines) if __name__ == "__main__": for cls in [ *get_plot_classes(), Plot, MultiplePlot, Animation, SubPlots, Session, *get_session_classes().values() ]: fill_class_docs(cls)