1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
"""Test slugify."""
import pytest
import nikola.utils
@pytest.mark.parametrize(
"title, language, expected_slug",
[
pytest.param("hello", "en", "hello", id="ASCII"),
pytest.param("hello-world", "en", "hello-world", id="ASCII with dashes"),
pytest.param("hello world", "en", "hello-world", id="ASCII two words"),
pytest.param("Hello World", "en", "hello-world", id="ASCII uppercase"),
pytest.param(
"The quick brown fox jumps over the lazy dog!-123.456",
"en",
"the-quick-brown-fox-jumps-over-the-lazy-dog-123456",
id="ASCII with fancy characters",
),
pytest.param(
"zażółćgęśląjaźń",
"pl",
"zazolcgeslajazn",
id="Polish diacritical characters",
),
pytest.param(
"zażółć-gęślą-jaźń",
"pl",
"zazolc-gesla-jazn",
id="Polish diacritical characters and dashes",
),
pytest.param(
"Zażółć gęślą jaźń!-123.456",
"pl",
"zazolc-gesla-jazn-123456",
id="Polish diacritical characters and fancy characters",
),
],
)
def test_slugify(title, language, expected_slug):
o = nikola.utils.slugify(title, lang=language)
assert o == expected_slug
assert isinstance(o, str)
@pytest.mark.parametrize(
"title, expected_slug",
[
pytest.param(
u"Zażółć gęślą jaźń!-123.456", u"Zażółć gęślą jaźń!-123.456", id="polish"
),
pytest.param(
u'Zażółć gęślą jaźń!-123.456 "Hello World"?#H<e>l/l\\o:W\'o\rr*l\td|!\n',
u"Zażółć gęślą jaźń!-123.456 -Hello World---H-e-l-l-o-W-o-r-l-d-!-",
id="polish with banned characters",
),
],
)
def test_disarmed(disarm_slugify, title, expected_slug):
"""Test disarmed slugify."""
o = nikola.utils.slugify(title, lang="pl")
assert o == expected_slug
assert isinstance(o, str)
@pytest.fixture
def disarm_slugify():
nikola.utils.USE_SLUGIFY = False
try:
yield
finally:
nikola.utils.USE_SLUGIFY = True
|