A script to remove whitespaces and other funky characters from filenames.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

from string import punctuation, whitespace
from os.path import dirname
import pytest
from normalisename import Normalisename
# pylint: disable=redefined-outer-name
SEP = '_'
WHLI = {'.', '-'}
OP = None
def normalise():
return Normalisename(SEP, WHLI, OP)
'before, after', [
) for ws in whitespace
def test_replace_whitespaces_with_separator(normalise, before, after):
assert normalise(before) == after
def test_remove_funky_characters(normalise):
assert normalise(''.join(set(punctuation).difference(WHLI.union({SEP, '/'})))) == ''
def test_remove_accent_from_letters(normalise):
assert normalise('éáűöüóőú') == 'eauouoou'
'path', [
'/home/user/Desktop/cica sajt',
'/root/what/big celebration.txt'
def test_dirname_is_not_changed(normalise, path):
assert dirname(normalise(path)) == dirname(path)
def test_name_with_trailing_slash_is_normalised(normalise):
path = '/home/user/Desktop/cat directory/'
assert normalise(path) == f'/home/user/Desktop/cat{SEP}directory'