Skip to content

Commit

Permalink
use yaxp v0.2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
realtimeprojects committed Sep 6, 2023
1 parent a6ff77f commit 1609d3c
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 85 deletions.
32 changes: 16 additions & 16 deletions tests/test_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
def test_default_config(simple, config):
html = mock.render_single(simple, config)
log.debug(html)
dl = xpath.dl()
dl = dl.has(xpath.dt().has(xpath.a(name="test_first_defs_0", text="first")))
dl = xpath.dl
dl = dl.has(xpath.dt.has(xpath.a(name="test_first_defs_0", text="first")))
dl = dl.has(xpath.dd(text="first term"))
dl = dl.has(xpath.dt().has(xpath.a(name="test_second_defs_0", text="second")))
dl = dl.has(xpath.dt.has(xpath.a(name="test_second_defs_0", text="second")))
dl = dl.has(xpath.dd(text="*second term"))
assert len(html.xpath(str(dl)))

dl = xpath.dl()
dl = dl.has(xpath.dt().has(xpath.a(name="demo_first_defs_0", text="first")))
dl = xpath.dl
dl = dl.has(xpath.dt.has(xpath.a(name="demo_first_defs_0", text="first")))
dl = dl.has(xpath.dd(text="demo 1"))
dl = dl.has(xpath.dt().has(xpath.a(name="demo_second_defs_0", text="second")))
dl = dl.has(xpath.dt.has(xpath.a(name="demo_second_defs_0", text="second")))
dl = dl.has(xpath.dd(text="demo 2"))
assert len(html.xpath(str(dl)))

dl = xpath.dl()
dl = xpath.dl
dl = dl.has(xpath.dd(text="*demo 2").has(xpath.a()))
assert len(html.xpath(str(dl))) == 0

Expand All @@ -33,13 +33,13 @@ def test_inline_refs(simple, config):
config['inline_refs'] = "short"
html = mock.render_single(simple, config)

dl = xpath.dl()
dl = dl.has(xpath.dt().has(xpath.a(name="test_first_defs_0", text="first")))
dl = xpath.dl
dl = dl.has(xpath.dt.has(xpath.a(name="test_first_defs_0", text="first")))
dl = dl.has(xpath.dd(text="*first term").has(xpath.a()))
assert len(html.xpath(str(dl))) == 0

dl = xpath.dl()
dl = dl.has(xpath.dt().has(xpath.a(name="test_third_defs_0", text="third")))
dl = dl.has(xpath.dt.has(xpath.a(name="test_third_defs_0", text="third")))
dl = dl.has(xpath.dd(text="*third term").has(xpath.a(title="Hello",
href="../simple.md#test_third_refs_0",
text="*[1]")))
Expand All @@ -50,18 +50,18 @@ def test_default_section(simple, config):
config['use_default'] = True
html = mock.render_single(simple, config)
log.debug(html)
dl = xpath.dl()
dl = dl.has(xpath.dt().has(xpath.a(name="__default_defs_0", text="default")))
dl = xpath.dl
dl = dl.has(xpath.dt.has(xpath.a(name="__default_defs_0", text="default")))
dl = dl.has(xpath.dd(text="default term"))
assert len(html.xpath(str(dl)))

dl = xpath.dl()
dl = dl.has(xpath.dt().has(xpath.a(name="demo_first_defs_0", text="first")))
dl = xpath.dl
dl = dl.has(xpath.dt.has(xpath.a(name="demo_first_defs_0", text="first")))
dl = dl.has(xpath.dd(text="demo 1"))
dl = dl.has(xpath.dt().has(xpath.a(name="demo_second_defs_0", text="second")))
dl = dl.has(xpath.dt.has(xpath.a(name="demo_second_defs_0", text="second")))
dl = dl.has(xpath.dd(text="demo 2"))
assert len(html.xpath(str(dl)))

dl = xpath.dl()
dl = xpath.dl
dl = dl.has(xpath.dd(text="*demo 2").has(xpath.a()))
assert len(html.xpath(str(dl))) == 0
56 changes: 28 additions & 28 deletions tests/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
def test_link_no_title(simple, config):
html = mock.render_single(simple, config)

