util: Strip file:// from local urls

Make sure that the function returns a path even for local files
specified by file:// urls.

JIRA: RHELCMP-5340
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2021-05-06 12:37:01 +02:00
parent c27bfe0c59
commit 7fe32ae758
2 changed files with 7 additions and 0 deletions

View File

@ -1046,6 +1046,8 @@ def as_local_file(url):
yield local_filename
finally:
os.remove(local_filename)
elif url.startswith("file://"):
yield url[7:]
else:
# Not a remote url, return unchanged.
yield url

View File

@ -1060,3 +1060,8 @@ class TestAsLocalFile(PungiTestCase):
self.assertEqual(fn, self.filename)
self.assertTrue(os.path.exists(self.filename))
self.assertFalse(os.path.exists(self.filename))
def test_file_url(self, urlretrieve):
with util.as_local_file("file:///tmp/foo") as fn:
self.assertEqual(fn, "/tmp/foo")
self.assertEqual(urlretrieve.call_args_list, [])