From 8c1eeca83fe0ff9b7801dbdf26af5aef17f20cea Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 5 Feb 2024 11:27:44 -0500 Subject: [PATCH 01/12] Support rendering JSON in a Jupyter Notebook Signed-off-by: Jinzhe Zeng --- dargs/notebook.py | 217 ++++++++++++++++++++++++++++++++++++++++++ docs/conf.py | 2 +- docs/index.rst | 1 + docs/nb.ipynb | 46 +++++++++ docs/requirements.txt | 2 +- 5 files changed, 266 insertions(+), 2 deletions(-) create mode 100644 dargs/notebook.py create mode 100644 docs/nb.ipynb diff --git a/dargs/notebook.py b/dargs/notebook.py new file mode 100644 index 0000000..d21e3a8 --- /dev/null +++ b/dargs/notebook.py @@ -0,0 +1,217 @@ +from typing import List, Union +from IPython.core.display import display, HTML + +from dargs import Argument, Variant +import json +import re + +__all__ = ["JSON"] + +# https://www.w3schools.com/css/css_tooltip.asp +css = """ +""" + + +def JSON(data: Union[dict, str], arg: Union[Argument, List[Argument]]): + """Display JSON data with Argument in the Jupyter Notebook. + + Parameters + ---------- + data : dict or str + The JSON data to be displayed, either JSON string or a dict. + arg : dargs.Argument or list[dargs.Argument] + The Argument that describes the JSON data. + """ + if isinstance(data, str): + data = json.loads(data) + elif isinstance(data, dict): + pass + else: + raise ValueError(f"Unknown type: {type(data)}") + + if isinstance(arg, list): + arg = Argument("data", dtype=dict, sub_fields=arg) + elif isinstance(arg, Argument): + pass + else: + raise ValueError(f"Unknown type: {type(arg)}") + argdata = ArgumentData(data, arg) + buff = [css, r"""
""", argdata.print_html(), "
"] + + display(HTML("".join(buff))) + + +class ArgumentData: + def __init__(self, data: dict, arg: Argument): + self.data = data + self.arg = arg + self.subdata = [] + self._init_subdata() + + def _init_subdata(self): + """Initialize sub ArgumentData.""" + if isinstance(self.data, dict): + sub_fields = self.arg.sub_fields.copy() + # extend subfiles with sub_variants + for vv in self.arg.sub_variants.values(): + choice = self.data.get(vv.flag_name, vv.default_tag) + if choice and choice in vv.choice_dict: + sub_fields.update(vv.choice_dict[choice].sub_fields) + + for kk in self.data: + if kk in sub_fields: + self.subdata.append(ArgumentData(self.data[kk], sub_fields[kk])) + elif kk in self.arg.sub_variants: + self.subdata.append( + ArgumentData(self.data[kk], self.arg.sub_variants[kk]) + ) + else: + self.subdata.append(ArgumentData(self.data[kk], kk)) + + def print_html(self, _level=0, _last_one=True): + linebreak = "
" + indent = ( + r"""""" + + " " * (_level * 2) + + "" + ) + buff = [] + buff.append(indent) + if _level > 0: + if isinstance(self.arg, (Argument, Variant)): + buff.append(r"""""") + else: + buff.append(r"""""") + buff.append(r"""""") + buff.append('"') + if isinstance(self.arg, Argument): + buff.append(self.arg.name) + elif isinstance(self.arg, Variant): + buff.append(self.arg.flag_name) + elif isinstance(self.arg, str): + buff.append(self.arg) + else: + raise ValueError(f"Unknown type: {type(self.arg)}") + buff.append('"') + buff.append("") + if isinstance(self.arg, (Argument, Variant)): + buff.append(r"""""") + if isinstance(self.arg, Argument): + doc_head = ( + self.arg.gen_doc_head() + .replace("| type:", "type:") + .replace("\n", linebreak) + ) + # use re to replace ``xx`` to xx + doc_head = re.sub( + r"``(.*?)``", r'\1', doc_head + ) + doc_head = re.sub(r"\*(.+)\*", r"\1", doc_head) + buff.append(doc_head) + elif isinstance(self.arg, Variant): + buff.append(f"{self.arg.flag_name}:
type: ") + buff.append(r"""""") + buff.append("str") + buff.append(r"""""") + if self.arg.default_tag: + buff.append(", default: ") + buff.append(r"""""") + buff.append(self.arg.default_tag) + buff.append(r"""""") + else: + raise ValueError(f"Unknown type: {type(self.arg)}") + + buff.append(linebreak) + buff.append(linebreak) + doc_body = self.arg.doc.strip() + doc_body = re.sub(r"""\n+""", "\n", doc_body) + doc_body = doc_body.replace("\n", linebreak) + doc_body = re.sub( + r"`+(.*?)`+", r'\1', doc_body + ) + doc_body = re.sub(r"\*(.+)\*", r"\1", doc_body) + buff.append(doc_body) + + buff.append(r"""
""") + buff.append(r"""""") + buff.append(": ") + buff.append("") + if self.subdata: + buff.append(r"""""") + buff.append("{") + buff.append("") + buff.append(linebreak) + for ii, sub in enumerate(self.subdata): + buff.append(sub.print_html(_level + 1, _last_one=(ii == len(self.subdata) - 1))) + buff.append(indent) + buff.append(r"""""") + buff.append("}") + if not _last_one: + buff.append(",") + buff.append("") + buff.append(linebreak) + else: + buff.append(r"""""") + buff.append( + json.dumps(self.data, indent=2).replace("\n", f"{linebreak}{indent}") + ) + if not _last_one: + buff.append(",") + buff.append("") + buff.append(linebreak) + return "".join(buff) diff --git a/docs/conf.py b/docs/conf.py index 4bebdaa..aa65b81 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -46,7 +46,7 @@ "sphinx.ext.viewcode", "sphinx.ext.intersphinx", "numpydoc", - "myst_parser", + "myst_nb", "dargs.sphinx", ] diff --git a/docs/index.rst b/docs/index.rst index 482500d..5d6f0f2 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -13,6 +13,7 @@ Welcome to dargs's documentation! intro sphinx dpgui + nb api/api credits diff --git a/docs/nb.ipynb b/docs/nb.ipynb new file mode 100644 index 0000000..4934a34 --- /dev/null +++ b/docs/nb.ipynb @@ -0,0 +1,46 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Use with Jupyter Notebook\n", + "\n", + "In a [Jupyter Notebook](https://jupyter.org/), with {meth}`dargs.notebook.JSON`, one can render an JSON string with an Argument." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from dargs.sphinx import _test_argument\n", + "from dargs.notebook import JSON\n", + "\n", + "jstr = \"\"\"\n", + "{\n", + " \"test_argument\": \"test1\",\n", + " \"test_variant\": \"test_variant_argument\",\n", + " \"_comment\": \"This is an example data\"\n", + "}\n", + "\"\"\"\n", + "JSON(jstr, _test_argument())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "When the monse stays on an argument key, the documentation of this argument will pop up." + ] + } + ], + "metadata": { + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/docs/requirements.txt b/docs/requirements.txt index 54fdba7..d2c7bc5 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,5 @@ . numpydoc deepmodeling_sphinx>=0.1.1 -myst_parser +myst-nb sphinx_rtd_theme From 05dbf49038499a0134c5e0d6ed157357e22f9e24 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Feb 2024 10:12:14 +0000 Subject: [PATCH 02/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dargs/notebook.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/dargs/notebook.py b/dargs/notebook.py index d21e3a8..ae05b6e 100644 --- a/dargs/notebook.py +++ b/dargs/notebook.py @@ -53,7 +53,7 @@ background-color: black; color: #fff; padding: 1em 1em; - border-radius: 6px; + border-radius: 6px; position: absolute; z-index: 1; } @@ -159,7 +159,9 @@ def print_html(self, _level=0, _last_one=True): ) # use re to replace ``xx`` to xx doc_head = re.sub( - r"``(.*?)``", r'\1', doc_head + r"``(.*?)``", + r'\1', + doc_head, ) doc_head = re.sub(r"\*(.+)\*", r"\1", doc_head) buff.append(doc_head) @@ -175,7 +177,7 @@ def print_html(self, _level=0, _last_one=True): buff.append(r"""
""") else: raise ValueError(f"Unknown type: {type(self.arg)}") - + buff.append(linebreak) buff.append(linebreak) doc_body = self.arg.doc.strip() @@ -197,7 +199,9 @@ def print_html(self, _level=0, _last_one=True): buff.append("") buff.append(linebreak) for ii, sub in enumerate(self.subdata): - buff.append(sub.print_html(_level + 1, _last_one=(ii == len(self.subdata) - 1))) + buff.append( + sub.print_html(_level + 1, _last_one=(ii == len(self.subdata) - 1)) + ) buff.append(indent) buff.append(r"""""") buff.append("}") From 04319b38947e6da485dc4911611e3a42508ebf39 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 5 Feb 2024 12:32:39 -0500 Subject: [PATCH 03/12] bugfix Signed-off-by: Jinzhe Zeng --- dargs/notebook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dargs/notebook.py b/dargs/notebook.py index ae05b6e..45cb942 100644 --- a/dargs/notebook.py +++ b/dargs/notebook.py @@ -105,7 +105,7 @@ def __init__(self, data: dict, arg: Argument): def _init_subdata(self): """Initialize sub ArgumentData.""" - if isinstance(self.data, dict): + if isinstance(self.data, dict) and isinstance(self.arg, Argument): sub_fields = self.arg.sub_fields.copy() # extend subfiles with sub_variants for vv in self.arg.sub_variants.values(): From 1f12d0672abe08637ef5792b434faa7229d483de Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 5 Feb 2024 12:41:26 -0500 Subject: [PATCH 04/12] support repeat Signed-off-by: Jinzhe Zeng --- dargs/notebook.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/dargs/notebook.py b/dargs/notebook.py index 45cb942..9077bed 100644 --- a/dargs/notebook.py +++ b/dargs/notebook.py @@ -122,6 +122,13 @@ def _init_subdata(self): ) else: self.subdata.append(ArgumentData(self.data[kk], kk)) + elif ( + isinstance(self.data, list) + and isinstance(self.arg, Argument) + and self.arg.repeat + ): + for dd in self.data: + self.subdata.append(ArgumentData(dd, self.arg)) def print_html(self, _level=0, _last_one=True): linebreak = "
" @@ -132,7 +139,11 @@ def print_html(self, _level=0, _last_one=True): ) buff = [] buff.append(indent) - if _level > 0: + if _level > 0 and not ( + isinstance(self.data, dict) + and isinstance(self.arg, Argument) + and self.arg.repeat + ): if isinstance(self.arg, (Argument, Variant)): buff.append(r"""""") else: @@ -193,7 +204,7 @@ def print_html(self, _level=0, _last_one=True): buff.append(r"""""") buff.append(": ") buff.append("") - if self.subdata: + if self.subdata and isinstance(self.data, dict): buff.append(r"""""") buff.append("{") buff.append("") @@ -209,6 +220,22 @@ def print_html(self, _level=0, _last_one=True): buff.append(",") buff.append("
") buff.append(linebreak) + elif self.subdata and isinstance(self.data, list): + buff.append(r"""""") + buff.append("[") + buff.append("") + buff.append(linebreak) + for ii, sub in enumerate(self.subdata): + buff.append( + sub.print_html(_level + 1, _last_one=(ii == len(self.subdata) - 1)) + ) + buff.append(indent) + buff.append(r"""""") + buff.append("]") + if not _last_one: + buff.append(",") + buff.append("") + buff.append(linebreak) else: buff.append(r"""""") buff.append( From 78b56a39237ea57506d95f38bcfe084023082a67 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 5 Feb 2024 12:43:52 -0500 Subject: [PATCH 05/12] use
Signed-off-by: Jinzhe Zeng --- dargs/notebook.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dargs/notebook.py b/dargs/notebook.py index 9077bed..9ffc74c 100644 --- a/dargs/notebook.py +++ b/dargs/notebook.py @@ -189,9 +189,9 @@ def print_html(self, _level=0, _last_one=True): else: raise ValueError(f"Unknown type: {type(self.arg)}") - buff.append(linebreak) - buff.append(linebreak) doc_body = self.arg.doc.strip() + if doc_body: + buff.append("
") doc_body = re.sub(r"""\n+""", "\n", doc_body) doc_body = doc_body.replace("\n", linebreak) doc_body = re.sub( From 64710b732841b27568dc89bb9e2e5b2703d8ef4e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Feb 2024 22:39:32 +0000 Subject: [PATCH 06/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dargs/notebook.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dargs/notebook.py b/dargs/notebook.py index 9ffc74c..cca74f4 100644 --- a/dargs/notebook.py +++ b/dargs/notebook.py @@ -1,9 +1,10 @@ +import json +import re from typing import List, Union -from IPython.core.display import display, HTML + +from IPython.core.display import HTML, display from dargs import Argument, Variant -import json -import re __all__ = ["JSON"] From f6302b235cffc6f4ca22f813e3610db366cea464 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 7 Feb 2024 17:47:59 -0500 Subject: [PATCH 07/12] add doc Signed-off-by: Jinzhe Zeng --- dargs/notebook.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/dargs/notebook.py b/dargs/notebook.py index cca74f4..f10334a 100644 --- a/dargs/notebook.py +++ b/dargs/notebook.py @@ -1,3 +1,22 @@ +r'''IPython/Jupyter Notebook display for dargs. + +It is expected to be used in Jupyter Notebook, where +the IPython module is available. + +Examples +-------- +>>> from dargs.sphinx import _test_argument +>>> from dargs.notebook import JSON +>>> jstr = """ +... { +... "test_argument": "test1", +... "test_variant": "test_variant_argument", +... "_comment": "This is an example data" +... } +... """ +>>> JSON(jstr, _test_argument()) +''' + import json import re from typing import List, Union @@ -98,6 +117,18 @@ def JSON(data: Union[dict, str], arg: Union[Argument, List[Argument]]): class ArgumentData: + """ArgumentData is a class to hold the data and Argument. + + It is used to print the data with Argument in the Jupyter Notebook. + + Parameters + ---------- + data : dict + The data to be displayed. + arg : dargs.Argument + The Argument that describes the data. + """ + def __init__(self, data: dict, arg: Argument): self.data = data self.arg = arg @@ -132,6 +163,15 @@ def _init_subdata(self): self.subdata.append(ArgumentData(dd, self.arg)) def print_html(self, _level=0, _last_one=True): + """Print the data with Argument in HTML format. + + Parameters + ---------- + _level : int, optional + The level of indentation, by default 0 + _last_one : bool, optional + Whether it is the last one, by default True + """ linebreak = "
" indent = ( r"""""" From 59a2dbaa3c93ee3f1e96aa998fbbf5fea30175f6 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 7 Feb 2024 17:54:05 -0500 Subject: [PATCH 08/12] add more test items Signed-off-by: Jinzhe Zeng --- dargs/sphinx.py | 20 +++++++++++++++++++- docs/nb.ipynb | 4 ++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/dargs/sphinx.py b/dargs/sphinx.py index 2c7aa82..986f743 100644 --- a/dargs/sphinx.py +++ b/dargs/sphinx.py @@ -176,7 +176,25 @@ def _test_argument() -> Argument: "test_variant", doc=doc_test, choices=[ - Argument("test_variant_argument", dtype=str, doc=doc_test), + Argument( + "test_variant_argument", + dtype=dict, + optional=True, + doc=doc_test, + sub_fields=[ + Argument( + "test_repeat", + dtype=list, + repeat=True, + doc=doc_test, + sub_fields=[ + Argument( + "test_repeat_item", dtype=bool, doc=doc_test + ), + ], + ) + ], + ), ], ), ], diff --git a/docs/nb.ipynb b/docs/nb.ipynb index 4934a34..1793515 100644 --- a/docs/nb.ipynb +++ b/docs/nb.ipynb @@ -22,6 +22,10 @@ "{\n", " \"test_argument\": \"test1\",\n", " \"test_variant\": \"test_variant_argument\",\n", + " \"test_repeat\": [\n", + " {\"test_repeat_item\": false},\n", + " {\"test_repeat_item\": true}\n", + " ],\n", " \"_comment\": \"This is an example data\"\n", "}\n", "\"\"\"\n", From 34b74cafe9449545fa67d29359b58cb825f4d00b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Feb 2024 22:54:39 +0000 Subject: [PATCH 09/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dargs/notebook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dargs/notebook.py b/dargs/notebook.py index f10334a..168990d 100644 --- a/dargs/notebook.py +++ b/dargs/notebook.py @@ -14,7 +14,7 @@ ... "_comment": "This is an example data" ... } ... """ ->>> JSON(jstr, _test_argument()) +>>> JSON(jstr, _test_argument()) ''' import json From 4aeb529bd419e6316e60bee0d744605eec18a0fc Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 7 Feb 2024 18:01:01 -0500 Subject: [PATCH 10/12] import from IPython.display Signed-off-by: Jinzhe Zeng --- dargs/notebook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dargs/notebook.py b/dargs/notebook.py index 168990d..fb3f31c 100644 --- a/dargs/notebook.py +++ b/dargs/notebook.py @@ -21,7 +21,7 @@ import re from typing import List, Union -from IPython.core.display import HTML, display +from IPython.display import HTML, display from dargs import Argument, Variant From 4ca03997d96a02ecc71ad33bea595581fe64fc88 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 7 Feb 2024 18:23:36 -0500 Subject: [PATCH 11/12] add tests; fix unclosed xml Signed-off-by: Jinzhe Zeng --- dargs/notebook.py | 26 ++++++++++++--- pyproject.toml | 5 +++ tests/test_notebook.py | 72 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 tests/test_notebook.py diff --git a/dargs/notebook.py b/dargs/notebook.py index fb3f31c..30b9708 100644 --- a/dargs/notebook.py +++ b/dargs/notebook.py @@ -97,6 +97,24 @@ def JSON(data: Union[dict, str], arg: Union[Argument, List[Argument]]): arg : dargs.Argument or list[dargs.Argument] The Argument that describes the JSON data. """ + display(HTML(print_html(data, arg))) + + +def print_html(data: Union[dict, str], arg: Union[Argument, List[Argument]]) -> str: + """Print HTML string with Argument in the Jupyter Notebook. + + Parameters + ---------- + data : dict or str + The JSON data to be displayed, either JSON string or a dict. + arg : dargs.Argument or list[dargs.Argument] + The Argument that describes the JSON data. + + Returns + ------- + str + The HTML string. + """ if isinstance(data, str): data = json.loads(data) elif isinstance(data, dict): @@ -111,9 +129,8 @@ def JSON(data: Union[dict, str], arg: Union[Argument, List[Argument]]): else: raise ValueError(f"Unknown type: {type(arg)}") argdata = ArgumentData(data, arg) - buff = [css, r"""
""", argdata.print_html(), "
"] - - display(HTML("".join(buff))) + buff = [css, r"""
""", argdata.print_html(), r"
"] + return "".join(buff) class ArgumentData: @@ -241,7 +258,8 @@ def print_html(self, _level=0, _last_one=True): doc_body = re.sub(r"\*(.+)\*", r"\1", doc_body) buff.append(doc_body) - buff.append(r"""""") + buff.append(r"""""") + buff.append(r"""""") buff.append(r"""""") buff.append(": ") buff.append("") diff --git a/pyproject.toml b/pyproject.toml index ab89bf1..0a6b0fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,6 +27,11 @@ Homepage = "https://github.com/deepmodeling/dargs" documentation = "https://docs.deepmodeling.com/projects/dargs" repository = "https://github.com/deepmodeling/dargs" +[project.optional-dependencies] +test = [ + "ipython", +] + [tool.setuptools.packages.find] include = ["dargs*"] diff --git a/tests/test_notebook.py b/tests/test_notebook.py new file mode 100644 index 0000000..f674c20 --- /dev/null +++ b/tests/test_notebook.py @@ -0,0 +1,72 @@ +import unittest +from xml.etree import ElementTree as ET + +from dargs import Argument, Variant + +try: + import IPython # noqa: F401 +except ImportError: + ipython_installed = False +else: + ipython_installed = True + + +@unittest.skipUnless(ipython_installed, "IPython not installed") +class TestNotebook(unittest.TestCase): + def test_html_validation(self): + from dargs.notebook import print_html + + doc_test = "Test doc." + test_arg = Argument( + name="test", + dtype=str, + doc=doc_test, + sub_fields=[ + Argument("test_argument", dtype=str, doc=doc_test, default="test"), + ], + sub_variants=[ + Variant( + "test_variant", + doc=doc_test, + choices=[ + Argument( + "test_variant_argument", + dtype=dict, + optional=True, + doc=doc_test, + sub_fields=[ + Argument( + "test_repeat", + dtype=list, + repeat=True, + doc=doc_test, + sub_fields=[ + Argument( + "test_repeat_item", dtype=bool, doc=doc_test + ), + ], + ) + ], + ), + ], + ), + ], + ) + jdata = { + "test_argument": "test1", + "test_variant": "test_variant_argument", + "test_repeat": [ + {"test_repeat_item": False}, + {"test_repeat_item": True} + ], + "_comment": "This is an example data" + } + html = print_html( + jdata, test_arg, + ) + # https://stackoverflow.com/a/29533744/9567349 + # https://stackoverflow.com/a/35591479/9567349 + magic = ''' + ]>''' + ET.fromstring(magic + f"{html}") \ No newline at end of file From 579eff6d05864365b5286afcd157c3c72c2b0ae6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 7 Feb 2024 23:23:54 +0000 Subject: [PATCH 12/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_notebook.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/test_notebook.py b/tests/test_notebook.py index f674c20..01e46a7 100644 --- a/tests/test_notebook.py +++ b/tests/test_notebook.py @@ -52,21 +52,19 @@ def test_html_validation(self): ), ], ) - jdata = { + jdata = { "test_argument": "test1", "test_variant": "test_variant_argument", - "test_repeat": [ - {"test_repeat_item": False}, - {"test_repeat_item": True} - ], - "_comment": "This is an example data" + "test_repeat": [{"test_repeat_item": False}, {"test_repeat_item": True}], + "_comment": "This is an example data", } html = print_html( - jdata, test_arg, + jdata, + test_arg, ) # https://stackoverflow.com/a/29533744/9567349 # https://stackoverflow.com/a/35591479/9567349 - magic = ''' - ]>''' - ET.fromstring(magic + f"{html}") \ No newline at end of file + ]>""" + ET.fromstring(magic + f"{html}")