Browse Source

make sure we iterate through possible returns from rglob

main
John-Mark Gurney 2 years ago
parent
commit
33ea645f1d
1 changed files with 27 additions and 5 deletions
  1. +27
    -5
      ui/medashare/btv/__init__.py

+ 27
- 5
ui/medashare/btv/__init__.py View File

@@ -144,11 +144,15 @@ def validate_file(fname):

finddname = glob_escape(torrent['info']['name'].decode(_encoding))

dirname = list(fname.parent.rglob(finddname))[0]
for dirname in fname.parent.rglob(finddname):
tordir = dirname.parent

tordir = dirname.parent

return validate(torrent, tordir)
try:
return validate(torrent, tordir)
except FileNotFoundError as e:
continue
else:
raise FileNotFoundError('unable to find directory for %s' % (repr(fname.name)))

def validate(torrent, basedir):
'''Take a decode torrent file, where it was stored in basedir,
@@ -256,7 +260,25 @@ class _TestCases(unittest.TestCase):

self.make_files(sd, self.origfiledata)

good, bad = validate_file(tf)
origrglob = pathlib.PosixPath.rglob

def _rglob_patch(b):
return ()

with unittest.mock.patch.object(pathlib.PosixPath, 'rglob',
side_effect=_rglob_patch):
self.assertRaisesRegex(FileNotFoundError,
'unable to find directory for \'a.torrent\'',
validate_file, tf)

def _rglob_patch(b):
return list(pathlib.PosixPath(x) for x in
[ 'randomdir', 'somedir' ]) + \
list(origrglob(pathlib.PosixPath('.'), 'somedir'))

with unittest.mock.patch.object(pathlib.PosixPath, 'rglob',
side_effect=_rglob_patch):
good, bad = validate_file(tf)

self.assertFalse(bad)



Loading…
Cancel
Save