dl = xpath.body().p().a(name="test_third_refs_0",
title="",
href="../simple.md#test_third_defs_0",
text="third")
dl = xpath.body.p.a(name="test_third_refs_0",
title="",
href="../simple.md#test_third_defs_0",
text="third")
assert len(html.xpath(str(dl))) == 1


Expand All @@ -21,10 +21,10 @@ def test_link_short_title(simple, config):
html = mock.render_single(simple, config)
log.debug(html)

dl = xpath.body().p().a(name="test_third_refs_0",
title="third term",
href="../simple.md#test_third_defs_0",
text="third")
dl = xpath.body.p.a(name="test_third_refs_0",
title="third term",
href="../simple.md#test_third_defs_0",
text="third")
assert len(html.xpath(str(dl))) == 1


Expand All @@ -33,10 +33,10 @@ def test_link_full_title(simple, config):
html = mock.render_single(simple, config)
log.debug(html)

dl = xpath.body().p().a(name="test_third_refs_0",
title="*detailed description of third term",
href="../simple.md#test_third_defs_0",
text="third")
dl = xpath.body.p.a(name="test_third_refs_0",
title="*detailed description of third term",
href="../simple.md#test_third_defs_0",
text="third")
assert len(html.xpath(str(dl))) == 1


Expand All @@ -45,10 +45,10 @@ def test_link_replace_html(simple, config):
html = mock.render_single(simple, config)
log.debug(html)

dl = xpath.body().p().a(name="test_second_refs_0",
title="*this text is formatted",
href="../simple.md#test_second_defs_0",
text="second")
dl = xpath.body.p.a(name="test_second_refs_0",
title="*this text is formatted",
href="../simple.md#test_second_defs_0",
text="second")
assert len(html.xpath(str(dl))) == 1


Expand All @@ -57,21 +57,21 @@ def test_link_second_ref(simple, summary, config):
summary = mock.render([simple, summary], config)['summary.md']
log.debug(summary)

dl = xpath.body().p().a(name="test_third_refs_1",
title="*third term",
href="../simple.md#test_third_defs_0",
text="third")
dl = xpath.body.p.a(name="test_third_refs_1",
title="*third term",
href="../simple.md#test_third_defs_0",
text="third")
assert len(summary.xpath(str(dl))) == 1


def test_link_default_ref_disabled(simple, summary, config):
summary = mock.render([simple, summary], config)['summary.md']
log.debug(summary)

dl = xpath.body().p().a(name="__default_refs_0",
title="",
href="../simple.md#__default_defs_0",
text="default")
dl = xpath.body.p.a(name="__default_refs_0",
title="",
href="../simple.md#__default_defs_0",
text="default")
assert len(summary.xpath(str(dl))) == 0


Expand All @@ -80,8 +80,8 @@ def test_link_default_ref_enabled(simple, summary, config):
summary = mock.render([simple, summary], config)['summary.md']
log.debug(summary)

dl = xpath.body().p().a(name="__default_refs_0",
title="",
href="../simple.md#__default_defs_0",
text="default")
dl = xpath.body.p.a(name="__default_refs_0",
title="",
href="../simple.md#__default_defs_0",
text="default")
assert len(summary.xpath(str(dl))) == 1
32 changes: 16 additions & 16 deletions tests/test_page_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ def test_page_ref_simple(config):
pages = mock.render([mycommand, commands], config)

dl = xp.dl(_class="#mkdocs-ezglossary-summary", _id="page")
dl = dl.has(xp.dt().a(href="../mycommand.md#",
text="help1"))
dl = dl.has(xp.dt.a(href="../mycommand.md#",
text="help1"))
assert len(pages['commands.md'].xpath(str(dl))) == 1

dd = xp.dd().ul().li().a(href="../commands.md#cmd_help2_refs_0",
text="Commands")
dd = xp.dd.ul.li.a(href="../commands.md#cmd_help2_refs_0",
text="Commands")
dl = xp.dl(_class="mkdocs-ezglossary-summary", _id="cmd")
dl = dl.has(dd)
dl = dl.has(xp.dt().a(text="help2"))
dl = dl.has(xp.dt.a(text="help2"))
assert len(pages['commands.md'].xpath(str(dl))) == 1


