|
1 | 1 | import os.path |
2 | 2 | import sqlite3 |
| 3 | +import stat |
3 | 4 | from unittest import mock |
4 | 5 |
|
5 | 6 | import pytest |
|
12 | 13 | from testing.fixtures import git_dir |
13 | 14 | from testing.util import cwd |
14 | 15 | from testing.util import git_commit |
| 16 | +from testing.util import xfailif_windows |
15 | 17 |
|
16 | 18 |
|
17 | 19 | def test_our_session_fixture_works(): |
@@ -217,3 +219,27 @@ def test_select_all_configs_roll_forward(store): |
217 | 219 | def test_mark_config_as_used_roll_forward(store, tmpdir): |
218 | 220 | _simulate_pre_1_14_0(store) |
219 | 221 | test_mark_config_as_used(store, tmpdir) |
| 222 | + |
| 223 | + |
| 224 | +@xfailif_windows # pragma: win32 no cover |
| 225 | +def test_mark_config_as_used_readonly(tmpdir): |
| 226 | + cfg = tmpdir.join('f').ensure() |
| 227 | + store_dir = tmpdir.join('store') |
| 228 | + # make a store, then we'll convert its directory to be readonly |
| 229 | + assert not Store(str(store_dir)).readonly # directory didn't exist |
| 230 | + assert not Store(str(store_dir)).readonly # directory did exist |
| 231 | + |
| 232 | + def _chmod_minus_w(p): |
| 233 | + st = os.stat(p) |
| 234 | + os.chmod(p, st.st_mode & ~(stat.S_IWUSR | stat.S_IWOTH | stat.S_IWGRP)) |
| 235 | + |
| 236 | + _chmod_minus_w(store_dir) |
| 237 | + for fname in os.listdir(store_dir): |
| 238 | + assert not os.path.isdir(fname) |
| 239 | + _chmod_minus_w(os.path.join(store_dir, fname)) |
| 240 | + |
| 241 | + store = Store(str(store_dir)) |
| 242 | + assert store.readonly |
| 243 | + # should be skipped due to readonly |
| 244 | + store.mark_config_used(str(cfg)) |
| 245 | + assert store.select_all_configs() == [] |
0 commit comments