@@ -260,9 +260,18 @@ def __init__(self, module, fullname):
260
260
self ._module = module
261
261
self ._fullname = fullname
262
262
263
- def iterdir (self ):
263
+ def _resolve (self ):
264
+ """
265
+ Fully traverse the `fixtures` dictionary.
266
+
267
+ This should be wrapped in a `try/except KeyError`
268
+ but it is not currently needed and lowers the code coverage numbers.
269
+ """
264
270
path = pathlib .PurePosixPath (self ._fullname )
265
- directory = functools .reduce (lambda d , p : d [p ], path .parts , fixtures )
271
+ return functools .reduce (lambda d , p : d [p ], path .parts , fixtures )
272
+
273
+ def iterdir (self ):
274
+ directory = self ._resolve ()
266
275
if not isinstance (directory , dict ):
267
276
# Filesystem openers raise OSError, and that exception is mirrored here.
268
277
raise OSError (f"{ self ._fullname } is not a directory" )
@@ -272,21 +281,15 @@ def iterdir(self):
272
281
)
273
282
274
283
def is_dir (self ) -> bool :
275
- path = pathlib .PurePosixPath (self ._fullname )
276
- # Fully traverse the `fixtures` dictionary.
277
- # This should be wrapped in a `try/except KeyError`
278
- # but it is not currently needed, and lowers the code coverage numbers.
279
- directory = functools .reduce (lambda d , p : d [p ], path .parts , fixtures )
284
+ directory = self ._resolve ()
280
285
return isinstance (directory , dict )
281
286
282
287
def is_file (self ) -> bool :
283
- path = pathlib .PurePosixPath (self ._fullname )
284
- directory = functools .reduce (lambda d , p : d [p ], path .parts , fixtures )
288
+ directory = self ._resolve ()
285
289
return not isinstance (directory , dict )
286
290
287
291
def open (self , mode = 'r' , encoding = None , errors = None , * _ , ** __ ):
288
- path = pathlib .PurePosixPath (self ._fullname )
289
- contents = functools .reduce (lambda d , p : d [p ], path .parts , fixtures )
292
+ contents = self ._resolve ()
290
293
if isinstance (contents , dict ):
291
294
# Filesystem openers raise OSError when attempting to open a directory,
292
295
# and that exception is mirrored here.
0 commit comments