diff options
| author | 2021-02-03 19:17:50 -0500 | |
|---|---|---|
| committer | 2021-02-03 19:17:50 -0500 | |
| commit | 475d074fd74425efbe783fad08f97f2df0c4909f (patch) | |
| tree | 2acdae53999b3c74b716efa4edb5b40311fa356a /tests/test_slugify.py | |
| parent | cd502d52787f666fff3254d7d7e7578930c813c2 (diff) | |
| parent | 3a0d66f07b112b6d2bdc2b57bbf717a89a351ce6 (diff) | |
Update upstream source from tag 'upstream/8.1.2'
Update to upstream version '8.1.2'
with Debian dir e5e966a9e6010ef70618dc9a61558fa4db35aceb
Diffstat (limited to 'tests/test_slugify.py')
| -rw-r--r-- | tests/test_slugify.py | 120 |
1 files changed, 64 insertions, 56 deletions
diff --git a/tests/test_slugify.py b/tests/test_slugify.py index c910aaa..a60896f 100644 --- a/tests/test_slugify.py +++ b/tests/test_slugify.py @@ -1,65 +1,73 @@ -# -*- coding: utf-8 -*- +"""Test slugify.""" -u"""Test slugify.""" +import pytest -from __future__ import unicode_literals import nikola.utils -def test_ascii(): - """Test an ASCII-only string.""" - o = nikola.utils.slugify(u'hello', lang='en') - assert o == u'hello' - assert isinstance(o, nikola.utils.unicode_str) - - -def test_ascii_dash(): - """Test an ASCII string, with dashes.""" - o = nikola.utils.slugify(u'hello-world', lang='en') - assert o == u'hello-world' - assert isinstance(o, nikola.utils.unicode_str) - - -def test_ascii_fancy(): - """Test an ASCII string, with fancy characters.""" - o = nikola.utils.slugify(u'The quick brown fox jumps over the lazy dog!-123.456', lang='en') - assert o == u'the-quick-brown-fox-jumps-over-the-lazy-dog-123456' - assert isinstance(o, nikola.utils.unicode_str) - - -def test_pl(): - """Test a string with Polish diacritical characters.""" - o = nikola.utils.slugify(u'zażółćgęśląjaźń', lang='pl') - assert o == u'zazolcgeslajazn' - assert isinstance(o, nikola.utils.unicode_str) - - -def test_pl_dash(): - """Test a string with Polish diacritical characters and dashes.""" - o = nikola.utils.slugify(u'zażółć-gęślą-jaźń', lang='pl') - assert o == u'zazolc-gesla-jazn' - - -def test_pl_fancy(): - """Test a string with Polish diacritical characters and fancy characters.""" - o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456', lang='pl') - assert o == u'zazolc-gesla-jazn-123456' - assert isinstance(o, nikola.utils.unicode_str) - - -def test_disarmed(): +@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.""" - nikola.utils.USE_SLUGIFY = False - o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456', lang='pl') - assert o == u'Zażółć gęślą jaźń!-123.456' - assert isinstance(o, nikola.utils.unicode_str) - nikola.utils.USE_SLUGIFY = True + o = nikola.utils.slugify(title, lang="pl") + assert o == expected_slug + assert isinstance(o, str) -def test_disarmed_weird(): - """Test disarmed slugify with banned characters.""" +@pytest.fixture +def disarm_slugify(): nikola.utils.USE_SLUGIFY = False - o = nikola.utils.slugify(u'Zażółć gęślą jaźń!-123.456 "Hello World"?#H<e>l/l\\o:W\'o\rr*l\td|!\n', lang='pl') - assert o == u'Zażółć gęślą jaźń!-123.456 -Hello World---H-e-l-l-o-W-o-r-l-d-!-' - assert isinstance(o, nikola.utils.unicode_str) - nikola.utils.USE_SLUGIFY = True + try: + yield + finally: + nikola.utils.USE_SLUGIFY = True |
