Skip to content

Commit 054749e

Browse files
committed
Unsuccessful attempt to replicate issue where an inaccessible path raises an exception. Ref #94.
1 parent 6076c9a commit 054749e

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

importlib_metadata/tests/test_main.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# coding: utf-8
22
from __future__ import unicode_literals
33

4+
import os
45
import re
56
import json
67
import pickle
78
import textwrap
8-
import unittest
99
import importlib
10+
import unittest.mock
1011
import importlib_metadata
1112

1213
from . import fixtures
@@ -193,6 +194,41 @@ def test_egg(self):
193194
version('foo')
194195

195196

197+
class MissingSysPath(fixtures.OnSysPath, unittest.TestCase):
198+
site_dir = '/does-not-exist'
199+
200+
def test_discovery(self):
201+
"""
202+
Discovering distributions should succeed even if
203+
there is an invalid path on sys.path.
204+
"""
205+
importlib_metadata.distributions()
206+
207+
208+
class InaccessibleSysPath(fixtures.OnSysPath, unittest.TestCase):
209+
site_dir = '/access-denied'
210+
211+
def listdir(self, target, orig=os.listdir):
212+
"""
213+
Fake listdir raising an exception when access is denied.
214+
"""
215+
if target == self.site_dir:
216+
raise OSError(13, 'Permission denied')
217+
return orig(target)
218+
219+
def setUp(self):
220+
super(InaccessibleSysPath, self).setUp()
221+
self.fixtures.enter_context(
222+
unittest.mock.patch('os.listdir', self.listdir))
223+
224+
def test_discovery(self):
225+
"""
226+
Discovering distributions should succeed even if
227+
there is an invalid path on sys.path.
228+
"""
229+
importlib_metadata.distributions()
230+
231+
196232
class TestEntryPoints(unittest.TestCase):
197233
def __init__(self, *args):
198234
super(TestEntryPoints, self).__init__(*args)

0 commit comments

Comments
 (0)