|
22 | 22 | class TestDownloadUtilities: |
23 | 23 | """Test suite for download utility functions.""" |
24 | 24 |
|
25 | | - def test_get_cache_dir_default(self): |
26 | | - """Test default cache directory.""" |
27 | | - with patch.dict(os.environ, {}, clear=True): |
| 25 | + def test_get_cache_dir_default(self, monkeypatch): |
| 26 | + """Test default cache directory with warning when env vars not set.""" |
| 27 | + # Clear environment |
| 28 | + monkeypatch.delenv("SPINE_CACHE_DIR", raising=False) |
| 29 | + monkeypatch.delenv("SPINE_PROD_BASEDIR", raising=False) |
| 30 | + monkeypatch.delenv("SPINE_BASEDIR", raising=False) |
| 31 | + |
| 32 | + with patch("builtins.print") as mock_print: |
28 | 33 | cache_dir = get_cache_dir() |
| 34 | + # Should warn about missing env vars |
| 35 | + mock_print.assert_called_once() |
| 36 | + assert "WARNING" in str(mock_print.call_args) |
29 | 37 | assert cache_dir == Path.cwd() / "weights" |
30 | 38 |
|
31 | | - def test_get_cache_dir_env_override(self): |
32 | | - """Test cache directory from environment variable.""" |
33 | | - with patch.dict(os.environ, {"SPINE_CACHE_DIR": "/custom/cache"}): |
34 | | - cache_dir = get_cache_dir() |
35 | | - assert cache_dir == Path("/custom/cache") |
| 39 | + def test_get_cache_dir_spine_prod(self, monkeypatch): |
| 40 | + """Test cache directory from SPINE_PROD_BASEDIR.""" |
| 41 | + monkeypatch.delenv("SPINE_CACHE_DIR", raising=False) |
| 42 | + monkeypatch.setenv("SPINE_PROD_BASEDIR", "/opt/spine-prod") |
| 43 | + monkeypatch.setenv("SPINE_BASEDIR", "/opt/spine") |
| 44 | + |
| 45 | + cache_dir = get_cache_dir() |
| 46 | + # Should prefer SPINE_PROD_BASEDIR |
| 47 | + assert cache_dir == Path("/opt/spine-prod") / ".cache" / "weights" |
| 48 | + |
| 49 | + def test_get_cache_dir_spine_basedir(self, monkeypatch): |
| 50 | + """Test cache directory from SPINE_BASEDIR.""" |
| 51 | + monkeypatch.delenv("SPINE_CACHE_DIR", raising=False) |
| 52 | + monkeypatch.delenv("SPINE_PROD_BASEDIR", raising=False) |
| 53 | + monkeypatch.setenv("SPINE_BASEDIR", "/opt/spine") |
| 54 | + |
| 55 | + cache_dir = get_cache_dir() |
| 56 | + assert cache_dir == Path("/opt/spine") / ".cache" / "weights" |
| 57 | + |
| 58 | + def test_get_cache_dir_env_override(self, monkeypatch): |
| 59 | + """Test cache directory from environment variable override.""" |
| 60 | + monkeypatch.setenv("SPINE_CACHE_DIR", "/custom/cache") |
| 61 | + monkeypatch.setenv("SPINE_PROD_BASEDIR", "/opt/spine-prod") |
| 62 | + |
| 63 | + cache_dir = get_cache_dir() |
| 64 | + # SPINE_CACHE_DIR should take precedence |
| 65 | + assert cache_dir == Path("/custom/cache") |
36 | 66 |
|
37 | 67 | def test_url_to_filename(self): |
38 | 68 | """Test URL to filename conversion.""" |
|
0 commit comments