Browse Source

Fix directories not normalised when trailing slash is present

master
Kristóf Tóth 3 years ago
parent
commit
122a59cbb6
  1. 8
      normalisename.py
  2. 3
      test.py

8
normalisename.py

@ -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(

3
test.py

@ -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'
Loading…
Cancel
Save