Skip to content

Commit 6d02370

Browse files
authored
DOP-1575: Add mongo web shell as a directive (#244)
* DOP-1575: Add mongo web shell as a directive * Put everything into rstspec.toml
1 parent e430549 commit 6d02370

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

snooty/rstspec.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ card_type = ["small", "large"]
1010
output_format = ["html"]
1111
devhub_type = ["article", "quickstart", "how-to", "video", "live"]
1212
charts_theme = ["light", "dark"]
13+
mws_version = ["3.4", "3.6", "4.0", "4.2", "4.4", "latest"]
1314

1415
[directive.default-domain]
1516
argument_type = "string"
@@ -617,6 +618,13 @@ inherit = "_guides-base"
617618
# - second related page}
618619
# """
619620

621+
[directive."mongodb:mongo-web-shell"]
622+
help = """An instance of the web version of a Mongo shell"""
623+
options.version = "mws_version"
624+
example = """.. mongo-web-shell::
625+
${1::version: (string)}
626+
"""
627+
620628
[directive."mongodb:openapi"]
621629
help = """Include a reStructuredText file's contents."""
622630
argument_type = ["path", "uri"]

snooty/test_parser.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,88 @@ def test_toctree() -> None:
18121812
)
18131813

18141814

1815+
def test_mongo_web_shell() -> None:
1816+
path = ROOT_PATH.joinpath(Path("test.rst"))
1817+
project_config = ProjectConfig(ROOT_PATH, "", source="./")
1818+
parser = rstparser.Parser(project_config, JSONVisitor)
1819+
1820+
# Test simple use of mongo-web-shell directive
1821+
page, diagnostics = parse_rst(
1822+
parser,
1823+
path,
1824+
"""
1825+
.. mongo-web-shell::
1826+
""",
1827+
)
1828+
page.finish(diagnostics)
1829+
assert diagnostics == []
1830+
check_ast_testing_string(
1831+
page.ast,
1832+
"""<root>
1833+
<directive domain="mongodb" name="mongo-web-shell"/>
1834+
</root>""",
1835+
)
1836+
1837+
# Test with option
1838+
page, diagnostics = parse_rst(
1839+
parser,
1840+
path,
1841+
"""
1842+
.. mongo-web-shell::
1843+
:version: 4.2
1844+
""",
1845+
)
1846+
page.finish(diagnostics)
1847+
assert diagnostics == []
1848+
check_ast_testing_string(
1849+
page.ast,
1850+
"""<root>
1851+
<directive domain="mongodb" name="mongo-web-shell" version="4.2"/>
1852+
</root>""",
1853+
)
1854+
1855+
# Test with invalid version
1856+
page, diagnostics = parse_rst(
1857+
parser,
1858+
path,
1859+
"""
1860+
.. mongo-web-shell::
1861+
:version: 4.1
1862+
""",
1863+
)
1864+
page.finish(diagnostics)
1865+
assert len(diagnostics) == 1
1866+
assert isinstance(diagnostics[0], DocUtilsParseError)
1867+
1868+
# Test unknown options
1869+
page, diagnostics = parse_rst(
1870+
parser,
1871+
path,
1872+
"""
1873+
.. mongo-web-shell::
1874+
:width: 100%
1875+
:height: 300
1876+
""",
1877+
)
1878+
page.finish(diagnostics)
1879+
assert len(diagnostics) == 1
1880+
assert isinstance(diagnostics[0], DocUtilsParseError)
1881+
1882+
# Test with unwanted content block
1883+
page, diagnostics = parse_rst(
1884+
parser,
1885+
path,
1886+
"""
1887+
.. mongo-web-shell::
1888+
1889+
Hello world. This is unwanted content.
1890+
""",
1891+
)
1892+
page.finish(diagnostics)
1893+
assert len(diagnostics) == 1
1894+
assert isinstance(diagnostics[0], DocUtilsParseError)
1895+
1896+
18151897
def test_callable_target() -> None:
18161898
path = ROOT_PATH.joinpath(Path("test.rst"))
18171899
project_config = ProjectConfig(ROOT_PATH, "", source="./")

0 commit comments

Comments
 (0)