|
10 | 10 | import asyncio
|
11 | 11 | import concurrent
|
12 | 12 | import os
|
| 13 | +import tempfile |
13 | 14 | import time
|
14 | 15 | import unittest
|
15 | 16 | from dataclasses import asdict
|
| 17 | +from pathlib import Path |
16 | 18 | from typing import Dict, List, Mapping, Tuple, Union
|
| 19 | +from unittest import mock |
17 | 20 | from unittest.mock import MagicMock
|
18 | 21 |
|
19 | 22 | import torchx.specs.named_resources_aws as named_resources_aws
|
|
40 | 43 | RoleStatus,
|
41 | 44 | runopt,
|
42 | 45 | runopts,
|
| 46 | + TORCHX_HOME, |
43 | 47 | )
|
44 | 48 |
|
45 | 49 |
|
| 50 | +class TorchXHomeTest(unittest.TestCase): |
| 51 | + # guard against TORCHX_HOME set outside the test |
| 52 | + @mock.patch.dict(os.environ, {}, clear=True) |
| 53 | + def test_TORCHX_HOME_default(self) -> None: |
| 54 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 55 | + user_home = Path(tmpdir) / "sally" |
| 56 | + with mock.patch("pathlib.Path.home", return_value=user_home): |
| 57 | + torchx_home = TORCHX_HOME() |
| 58 | + self.assertEqual(torchx_home, user_home / ".torchx") |
| 59 | + self.assertTrue(torchx_home.exists()) |
| 60 | + |
| 61 | + def test_TORCHX_HOME_override(self) -> None: |
| 62 | + with tempfile.TemporaryDirectory() as tmpdir: |
| 63 | + override_torchx_home = Path(tmpdir) / "test" / ".torchx" |
| 64 | + with mock.patch.dict( |
| 65 | + os.environ, {"TORCHX_HOME": str(override_torchx_home)} |
| 66 | + ): |
| 67 | + torchx_home = TORCHX_HOME() |
| 68 | + conda_pack_out = TORCHX_HOME("conda-pack", "out") |
| 69 | + |
| 70 | + self.assertEqual(override_torchx_home, torchx_home) |
| 71 | + self.assertEqual(torchx_home / "conda-pack" / "out", conda_pack_out) |
| 72 | + |
| 73 | + self.assertTrue(torchx_home.is_dir()) |
| 74 | + self.assertTrue(conda_pack_out.is_dir()) |
| 75 | + |
| 76 | + |
46 | 77 | class AppDryRunInfoTest(unittest.TestCase):
|
47 | 78 | def test_repr(self) -> None:
|
48 | 79 | request_mock = MagicMock()
|
|
0 commit comments