Skip to content

Commit 7182735

Browse files
authored
fix data_ingester_test on Python 3.8 (#3861)
Python 3.8 includes breaking changes to the `os.path.expanduser` method, which no longer reads from the `HOME` environment variable on Windows, but rather uses `USERPROFILE`. This broke the `data_ingester_test.py`, which tries to emulate platform specific expansion by setting `os.environ["HOME"]`. To allow this test to run on both Python 3.8 and before, this change makes the test simulate home directory expansion by setting both environment variables. Manually tested that the test fails before and passes after this change, with `bazel run //tensorboard/backend/event_processing:data_ingester_test`. Note that our Travis config does not use Python 3.8, so our CI does not validate whether this change works. See https://bugs.python.org/issue36264
1 parent 869e2b4 commit 7182735

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

tensorboard/backend/event_processing/data_ingester_test.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,38 +134,52 @@ def testPathWithColonThatComesAfterASlash_isNotConsideredARunName(self):
134134
)
135135

136136
def testExpandsUser(self):
137-
oldhome = os.environ.get("HOME", None)
137+
# USERPROFILE is used for simulating Python 3.8 on Windows.
138+
old_home = os.environ.get("HOME", None)
139+
old_userprofile = os.environ.get("USERPROFILE", None)
138140
try:
139-
os.environ["HOME"] = "/usr/eliza"
141+
test_home_directory = "/usr/eliza"
142+
os.environ["HOME"] = test_home_directory
140143
self.assertPlatformSpecificLogdirParsing(
141144
posixpath, "~/lol/cat~dog", {"/usr/eliza/lol/cat~dog": None}
142145
)
143-
os.environ["HOME"] = r"C:\Users\eliza"
146+
test_home_directory = r"C:\Users\eliza"
147+
os.environ["HOME"] = test_home_directory
148+
os.environ["USERPROFILE"] = test_home_directory
144149
self.assertPlatformSpecificLogdirParsing(
145150
ntpath, r"~\lol\cat~dog", {r"C:\Users\eliza\lol\cat~dog": None}
146151
)
147152
finally:
148-
if oldhome is not None:
149-
os.environ["HOME"] = oldhome
153+
if old_home is not None:
154+
os.environ["HOME"] = old_home
155+
if old_userprofile is not None:
156+
os.environ["USERPROFILE"] = old_userprofile
150157

151158
def testExpandsUserForMultipleDirectories(self):
152-
oldhome = os.environ.get("HOME", None)
159+
# USERPROFILE is used for simulating Python 3.8 on Windows.
160+
old_home = os.environ.get("HOME", None)
161+
old_userprofile = os.environ.get("USERPROFILE", None)
153162
try:
154-
os.environ["HOME"] = "/usr/eliza"
163+
test_home_directory = "/usr/eliza"
164+
os.environ["HOME"] = test_home_directory
155165
self.assertPlatformSpecificLogdirParsing(
156166
posixpath,
157167
"a:~/lol,b:~/cat",
158168
{"/usr/eliza/lol": "a", "/usr/eliza/cat": "b"},
159169
)
160-
os.environ["HOME"] = r"C:\Users\eliza"
170+
test_home_directory = r"C:\Users\eliza"
171+
os.environ["HOME"] = test_home_directory
172+
os.environ["USERPROFILE"] = test_home_directory
161173
self.assertPlatformSpecificLogdirParsing(
162174
ntpath,
163175
r"aa:~\lol,bb:~\cat",
164176
{r"C:\Users\eliza\lol": "aa", r"C:\Users\eliza\cat": "bb"},
165177
)
166178
finally:
167-
if oldhome is not None:
168-
os.environ["HOME"] = oldhome
179+
if old_home is not None:
180+
os.environ["HOME"] = old_home
181+
if old_userprofile is not None:
182+
os.environ["USERPROFILE"] = old_userprofile
169183

170184
def testMultipleDirectories(self):
171185
self.assertPlatformSpecificLogdirParsing(

0 commit comments

Comments
 (0)