1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-12-05 01:23:44 +01:00
svtplay-dl/lib/svtplay_dl/tests/test_text.py

49 lines
1.5 KiB
Python
Raw Normal View History

2016-01-10 14:55:21 +01:00
#!/usr/bin/python
# ex:ts=4:sw=4:sts=4:et:fenc=utf-8
# The unittest framwork doesn't play nice with pylint:
# pylint: disable-msg=C0103
2021-05-10 12:14:30 +02:00
import pathlib
2016-01-10 14:55:21 +01:00
import unittest
2019-08-25 00:40:39 +02:00
2019-08-31 01:02:59 +02:00
from svtplay_dl.utils.parser import setup_defaults
from svtplay_dl.utils.text import decode_html_entities
from svtplay_dl.utils.text import ensure_unicode
2019-08-31 01:02:59 +02:00
from svtplay_dl.utils.text import exclude
from svtplay_dl.utils.text import filenamify
2016-01-10 14:55:21 +01:00
2018-01-30 20:11:37 +01:00
2016-01-10 14:55:21 +01:00
class filenamifyTest(unittest.TestCase):
test_values = [
["foo", "foo"],
["foo bar", "foo.bar"],
["FOO BAR", "foo.bar"],
2019-08-25 00:27:31 +02:00
["foo-bar baz", "foo-bar.baz"],
['Jason "Timbuktu" Diakité', "jason.timbuktu.diakite"],
["Matlagning del 1 av 10 - R\xe4ksm\xf6rg\xe5s | SVT Play", "matlagning.del.1.av.10-raksmorgas.svt.play"],
2019-08-25 00:27:31 +02:00
["$FOOBAR", "foobar"],
2016-01-10 14:55:21 +01:00
]
def test(self):
for inp, ref in self.test_values:
2019-08-31 01:02:59 +02:00
assert filenamify(inp) == ref
def test_exclude_true(self):
config = setup_defaults()
config.set("exclude", "hej")
2021-05-10 12:14:30 +02:00
assert exclude(config, pathlib.Path("hejsanhoppsan"))
2019-08-31 01:02:59 +02:00
def test_exclude_false(self):
config = setup_defaults()
config.set("exclude", "hej")
2021-05-10 12:14:30 +02:00
assert not exclude(config, pathlib.Path("hoppsan"))
2019-08-31 01:02:59 +02:00
def test_exlude_default(self):
config = setup_defaults()
2021-05-10 12:14:30 +02:00
assert not exclude(config, pathlib.Path("hoppsan"))
def test_ensure_unicode(self):
assert ensure_unicode(b"hello") == "hello"
def test_decode_html(self):
assert decode_html_entities("&lt;3 &amp;") == "<3 &"