Ensure that find_files only returns unicode

This commit is contained in:
Thomas Adamcik 2010-10-30 23:12:32 +02:00
parent a078a7448e
commit dd259d0797
2 changed files with 10 additions and 2 deletions

View File

@ -48,12 +48,14 @@ def split_path(path):
def find_files(path):
path = os.path.expanduser(path)
if os.path.isfile(path):
yield os.path.abspath(path)
filename = os.path.abspath(path)
yield filename.decode('utf-8')
else:
for dirpath, dirnames, filenames in os.walk(path):
for filename in filenames:
dirpath = os.path.abspath(dirpath)
yield os.path.join(dirpath, filename)
filename = os.path.join(dirpath, filename)
yield filename.decode('utf-8')
class Mtime(object):
def __init__(self):

View File

@ -133,6 +133,12 @@ class FindFilesTest(unittest.TestCase):
self.assertEqual(len(files), 1)
self.assert_(files[0], data_folder('blank.mp3'))
def test_names_are_unicode(self):
is_unicode = lambda f: isinstance(f, unicode)
for name in self.find(''):
self.assert_(is_unicode(name),
'%s is not unicode object' % repr(name))
def test_expanduser(self):
raise SkipTest