Skip to content

Commit f07f0a2

Browse files
committed
Leverage pathlib in build_files for simplicity.
1 parent 6cf704f commit f07f0a2

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

importlib_metadata/tests/fixtures.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import unicode_literals
22

3-
import os
43
import sys
54
import shutil
65
import tempfile
@@ -63,7 +62,7 @@ def main():
6362

6463
def setUp(self):
6564
super(DistInfoPkg, self).setUp()
66-
build_files(DistInfoPkg.files, str(self.site_dir))
65+
build_files(DistInfoPkg.files, self.site_dir)
6766

6867

6968
class EggInfoPkg(SiteDir):
@@ -100,10 +99,10 @@ def main():
10099

101100
def setUp(self):
102101
super(EggInfoPkg, self).setUp()
103-
build_files(EggInfoPkg.files, prefix=str(self.site_dir))
102+
build_files(EggInfoPkg.files, prefix=self.site_dir)
104103

105104

106-
def build_files(file_defs, prefix=""):
105+
def build_files(file_defs, prefix=pathlib.Path()):
107106
"""
108107
Build a set of files/directories, as described by the
109108
file_defs dictionary.
@@ -124,17 +123,16 @@ def build_files(file_defs, prefix=""):
124123
}
125124
"""
126125
for name, contents in file_defs.items():
127-
full_name = os.path.join(prefix, name)
126+
full_name = prefix / name
128127
if isinstance(contents, dict):
129-
# Keep makedirs for now. Pathlib later.
130-
os.makedirs(full_name)
128+
full_name.mkdir()
131129
build_files(contents, prefix=full_name)
132130
else:
133131
if isinstance(contents, bytes):
134-
with open(full_name, 'wb') as f:
132+
with full_name.open('wb') as f:
135133
f.write(contents)
136134
else:
137-
with open(full_name, 'w') as f:
135+
with full_name.open('w') as f:
138136
f.write(DALS(contents))
139137

140138

0 commit comments

Comments
 (0)