Skip to content

Commit 7bf3645

Browse files
committed
add unittests
1 parent e356426 commit 7bf3645

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/tests_pytorch/accelerators/test_xla.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,24 @@ def test_tpu_device_name():
313313
assert XLAAccelerator.device_name() == tpu.get_tpu_env()[xenv.ACCELERATOR_TYPE]
314314

315315

316+
def test_tpu_device_name_exception(tpu_available, monkeypatch):
317+
from requests.exceptions import HTTPError
318+
319+
monkeypatch.delattr(
320+
lightning.pytorch.accelerators.xla.XLAAccelerator,
321+
"device_name",
322+
raising=False,
323+
)
324+
325+
mock.patch(
326+
"torch_xla._internal.tpu",
327+
"get_tpu_env",
328+
side_effect=HTTPError("Could not fetch TPU device name"),
329+
)
330+
331+
assert XLAAccelerator.device_name() == "True"
332+
333+
316334
@pytest.mark.parametrize(
317335
("devices", "expected_device_ids"),
318336
[

0 commit comments

Comments
 (0)