Esempio n. 1
0
def test_tmp_path_factory_handles_invalid_dir_characters(
        tmp_path_factory: TempPathFactory, monkeypatch: MonkeyPatch) -> None:
    monkeypatch.setattr("getpass.getuser", lambda: "os/<:*?;>agnostic")
    # _basetemp / _given_basetemp are cached / set in parallel runs, patch them
    monkeypatch.setattr(tmp_path_factory, "_basetemp", None)
    monkeypatch.setattr(tmp_path_factory, "_given_basetemp", None)
    p = tmp_path_factory.getbasetemp()
    assert "pytest-of-unknown" in str(p)
Esempio n. 2
0
def test_tmp_path_factory_fixes_up_world_readable_permissions(
        tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
    """Verify that if a /tmp/pytest-of-foo directory already exists with
    world-readable permissions, it is fixed.

    pytest used to mkdir with such permissions, that's why we fix it up.
    """
    # Use the test's tmp_path as the system temproot (/tmp).
    monkeypatch.setenv("PYTEST_DEBUG_TEMPROOT", str(tmp_path))
    tmp_factory = TempPathFactory(None, lambda *args: None, _ispytest=True)
    basetemp = tmp_factory.getbasetemp()

    # Before - simulate bad perms.
    os.chmod(basetemp.parent, 0o777)
    assert (basetemp.parent.stat().st_mode & 0o077) != 0

    tmp_factory = TempPathFactory(None, lambda *args: None, _ispytest=True)
    basetemp = tmp_factory.getbasetemp()

    # After - fixed.
    assert (basetemp.parent.stat().st_mode & 0o077) == 0
Esempio n. 3
0
def test_tmp_path_factory_create_directory_with_safe_permissions(
        tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
    """Verify that pytest creates directories under /tmp with private permissions."""
    # Use the test's tmp_path as the system temproot (/tmp).
    monkeypatch.setenv("PYTEST_DEBUG_TEMPROOT", str(tmp_path))
    tmp_factory = TempPathFactory(None, lambda *args: None, _ispytest=True)
    basetemp = tmp_factory.getbasetemp()

    # No world-readable permissions.
    assert (basetemp.stat().st_mode & 0o077) == 0
    # Parent too (pytest-of-foo).
    assert (basetemp.parent.stat().st_mode & 0o077) == 0
Esempio n. 4
0
def setup(tmp_path_factory: TempPathFactory):
    tmp_directory = str(tmp_path_factory.getbasetemp())
    src_dir = os.path.join(os.path.dirname(__file__), 'sbroot_test')
    sbroot = os.path.join(tmp_directory, 'sbroot_test')
    shutil.copytree(src_dir, sbroot)
    yield sbroot