Skip to content

Commit 63eb109

Browse files
Test build (#65)
1 parent 57ec84d commit 63eb109

3 files changed

Lines changed: 59 additions & 11 deletions

File tree

‎src/mkdocs/extensions/relative_urls.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import markdown
22
import mkdocs
33
import os
4-
import posixpath
5-
import httpx
4+
import hip
65

76

87
class URLProcessor(markdown.treeprocessors.Treeprocessor):
@@ -26,7 +25,7 @@ def run(self, root):
2625

2726
if link:
2827
el.set(key, link)
29-
url = httpx.URL(link)
28+
url = hip.URL(link)
3029
# We want to rewrite relative links... '/page'
3130
# We don't want to rewrite external links. 'https://elsewhere.com/here'
3231
# We don't want to rewrite anchor links. '#section'

‎src/mkdocs/mkdocs.py‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,15 @@ def build(self, input, output):
251251
input_dir = pathlib.Path(input)
252252
output_dir = pathlib.Path(output)
253253

254-
print(DARK_GRAY + "Collected %d resources" % len(self.site) + RESET)
254+
click.echo(
255+
click.style("Collected %d resources" % len(self.site), fg='bright_black')
256+
)
255257
for page in self.site.pages:
256-
print(GREEN + " + " + RESET + BOLD + str(page.path) + RESET + DARK_GRAY + " [markdown]" + RESET)
258+
click.echo(
259+
click.style(" + ", fg='green') +
260+
click.style(str(page.path), bold=True) +
261+
click.style(" [markdown]", fg='bright_black')
262+
)
257263
input_path = input_dir.joinpath(page.path)
258264
output_path = output_dir.joinpath(page.build_path)
259265

@@ -268,7 +274,11 @@ def build(self, input, output):
268274
output_path.write_text(output)
269275

270276
for static in self.site.statics:
271-
print(GREEN + " + " + RESET + BOLD + str(static.path) + RESET + DARK_GRAY + " [static]" + RESET)
277+
click.echo(
278+
click.style(" + ", fg='green') +
279+
click.style(str(static.path), bold=True) +
280+
click.style(" [static]", fg='bright_black')
281+
)
272282
input_path = input_dir.joinpath(static.path)
273283
output_path = output_dir.joinpath(static.path)
274284

@@ -278,12 +288,22 @@ def build(self, input, output):
278288
def serve(self, input):
279289
input_dir = pathlib.Path(input)
280290

281-
print(DARK_GRAY + "Serving %d resources" % len(self.site) + RESET)
291+
click.echo(
292+
click.style("Serving %d resources" % len(self.site), fg='bright_black')
293+
)
282294
for page in self.site.pages:
283-
print(GREEN + " + " + RESET + BOLD + str(page.url) + RESET + DARK_GRAY + " [markdown]" + RESET)
295+
click.echo(
296+
click.style(" + ", fg='green') +
297+
click.style(str(page.url), bold=True) +
298+
click.style(" [markdown]", fg='bright_black')
299+
)
284300
for static in self.site.statics:
285-
print(GREEN + " + " + RESET + BOLD + str(static.url) + RESET + DARK_GRAY + " [static]" + RESET)
286-
print()
301+
click.echo(
302+
click.style(" + ", fg='green') +
303+
click.style(str(static.url), bold=True) +
304+
click.style(" [static]", fg='bright_black')
305+
)
306+
click.echo()
287307

288308
def app(request):
289309
resource = self.site.lookup_by_url(request.url.path)

‎tests/test_mkdocs.py‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from click.testing import CliRunner
2+
import os
23
import mkdocs
4+
import pathlib
35

46

5-
def test_mkdocs():
7+
def test_mkdocs_help():
68
runner = CliRunner()
79
result = runner.invoke(mkdocs.mkdocs, ['--help'])
810
assert result.exit_code == 0
@@ -16,3 +18,30 @@ def test_mkdocs():
1618
' build\n'
1719
' serve\n'
1820
)
21+
22+
23+
def test_mkdocs_build(tmp_path: pathlib.Path):
24+
# Setup
25+
os.chdir(tmp_path)
26+
27+
docs = tmp_path / "docs"
28+
docs.mkdir()
29+
30+
readme = docs / "README.md"
31+
readme.write_text("# README\n\nhello world!\n")
32+
33+
site = tmp_path / "site"
34+
35+
homepage = site / "index.html"
36+
37+
# Test
38+
runner = CliRunner()
39+
result = runner.invoke(mkdocs.mkdocs, ['build'])
40+
assert result.exit_code == 0
41+
assert result.output == (
42+
'Collected 1 resources\n'
43+
' + README.md [markdown]\n'
44+
)
45+
assert site.exists()
46+
assert homepage.exists()
47+
assert "<p>hello world!</p>" in homepage.read_text()

0 commit comments

Comments
 (0)