Expand All @@ -77,19 +77,19 @@ def test_page_ref_anchor(config):
a = xp.a(href="../mycommand.md#hello",
text="term2")
dl = xp.dl(_class="#mkdocs-ezglossary-summary", _id="page")
dl = dl.has(xp.dt().has(a))
dl = dl.has(xp.dt.has(a))
assert len(pages['commands.md'].xpath(str(dl))) == 1


def test_page_ref_direct(config):
pages = mock.render([mycommand, commands], config)

dd = xp.dd()
dd = xp.dd
a = xp.a(href="../mycommand.md#",
text="cmd2")
dd = dd.has(xp.p(text="*page subtitle"))
dl = xp.dl(_class="#mkdocs-ezglossary-summary", _id="page")
dl = dl.has(xp.dt().has(a))
dl = dl.has(xp.dt.has(a))
dl = dl.has(dd)
assert len(pages['commands.md'].xpath(str(dl))) == 1

Expand All @@ -102,7 +102,7 @@ def test_page_ref_direct_anchor(config):
dd = xp.dd()
dd = dd.has(xp.p(text="*Description of world"))
dl = xp.dl(_class="#mkdocs-ezglossary-summary", _id="page")
dl = dl.has(xp.dt().has(a))
dl = dl.has(xp.dt.has(a))
dl = dl.has(dd)
assert len(pages['commands.md'].xpath(str(dl))) == 1

Expand All @@ -113,7 +113,7 @@ def test_page_ref_default_section(config):
a = xp.a(href="../mycommand.md#",
text="cmd4")
dl = xp.dl(_class="mkdocs-ezglossary-summary", _id="_")
dl = dl.has(xp.dt().has(a))
dl = dl.has(xp.dt.has(a))
assert len(pages['commands.md'].xpath(str(dl))) == 1


Expand All @@ -123,16 +123,16 @@ def test_page_ref_default_section_anchor(config):
a = xp.a(href="../mycommand.md#world2",
text="cmd5")
dl = xp.dl(_class="mkdocs-ezglossary-summary", _id="_")
dl = dl.has(xp.dt().has(a))
dl = dl.has(xp.dt.has(a))
assert len(pages['commands.md'].xpath(str(dl))) == 1


def test_page_ref_link(config):
pages = mock.render([mycommand, commands], config)

dl = xp.body().p().a(_class="mkdocs-ezglossary-link",
name="cmd_help2_refs_0",
title="page subtitle",
href="../mycommand.md#",
text="help2")
dl = xp.body.p.a(_class="mkdocs-ezglossary-link",
name="cmd_help2_refs_0",
title="page subtitle",
href="../mycommand.md#",
text="help2")
assert len(pages['commands.md'].xpath(str(dl))) == 1
46 changes: 22 additions & 24 deletions tests/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,44 @@ def test_summary(simple, summary, config):
a = xp.a(href="../simple.md#test_first_defs_0",
text="first")
dl = xp.dl(_class="mkdocs-ezglossary-summary", _id="test")
dl = dl.has(xp.dt().has(a))
dl = dl.has(xp.dt.has(a))
assert len(summary.xpath(str(dl))) == 1

l1 = xp.a(href="../simple.md#test_first_refs_0")
dl = xp.dl(_class="mkdocs-ezglossary-summary", _id="test")
dl = dl.has(xp.dl().has(a))
dl = dl.has(xp.dl.has(a))
assert len(summary.xpath(str(dl))) == 0

a = xp.a(href="../simple.md#test_third_defs_0",
text="third")
dd = xp.dd()
l1 = xp.ul().li().a(href="../simple.md#test_third_refs_0",
text="Hello")
l2 = xp.ul().li().a(href="../summary.md#test_third_refs_1",
text="Summary")
dd = xp.dd
l1 = xp.ul.li.a(href="../simple.md#test_third_refs_0",
text="Hello")
l2 = xp.ul.li.a(href="../summary.md#test_third_refs_1",
text="Summary")
dd = dd.has(l1)
dd = dd.has(l2)
dl = xp.dl(_class="mkdocs-ezglossary-summary", _id="test")
dl = dl.has(xp.dt().has(a))
dl = dl.has(xp.dt.has(a))
dl = dl.has(dd)
assert len(summary.xpath(str(dl))) == 1

