Skip to content

Commit

Permalink
Test current expected behavior of git.util.rmtree
Browse files Browse the repository at this point in the history
  • Loading branch information
EliahKagan committed Oct 9, 2023
1 parent 683a3ee commit 4e98be7
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
# the BSD License: https://opensource.org/license/bsd-3-clause/

import os
import pathlib
import pickle
import sys
import tempfile
import time
from unittest import mock, skipUnless
from unittest import SkipTest, mock, skipUnless
from datetime import datetime

import ddt
Expand All @@ -19,25 +20,26 @@
from git.compat import is_win
from git.objects.util import (
altz_to_utctz_str,
utctz_to_altz,
verify_utctz,
from_timestamp,
parse_date,
tzoffset,
from_timestamp,
utctz_to_altz,
verify_utctz,
)
from test.lib import (
TestBase,
with_rw_repo,
)
from git.util import (
LockFile,
BlockingLockFile,
get_user_id,
Actor,
BlockingLockFile,
IterableList,
LockFile,
cygpath,
decygpath,
get_user_id,
remove_password_if_present,
rmtree,
)


Expand Down Expand Up @@ -85,6 +87,38 @@ def setup(self):
"array": [42],
}

def test_rmdir_deletes_nested_dir_with_files(self):
with tempfile.TemporaryDirectory() as parent:
td = pathlib.Path(parent, "testdir")
for d in td, td / "q", td / "s":
d.mkdir()
for f in td / "p", td / "q" / "w", td / "q" / "x", td / "r", td / "s" / "y", td / "s" / "z":
f.write_bytes(b"")

try:
rmtree(td)
except SkipTest as ex:
self.fail(f"rmtree unexpectedly attempts skip: {ex!r}")

self.assertFalse(td.exists())

def test_rmdir_deletes_dir_with_readonly_files(self):
# Automatically works on Unix, but requires special handling on Windows.
with tempfile.TemporaryDirectory() as parent:
td = pathlib.Path(parent, "testdir")
for d in td, td / "sub":
d.mkdir()
for f in td / "x", td / "sub" / "y":
f.write_bytes(b"")
f.chmod(0)

try:
rmtree(td)
except SkipTest as ex:
self.fail(f"rmtree unexpectedly attempts skip: {ex!r}")

self.assertFalse(td.exists())

# FIXME: Mark only the /proc-prefixing cases xfail, somehow (or fix them).
@pytest.mark.xfail(
reason="Many return paths prefixed /proc/cygdrive instead.",
Expand Down

0 comments on commit 4e98be7

Please sign in to comment.