diff options
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 9dec5a6..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') - 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') - 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') - 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źń') - 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źń') - 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') - 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') - 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') - 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 |
