Skip to content

Commit a1a681e

Browse files
committed
Tests for highlight.js, convert send_ -> _send_ methods
To internal methods. They require port check to work and thus should not be publically used.
1 parent 88d8d73 commit a1a681e

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ def send(self, via, markdown_file):
124124
"Has instant-markdown-d failed to start?"
125125
)
126126

127-
method = getattr(self, f"send_{via}")
127+
method = getattr(self, f"_send_{via}")
128128
method(markdown_file)
129129

130-
def send_stdin(self, markdown_file):
130+
def _send_stdin(self, markdown_file):
131131
logger.info(f"send via stdin {markdown_file}")
132132
with open(markdown_file, "rb") as file:
133133
text = file.read()
@@ -138,7 +138,7 @@ def send_stdin(self, markdown_file):
138138
except subprocess.TimeoutExpired:
139139
pass
140140

141-
def send_curl(self, markdown_file):
141+
def _send_curl(self, markdown_file):
142142
logger.info(f"send via curl using REST API {markdown_file}")
143143

144144
# Equivalent to

tests/test_code.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<span class="test-case"></span>
2+
3+
# Code with Highlight.js
4+
5+
Courtesy: [Rosetta Code](https://rosettacode.org/wiki/Factorial)
6+
7+
## JavaScript / ES6
8+
9+
```js
10+
var factorial = n => (n < 2) ? 1 : n * factorial(n - 1);
11+
```
12+
13+
## Python
14+
15+
```python
16+
def factorial(n):
17+
return n * factorial(n - 1) if n else 1
18+
```
19+
20+
21+
## Vim script
22+
23+
```vim
24+
function! Factorial(n)
25+
if a:n < 2
26+
return 1
27+
else
28+
return a:n * Factorial(a:n-1)
29+
endif
30+
endfunction
31+
```

tests/test_code.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
4+
def test_code(browser, Server):
5+
6+
with Server("--debug", 8090) as srv:
7+
srv.send("curl", "tests/test_code.md")
8+
9+
result = browser.get(srv.port)
10+
11+
assert '<span class="test-case"></span>' in result, "No text was rendered"
12+
13+
elems = browser.find_elements_by_xpath("//pre/code/span")
14+
assert all(
15+
e.get_attribute("class").startswith("hljs-") for e in elems
16+
), "Highlight.js processing not completed"

0 commit comments

Comments
 (0)