Taragolis commented on code in PR #38164:
URL: https://github.com/apache/airflow/pull/38164#discussion_r1525559182
##########
tests/utils/test_log_handlers.py:
##########
@@ -754,3 +754,15 @@ def test_permissions_for_new_directories():
os.umask(old_umask)
finally:
shutil.rmtree(tmp_path)
+
+
+def test_permissions_for_home_directory_subdir():
+ home_dir = Path.home()
+ for dir in home_dir.glob("*"):
+ if dir.is_dir():
+ with patch("pathlib.Path.chmod") as mock_chmod:
+ _change_directory_permissions_up(dir, 0o000)
+ # Should only be called once - for the subdir - but not for
the home directory
+ mock_chmod.assert_called_once_with(0o000)
+ return
+ pytest.fail("No directory found in home directory")
Review Comment:
Another option would be use
[`monkeypatch`](https://docs.pytest.org/en/latest/how-to/monkeypatch.html#monkeypatching-functions),
I think it already have home patching but unfortunetly it doesn't
```python
from pathlib import Path
import pytest
@pytest.fixture
def fake_home(tmp_path_factory, monkeypatch) -> Path:
home = tmp_path_factory.mktemp("home")
def mockreturn():
return home
monkeypatch.setattr(Path, "home", mockreturn)
return home
def test_foo_bar(fake_home):
assert fake_home == Path.home()
from os.path import expanduser
assert fake_home.as_posix() != expanduser("~")
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]