File: test_paths.py

package info (click to toggle)
normality 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 180 kB
  • sloc: python: 1,275; makefile: 17
file content (32 lines) | stat: -rw-r--r-- 1,125 bytes parent folder | download
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
from normality.paths import MAX_LENGTH, safe_filename


def test_safe_filename():
    assert safe_filename(None) is None
    assert safe_filename("test.txt") == "test.txt"
    assert safe_filename("test .txt") == "test.txt"
    assert safe_filename("test bla.txt") == "test_bla.txt"
    assert safe_filename("test_bla.txt") == "test_bla.txt"
    assert safe_filename("test.bla.txt") == "test_bla.txt"
    assert safe_filename("test", extension="txt") == "test.txt"


def test_long_filename():
    long_name = ["long name"] * 100
    long_name = "-".join(long_name)

    shortened = safe_filename(long_name)
    assert shortened is not None
    assert len(shortened) <= MAX_LENGTH, shortened

    shortened = safe_filename(long_name, extension="html")
    assert shortened is not None
    assert len(shortened) <= MAX_LENGTH, shortened

    shortened = safe_filename("bla", extension=long_name)
    assert shortened is not None
    assert len(shortened) <= MAX_LENGTH, shortened

    shortened = safe_filename(long_name, extension=long_name)
    assert shortened is not None
    assert len(shortened) <= MAX_LENGTH, shortened