def test_chmod__accepts_fileno(test_file: Path): with test_file.open() as fp: fd = fp.fileno() sh.chmod(fd, "+rwx") filemode = stat.filemode(test_file.stat().st_mode) assert filemode == "-rwxrwxrwx"
def test_chmod__sets_file_mode( test_file: Path, starting_mode: t.Optional[int], desired_mode: t.Union[int, str], expected_mode: str, ): if starting_mode is not None: test_file.chmod(starting_mode) sh.chmod(test_file, desired_mode) filemode = stat.filemode(test_file.stat().st_mode) assert filemode == expected_mode
def test_chmod__recursively_sets_mode( tmp_path: Path, items: t.List[t.Union[Dir, File]], mode: t.Union[int, str], expected_file_mode: int, expected_dir_mode: int, ): test_dir = Dir(tmp_path / "test_dir", *items) test_dir.mkdir() sh.chmod(test_dir.path, mode, recursive=True) for path in (test_dir.path, *sh.walk(test_dir.path)): expected_mode = expected_dir_mode if path.is_dir( ) else expected_file_mode path_mode = stat.filemode(path.stat().st_mode) assert ( path_mode == expected_mode ), f"Expected mode of {path} to be {expected_mode!r}, not {path_mode!r}"
def test_chmod__sets_dir_mode(test_dir: Path): sh.chmod(test_dir, "+rw") filemode = stat.filemode(test_dir.stat().st_mode) assert filemode == "drwxrwxrwx"
def test_chmod__raises_when_mode_invalid(test_file: Path, mode: t.Any, exception: t.Type[Exception]): with pytest.raises(exception): sh.chmod(test_file, mode)