3 from typing
import Callable
7 from tests
.conftest
import Dotfiles
10 @pytest.mark
.parametrize("directory", ["~/a", "~/b/c"])
11 def test_directory_creation(home
: str, directory
: str, dotfiles
: Dotfiles
, run_dotbot
: Callable
[..., None]) -> None:
12 """Test creating directories, including nested directories."""
15 dotfiles
.write_config([{"create": [directory
]}])
18 expanded_directory
= os
.path
.abspath(os
.path
.expanduser(directory
))
19 assert os
.path
.isdir(expanded_directory
)
20 assert os
.stat(expanded_directory
).st_mode
& 0o777 == 0o777
23 def test_default_mode(home
: str, dotfiles
: Dotfiles
, run_dotbot
: Callable
[..., None]) -> None:
24 """Test creating a directory with an explicit default mode.
26 Note: `os.chmod()` on Windows only supports changing write permissions.
27 Therefore, this test is restricted to testing read-only access.
31 read_only
= 0o777 - stat
.S_IWUSR
- stat
.S_IWGRP
- stat
.S_IWOTH
32 config
= [{"defaults": {"create": {"mode": read_only
}}}, {"create": ["~/a"]}]
33 dotfiles
.write_config(config
)
36 directory
= os
.path
.abspath(os
.path
.expanduser("~/a"))
37 assert os
.stat(directory
).st_mode
& stat
.S_IWUSR
== 0
38 assert os
.stat(directory
).st_mode
& stat
.S_IWGRP
== 0
39 assert os
.stat(directory
).st_mode
& stat
.S_IWOTH
== 0
42 def test_default_mode_override(home
: str, dotfiles
: Dotfiles
, run_dotbot
: Callable
[..., None]) -> None:
43 """Test creating a directory that overrides an explicit default mode.
45 Note: `os.chmod()` on Windows only supports changing write permissions.
46 Therefore, this test is restricted to testing read-only access.
50 read_only
= 0o777 - stat
.S_IWUSR
- stat
.S_IWGRP
- stat
.S_IWOTH
52 {"defaults": {"create": {"mode": read_only
}}},
53 {"create": {"~/a": {"mode": 0o777}}},
55 dotfiles
.write_config(config
)
58 directory
= os
.path
.abspath(os
.path
.expanduser("~/a"))
59 assert os
.stat(directory
).st_mode
& stat
.S_IWUSR
== stat
.S_IWUSR
60 assert os
.stat(directory
).st_mode
& stat
.S_IWGRP
== stat
.S_IWGRP
61 assert os
.stat(directory
).st_mode
& stat
.S_IWOTH
== stat
.S_IWOTH