os.walk を使用するコードをテストしようとしています。os.walk が返すサンプル (空の) ファイルとディレクトリを格納できる一時的なインメモリ ファイルシステムを作成したいと考えています。これにより、再帰をシミュレートするために os.walk 呼び出しをモックする複雑さが解消されます。
具体的には、テストしたいコードは次のとおりです。
if recursive:
log.debug("Recursively searching for files under %s" % path)
for (dir_path, dirs, files) in os.walk(path):
log.debug("Found %d files in %s: %s" % (len(files), path, files))
for f in [os.path.join(dir_path, f) for f in files
if not re.search(exclude, f)]:
yield f
else:
log.debug("Non-recursively searching for files under %s" % path)
for (dir_path, dirs, files) in os.walk(path):
log.debug("Found %d files in %s: %s" % (len(files), path, files))
for f in [os.path.join(dir_path, f) for f in files
if not re.search(exclude, f)]:
yield f
これはpythonで可能ですか?