Fix directories not normalised when trailing slash is present

This commit is contained in:
Kristóf Tóth 2018-09-09 00:54:36 +02:00
parent ad55d4011b
commit 122a59cbb6
2 changed files with 10 additions and 1 deletions

View File

@ -46,13 +46,21 @@ class Normalisename:
return [self.normalise(path) for path in paths]
def normalise(self, path):
path = self.strip_trailing_slash(path)
directory = dirname(path)
filename = basename(path)
normalpath = joinpath(directory, self.normalname(filename))
if path != normalpath:
self.operation(path, normalpath) # pylint: disable=not-callable
return normalpath
@staticmethod
def strip_trailing_slash(path):
if path[-1] == '/':
path = path[:-1]
return path
def normalname(self, filename):
return unidecode(
''.join(

View File

@ -50,4 +50,5 @@ def test_dirname_is_not_changed(normalise, path):
def test_name_with_trailing_slash_is_normalised(normalise):
assert False
path = '/home/user/Desktop/cat directory/'
assert normalise(path) == f'/home/user/Desktop/cat{SEP}directory'