a = xp.a(href="../simple.md#demo_first_defs_0",
text="first")
dl = xp.dl(_class="mkdocs-ezglossary-summary", _id="demo")
dl = dl.has(xp.dt().has(a))
dl = dl.has(xp.dt.has(a))
assert len(summary.xpath(str(dl))) == 1

a = xp.a(href="../simple.md#demo_third_defs_0",
text="third")
dl = xp.dl(_class="mkdocs-ezglossary-summary", _id="demo")
dl = dl.has(xp.dt().has(a))
dl = dl.has(xp.dt.has(a))
assert len(summary.xpath(str(dl))) == 1

a = xp.a(href="../simple.md#demo_third_refs_0",
text="third")
dl = xp.dl(_class="mkdocs-ezglossary-summary", _id="demo")
dl = dl.has(xp.dd().has(a))
dl = dl.has(xp.dd.has(a))
assert len(summary.xpath(str(dl))) == 0


Expand All @@ -66,14 +66,14 @@ def test_summary_noref(simple, summary, config):
a = xp.a(href="../simple.md#test_first_defs_0",
text="first")
dl = xp.dl(_class="mkdocs-ezglossary-summary", _id="test")
dl = dl.has(xp.dt().has(a))
dl = dl.has(xp.dt.has(a))
assert len(summary.xpath(str(dl))) == 1

a = xp.a(href="../simple.md#test_third_refs_0",
text="Hello")
dl = xp.dl(_class="mkdocs-ezglossary-summary", _id="test")
dl = dl.has(xp.dt(text="third"))
dl = dl.has(xp.dd().has(a))
dl = dl.has(xp.dd.has(a))
assert len(summary.xpath(str(dl))) == 0


Expand All @@ -82,8 +82,8 @@ def test_custom_summary(simple, summary, config):
pages = mock.render([simple, summary], config)
summary = pages["summary.md"]

dd = xp.dd().ul().li().a(href="../simple.md#test_third_refs_0",
text="Hello")
dd = xp.dd.ul.li.a(href="../simple.md#test_third_refs_0",
text="Hello")
dl = xp.dl(_class="custom-summary", _id="test")
dl = dl.has(xp.dt(text="third"))
dl = dl.has(dd)
Expand All @@ -99,7 +99,7 @@ def test_default_summary(simple, summary, config):
a = xp.a(href="../simple.md#__default_defs_0",
text="default")
dl = xp.dl(_class="mkdocs-ezglossary-summary", _id="_")
dl = dl.has(xp.dt().has(a))
dl = dl.has(xp.dt.has(a))
assert len(summary.xpath(str(dl))) == 1


Expand All @@ -108,13 +108,11 @@ def test_summary_table(simple, tablesummary, config):
summary = pages["tablesummary.md"]
log.debug(summary)

table = xp.div().table()
table.has(xp.th().has(xp.td(text="Term"))
.has(xp.td(text="Definition"))
.has(xp.td(text="References")))
tr = xp.div().table(_class="mkdocs-ezglossary-summary", _id="demo").tr()
tr = tr.has(xp.td(text="default"))
tr = tr.has(xp.ul().li().a(href="../simple.md#__default_defs_0",
text="Hello"))
table = xp.div(_class="#mkdocs-ezglossary-summary").table(_id="demo")
tr = xp.tr
table = table.has(xp.thead.has(xp.th(text="Term"))
.has(xp.th(text="Definition"))
.has(xp.th(text="References")))
tr = tr.has(xp.td(text="*first"))
table.has(tr)
assert len(summary.xpath(str(table))) == 1
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ testpaths = tests
[testenv:default]
setenv=
deps =
yaxp
yaxp>=0.2.0
mkdocs-material
lxml
pyyaml
Expand Down

0 comments on commit 1609d3c

Please sign in to comment.