@@ -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,13 @@ 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 )
280
- return isinstance (directory , dict )
284
+ return isinstance (self ._resolve (), dict )
281
285
282
286
def is_file (self ) -> bool :
283
- path = pathlib .PurePosixPath (self ._fullname )
284
- directory = functools .reduce (lambda d , p : d [p ], path .parts , fixtures )
285
- return not isinstance (directory , dict )
287
+ return not self .is_dir ()
286
288
287
289
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 )
290
+ contents = self ._resolve ()
290
291
if isinstance (contents , dict ):
291
292
# Filesystem openers raise OSError when attempting to open a directory,
292
293
# and that exception is mirrored here.
0 commit comments